2023-11-29 09:07:20 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
class Connection;
|
|
|
|
class CommandEvent;
|
|
|
|
|
|
|
|
class PrivThread : std::enable_shared_from_this<PrivThread>
|
|
|
|
{
|
|
|
|
Connection& connection_;
|
2023-11-29 09:44:36 -08:00
|
|
|
std::string config_path_;
|
|
|
|
|
2023-11-29 11:07:24 -08:00
|
|
|
std::unordered_map<std::string, std::unordered_set<std::string>> oper_privs_;
|
|
|
|
std::unordered_map<std::string, std::unordered_set<std::string>> account_privs_;
|
2023-11-29 09:07:20 -08:00
|
|
|
|
|
|
|
auto on_command(CommandEvent&) -> void;
|
|
|
|
|
|
|
|
auto check(
|
|
|
|
std::unordered_map<std::string, std::unordered_set<std::string>> const& privs,
|
|
|
|
std::string const& priv,
|
|
|
|
std::string const& name) -> bool;
|
|
|
|
|
2023-11-29 09:44:36 -08:00
|
|
|
auto load_config() -> void;
|
2023-11-29 11:07:24 -08:00
|
|
|
auto save_config() -> void;
|
|
|
|
auto list_privs(std::string_view nick) -> void;
|
2023-11-29 09:44:36 -08:00
|
|
|
|
2023-11-29 09:07:20 -08:00
|
|
|
public:
|
2023-11-29 09:44:36 -08:00
|
|
|
PrivThread(Connection&, std::string config_path);
|
2023-11-29 09:07:20 -08:00
|
|
|
auto check_command(CommandEvent& event, std::string priv) -> bool;
|
|
|
|
|
|
|
|
static constexpr char const* owner_priv = "owner";
|
2023-11-29 11:07:24 -08:00
|
|
|
static constexpr char const* wildcard = "*";
|
2023-11-29 09:07:20 -08:00
|
|
|
|
2023-11-29 09:44:36 -08:00
|
|
|
static auto start(Connection&, std::string config_path) -> std::shared_ptr<PrivThread>;
|
|
|
|
};
|