From ee44af8d04f23b4a16c9b377764f930d69e575f7 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 27 Nov 2022 07:32:42 +0000 Subject: Refactor the internals of the oper system. - Allow overriding privileges from the blocks in the and blocks. - Separate oper types from oper accounts in the code. This enables moving some core stuff out of the config tag later. - Merge the config tags together to make a synthetic tag that can have getXXX called on it instead of using getConfig and then converting it. - Move the details of Have*Permission into the oper type class. - Improve oper events to allow modules to easily hook into the oper system. --- src/modules/m_sqloper.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/modules/m_sqloper.cpp') diff --git a/src/modules/m_sqloper.cpp b/src/modules/m_sqloper.cpp index 6323d1ef2..8eb295222 100644 --- a/src/modules/m_sqloper.cpp +++ b/src/modules/m_sqloper.cpp @@ -54,11 +54,9 @@ public: void OnResult(SQL::Result& res) override { - ServerConfig::OperIndex& oper_blocks = ServerInstance->Config->oper_blocks; - - // Remove our previous blocks from oper_blocks for a clean update + // Remove our previous blocks from the core for a clean update for (const auto& block : my_blocks) - oper_blocks.erase(block); + ServerInstance->Config->OperAccounts.erase(block); my_blocks.clear(); SQL::Row row; @@ -82,11 +80,11 @@ public: const std::string name = tag->getString("name"); // Skip both duplicate sqloper blocks and sqloper blocks that attempt to override conf blocks. - if (oper_blocks.find(name) != oper_blocks.end()) + if (ServerInstance->Config->OperAccounts.find(name) != ServerInstance->Config->OperAccounts.end()) continue; const std::string type = tag->getString("type"); - ServerConfig::OperIndex::iterator tblk = ServerInstance->Config->OperTypes.find(type); + auto tblk = ServerInstance->Config->OperTypes.find(type); if (tblk == ServerInstance->Config->OperTypes.end()) { ServerInstance->Logs.Normal(MODNAME, "Sqloper block " + name + " has missing type " + type); @@ -94,12 +92,7 @@ public: continue; } - auto ifo = std::make_shared(type); - - ifo->type_block = tblk->second->type_block; - ifo->oper_block = std::move(tag); - ifo->class_blocks.assign(tblk->second->class_blocks.begin(), tblk->second->class_blocks.end()); - oper_blocks[name] = ifo; + ServerInstance->Config->OperAccounts[name] = std::make_shared(name, tblk->second, tag); my_blocks.push_back(name); row.clear(); } @@ -123,7 +116,7 @@ public: } } - // Call /oper after placing all blocks from the SQL table into the config->oper_blocks list. + // Call /oper after placing all blocks from the SQL table into the Config->OperAccounts list. void OperExec() { auto user = ServerInstance->Users.Find(uid); @@ -199,7 +192,7 @@ public: { // Remove all oper blocks that were from the DB for (const auto& block : my_blocks) - ServerInstance->Config->oper_blocks.erase(block); + ServerInstance->Config->OperAccounts.erase(block); } ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) override -- cgit v1.3.1-10-gc9f91