2023-11-25 20:09:20 -08:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-27 14:12:20 -08:00
|
|
|
#include "event.hpp"
|
2023-11-25 20:09:20 -08:00
|
|
|
|
2023-11-26 21:16:56 -08:00
|
|
|
#include <memory>
|
2023-11-28 11:34:27 -08:00
|
|
|
#include <regex>
|
2023-11-27 19:09:45 -08:00
|
|
|
#include <string_view>
|
2023-11-28 11:34:27 -08:00
|
|
|
#include <variant>
|
2023-11-26 21:16:56 -08:00
|
|
|
|
2023-11-25 20:09:20 -08:00
|
|
|
class Connection;
|
2023-11-27 19:09:45 -08:00
|
|
|
struct hs_database;
|
|
|
|
struct hs_scratch;
|
2023-11-25 20:09:20 -08:00
|
|
|
|
2023-11-26 21:16:56 -08:00
|
|
|
enum class SnoteTag
|
|
|
|
{
|
|
|
|
ClientConnecting,
|
|
|
|
ClientExiting,
|
2023-11-27 14:12:20 -08:00
|
|
|
RejectingKlined,
|
|
|
|
NickChange,
|
|
|
|
CreateChannel,
|
|
|
|
TemporaryKlineExpired,
|
2023-11-27 18:47:32 -08:00
|
|
|
PropagatedBanExpired,
|
2023-11-27 14:12:20 -08:00
|
|
|
DisconnectingKlined,
|
2023-11-27 18:47:32 -08:00
|
|
|
NewPropagatedKline,
|
|
|
|
NewTemporaryKline,
|
|
|
|
LoginAttempts,
|
|
|
|
PossibleFlooder,
|
|
|
|
Killed,
|
2023-11-26 21:16:56 -08:00
|
|
|
};
|
|
|
|
|
2023-11-28 11:34:27 -08:00
|
|
|
class SnoteEvent : public Event
|
2023-11-25 20:09:20 -08:00
|
|
|
{
|
2023-11-28 11:34:27 -08:00
|
|
|
public:
|
|
|
|
SnoteEvent(SnoteTag tag, std::regex const& regex, std::string_view full)
|
|
|
|
: tag_{tag}
|
|
|
|
, components_{std::make_pair(std::ref(regex), full)}
|
2023-11-26 21:16:56 -08:00
|
|
|
{}
|
|
|
|
|
2023-11-28 11:34:27 -08:00
|
|
|
auto get_tag() const -> SnoteTag;
|
|
|
|
auto get_results() -> std::match_results<std::string_view::const_iterator> const&;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SnoteTag tag_;
|
|
|
|
std::variant<std::pair<std::regex const&, std::string_view>, std::match_results<std::string_view::const_iterator>> components_;
|
2023-11-25 20:09:20 -08:00
|
|
|
};
|
|
|
|
|
2023-11-26 21:16:56 -08:00
|
|
|
struct SnoteThread
|
|
|
|
{
|
|
|
|
struct DbDeleter
|
|
|
|
{
|
2023-11-27 19:09:45 -08:00
|
|
|
auto operator()(hs_database * db) const -> void;
|
2023-11-26 21:16:56 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ScratchDeleter
|
|
|
|
{
|
2023-11-27 19:09:45 -08:00
|
|
|
auto operator()(hs_scratch * scratch) const -> void;
|
2023-11-26 21:16:56 -08:00
|
|
|
};
|
|
|
|
|
2023-11-27 19:09:45 -08:00
|
|
|
std::unique_ptr<hs_database, DbDeleter> db_;
|
|
|
|
std::unique_ptr<hs_scratch, ScratchDeleter> scratch_;
|
2023-11-26 21:16:56 -08:00
|
|
|
|
|
|
|
static auto start(Connection& connection) -> std::shared_ptr<SnoteThread>;
|
|
|
|
};
|