diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-02-20 13:34:27 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-02-20 13:34:27 +0100 |
commit | 5303501b930d3d6c765c24ff69edb722d8a6b5f1 (patch) | |
tree | f19fab0754dfe58e548ed389fa0e669b4af4ee48 /src/modules | |
parent | f66d05dbda78c44b9af40e3e6f4e1a50f802d054 (diff) |
Add a ModeParser::FindMode() overload that takes a mode name and a mode type
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_autoop.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_exemptchanops.cpp | 15 | ||||
-rw-r--r-- | src/modules/m_namedmodes.cpp | 56 |
3 files changed, 31 insertions, 50 deletions
diff --git a/src/modules/m_autoop.cpp b/src/modules/m_autoop.cpp index 889c3c801..828bef14c 100644 --- a/src/modules/m_autoop.cpp +++ b/src/modules/m_autoop.cpp @@ -37,14 +37,8 @@ class AutoOpList : public ListModeBase if (mid.length() == 1) return ServerInstance->Modes->FindPrefixMode(mid[0]); - const ModeParser::PrefixModeList& pmlist = ServerInstance->Modes->GetPrefixModes(); - for (ModeParser::PrefixModeList::const_iterator i = pmlist.begin(); i != pmlist.end(); ++i) - { - PrefixMode* mh = *i; - if (mh->name == mid) - return mh; - } - return NULL; + ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL); + return mh ? mh->IsPrefixMode() : NULL; } ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding) diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp index 7eb13690a..14050430f 100644 --- a/src/modules/m_exemptchanops.cpp +++ b/src/modules/m_exemptchanops.cpp @@ -29,10 +29,9 @@ class ExemptChanOps : public ListModeBase bool ValidateParam(User* user, Channel* chan, std::string &word) { - // TODO actually make sure there's a prop for this - if ((word.length() > 35) || (word.empty())) + if (!ServerInstance->Modes->FindMode(word, MODETYPE_CHANNEL)) { - user->WriteNumeric(955, "%s %s :word is too %s for exemptchanops list", chan->name.c_str(), word.c_str(), (word.empty() ? "short" : "long")); + user->WriteNumeric(955, "%s %s :Mode doesn't exist", chan->name.c_str(), word.c_str()); return false; } @@ -66,14 +65,8 @@ class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std: if (mid.length() == 1) return ServerInstance->Modes->FindPrefixMode(mid[0]); - const ModeParser::PrefixModeList& pmlist = ServerInstance->Modes->GetPrefixModes(); - for (ModeParser::PrefixModeList::const_iterator i = pmlist.begin(); i != pmlist.end(); ++i) - { - PrefixMode* mh = *i; - if (mh->name == mid) - return mh; - } - return NULL; + ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL); + return mh ? mh->IsPrefixMode() : NULL; } ModResult Call(User* user, Channel* chan, const std::string& restriction) diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp index d3f9f94a4..e8b90caa3 100644 --- a/src/modules/m_namedmodes.cpp +++ b/src/modules/m_namedmodes.cpp @@ -66,17 +66,15 @@ class CommandProp : public Command if (prop[0] == '+' || prop[0] == '-') prop.erase(prop.begin()); - for(char letter = 'A'; letter <= 'z'; letter++) + ModeHandler* mh = ServerInstance->Modes->FindMode(prop, MODETYPE_CHANNEL); + if (mh) { - ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); - if (mh && mh->name == prop) + modes[1].push_back(plus ? '+' : '-'); + modes[1].push_back(mh->GetModeChar()); + if (mh->GetNumParams(plus)) { - modes[1].append((plus ? "+" : "-") + std::string(1, letter)); - if (mh->GetNumParams(plus)) - { - if (i != parameters.size()) - modes.push_back(parameters[i++]); - } + if (i != parameters.size()) + modes.push_back(parameters[i++]); } } } @@ -143,7 +141,6 @@ class ModuleNamedModes : public Module ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL); if (modechar == 'Z') { - modechar = 0; std::string name, value; if (param_at < parameters.size()) name = parameters[param_at++]; @@ -153,31 +150,28 @@ class ModuleNamedModes : public Module value = name.substr(eq + 1); name = name.substr(0, eq); } - for(char letter = 'A'; modechar == 0 && letter <= 'z'; letter++) + + mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL); + if (!mh) + { + // Mode handler not found + modelist.erase(i--, 1); + continue; + } + + if (mh->GetNumParams(adding)) { - mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); - if (mh && mh->name == name) + if (value.empty()) { - if (mh->GetNumParams(adding)) - { - if (!value.empty()) - { - newparms.push_back(value); - modechar = letter; - break; - } - } - else - { - modechar = letter; - break; - } + // Mode needs a parameter but there wasn't one + modelist.erase(i--, 1); + continue; } + + newparms.push_back(value); } - if (modechar) - modelist[i] = modechar; - else - modelist.erase(i--, 1); + + modelist[i] = mh->GetModeChar(); } else if (mh && mh->GetNumParams(adding) && param_at < parameters.size()) { |