From 1336e2e7fed96898dfe7d6c3e482cfff1ebed598 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 4 Feb 2022 22:23:37 +0000 Subject: Refactor the opermodes module. - Fix the module class name to match the module name. - Squish ApplyModes into the only function that calls it. - Remove unnecessary logic to check mode is well formed (this check is alse done by the MODE command handler). - Remove obsolete comment from when we had to manually loop through the oper config to check their modes. --- src/modules/m_opermodes.cpp | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'src/modules/m_opermodes.cpp') diff --git a/src/modules/m_opermodes.cpp b/src/modules/m_opermodes.cpp index 7e5e9d45b..42acf9ad4 100644 --- a/src/modules/m_opermodes.cpp +++ b/src/modules/m_opermodes.cpp @@ -26,47 +26,34 @@ #include "inspircd.h" -class ModuleModesOnOper final +class ModuleOperModes final : public Module { public: - ModuleModesOnOper() + ModuleOperModes() : Module(VF_VENDOR, "Allows the server administrator to set user modes on server operators when they log into their server operator account.") { } - void OnPostOper(User* user, const std::string &opertype, const std::string &opername) override + void OnPostOper(User* user, const std::string&, const std::string&) override { if (!IS_LOCAL(user)) - return; + return; // We don't handle remote users. - // whenever a user opers, go through the oper types, find their , - // and if they have one apply their modes. The mode string can contain +modes - // to add modes to the user or -modes to take modes from the user. - std::string ThisOpersModes = user->oper->getConfig("modes"); - if (!ThisOpersModes.empty()) - { - ApplyModes(user, ThisOpersModes); - } - } - - void ApplyModes(User *u, std::string &smodes) - { - char first = *(smodes.c_str()); - if ((first != '+') && (first != '-')) - smodes = "+" + smodes; + const std::string opermodes = user->oper->getConfig("modes"); + if (opermodes.empty()) + return; // We don't have any modes to set. - std::string buf; - irc::spacesepstream ss(smodes); - CommandBase::Params modes; + CommandBase::Params modeparams; + modeparams.push_back(user->nick); - modes.push_back(u->nick); - // split into modes and mode params - while (ss.GetToken(buf)) - modes.push_back(buf); + irc::spacesepstream modestream(opermodes); + for (std::string modeparam; modestream.GetToken(modeparam); ) + modeparams.push_back(modeparam); - ServerInstance->Parser.CallHandler("MODE", modes, u); + if (modeparams.size() > 1) + ServerInstance->Parser.CallHandler("MODE", modeparams, user); } }; -MODULE_INIT(ModuleModesOnOper) +MODULE_INIT(ModuleOperModes) -- cgit v1.3.1-10-gc9f91