diff options
author | Attila Molnar <attilamolnar@hush.com> | 2016-08-30 16:12:39 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2016-08-30 16:12:39 +0200 |
commit | cf6a8ee7e3fb11ea19d627216f53118c563a0a71 (patch) | |
tree | 6111e8b977604cb542c037c4b7699a844b7459bf /src/modules/m_check.cpp | |
parent | f0debf907a36846e3b48767e9797880135a4583b (diff) |
Replace loop over alphabet with loop over mode list in several places
Diffstat (limited to 'src/modules/m_check.cpp')
-rw-r--r-- | src/modules/m_check.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index ddac033c1..4330f410d 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -109,6 +109,19 @@ class CommandCheck : public Command return ret; } + static std::string GetAllowedOperOnlyModes(LocalUser* user, ModeType modetype) + { + std::string ret; + const ModeParser::ModeHandlerMap& modes = ServerInstance->Modes.GetModes(modetype); + for (ModeParser::ModeHandlerMap::const_iterator i = modes.begin(); i != modes.end(); ++i) + { + const ModeHandler* const mh = i->second; + if ((mh->NeedsOper()) && (user->HasModePermission(mh))) + ret.push_back(mh->GetModeChar()); + } + return ret; + } + public: CommandCheck(Module* parent) : Command(parent,"CHECK", 1) @@ -179,17 +192,8 @@ class CommandCheck : public Command context.Write("opertype", oper->name); if (loctarg) { - std::string umodes; - std::string cmodes; - for(char c='A'; c <= 'z'; c++) - { - ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_USER); - if (mh && mh->NeedsOper() && loctarg->HasModePermission(mh)) - umodes.push_back(c); - mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL); - if (mh && mh->NeedsOper() && loctarg->HasModePermission(mh)) - cmodes.push_back(c); - } + std::string umodes = GetAllowedOperOnlyModes(loctarg, MODETYPE_USER); + std::string cmodes = GetAllowedOperOnlyModes(loctarg, MODETYPE_CHANNEL); context.Write("modeperms", "user=" + umodes + " channel=" + cmodes); CheckContext::List opcmdlist(context, "commandperms"); |