diff options
| author | 2022-02-04 22:23:37 +0000 | |
|---|---|---|
| committer | 2022-02-04 22:26:59 +0000 | |
| commit | 1336e2e7fed96898dfe7d6c3e482cfff1ebed598 (patch) | |
| tree | def5df97035eb65d979b908954442a7cb1839917 /src/modules | |
| parent | Release v4.0.0 alpha 8. (diff) | |
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.
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/m_opermodes.cpp | 43 |
1 files changed, 15 insertions, 28 deletions
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 <type:modes>, - // 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) |
