summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-02-20 13:34:27 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-02-20 13:34:27 +0100
commit5303501b930d3d6c765c24ff69edb722d8a6b5f1 (patch)
treef19fab0754dfe58e548ed389fa0e669b4af4ee48 /src
parentf66d05dbda78c44b9af40e3e6f4e1a50f802d054 (diff)
Add a ModeParser::FindMode() overload that takes a mode name and a mode type
Diffstat (limited to 'src')
-rw-r--r--src/mode.cpp10
-rw-r--r--src/modules/m_autoop.cpp10
-rw-r--r--src/modules/m_exemptchanops.cpp15
-rw-r--r--src/modules/m_namedmodes.cpp56
4 files changed, 41 insertions, 50 deletions
diff --git a/src/mode.cpp b/src/mode.cpp
index e70df5479..17379b620 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -708,6 +708,16 @@ bool ModeParser::DelMode(ModeHandler* mh)
return true;
}
+ModeHandler* ModeParser::FindMode(const std::string& modename, ModeType mt)
+{
+ ModeHandlerMap& mhmap = modehandlersbyname[mt];
+ ModeHandlerMap::const_iterator it = mhmap.find(modename);
+ if (it != mhmap.end())
+ return it->second;
+
+ return NULL;
+}
+
ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
{
if ((modeletter < 'A') || (modeletter > 'z'))
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 &parameter, 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())
{