#include "priv_thread.hpp" #include "connection.hpp" #include "command_thread.hpp" PrivThread::PrivThread(Connection& connection) : connection_{connection} {} auto PrivThread::check_command(CommandEvent& event, std::string priv) -> bool { return (not event.account.empty() && (check(account_privs, priv, "") || check(account_privs, priv, std::string{event.account}))) || (not event.oper.empty() && (check(oper_privs, priv, "") || check(oper_privs, priv, std::string{event.oper}))); } auto PrivThread::check( std::unordered_map> const& privs, std::string const& priv, std::string const& name ) -> bool { auto const cursor = privs.find(name); return cursor != privs.end() && cursor->second.contains(priv); } auto PrivThread::on_command(CommandEvent& event) -> void { if (event.command == "setup") { oper_privs["glguy"].insert("owner"); } } auto PrivThread::start(Connection& connection) -> std::shared_ptr { auto thread = std::make_shared(connection); connection.add_listener([thread](CommandEvent& event) { thread->on_command(event); }); return thread; }