summaryrefslogtreecommitdiff
path: root/src/modules/m_namedmodes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/m_namedmodes.cpp')
-rw-r--r--src/modules/m_namedmodes.cpp69
1 files changed, 29 insertions, 40 deletions
diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp
index 5c0ffeea5..4004db00e 100644
--- a/src/modules/m_namedmodes.cpp
+++ b/src/modules/m_namedmodes.cpp
@@ -89,6 +89,12 @@ class DummyZ : public ModeHandler
{
list = true;
}
+
+ // Handle /MODE #chan Z
+ void DisplayList(User* user, Channel* chan)
+ {
+ ::DisplayList(user, chan);
+ }
};
class ModuleNamedModes : public Module
@@ -110,39 +116,22 @@ class ModuleNamedModes : public Module
ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
}
- ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
+ ModResult OnPreMode(User* source, User* dest, Channel* channel, Modes::ChangeList& modes) CXX11_OVERRIDE
{
if (!channel)
return MOD_RES_PASSTHRU;
- if (parameters[1].find('Z') == std::string::npos)
- return MOD_RES_PASSTHRU;
- if (parameters.size() <= 2)
- {
- DisplayList(source, channel);
- return MOD_RES_DENY;
- }
-
- std::vector<std::string> newparms;
- newparms.push_back(parameters[0]);
- newparms.push_back(parameters[1]);
- std::string modelist = newparms[1];
- bool adding = true;
- unsigned int param_at = 2;
- for(unsigned int i = 0; i < modelist.length(); i++)
+ Modes::ChangeList::List& list = modes.getlist();
+ for (Modes::ChangeList::List::iterator i = list.begin(); i != list.end(); )
{
- unsigned char modechar = modelist[i];
- if (modechar == '+' || modechar == '-')
+ Modes::Change& curr = *i;
+ // Replace all namebase (dummyZ) modes being changed with the actual
+ // mode handler and parameter. The parameter format of the namebase mode is
+ // <modename>[=<parameter>].
+ if (curr.mh == &dummyZ)
{
- adding = (modechar == '+');
- continue;
- }
- ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL);
- if (modechar == 'Z')
- {
- std::string name, value;
- if (param_at < parameters.size())
- name = parameters[param_at++];
+ std::string name = curr.param;
+ std::string value;
std::string::size_type eq = name.find('=');
if (eq != std::string::npos)
{
@@ -150,36 +139,36 @@ class ModuleNamedModes : public Module
name = name.substr(0, eq);
}
- mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL);
+ ModeHandler* mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL);
if (!mh)
{
// Mode handler not found
- modelist.erase(i--, 1);
+ i = list.erase(i);
continue;
}
- if (mh->GetNumParams(adding))
+ curr.param.clear();
+ if (mh->GetNumParams(curr.adding))
{
if (value.empty())
{
// Mode needs a parameter but there wasn't one
- modelist.erase(i--, 1);
+ i = list.erase(i);
continue;
}
- newparms.push_back(value);
+ // Change parameter to the text after the '='
+ curr.param = value;
}
- modelist[i] = mh->GetModeChar();
- }
- else if (mh && mh->GetNumParams(adding) && param_at < parameters.size())
- {
- newparms.push_back(parameters[param_at++]);
+ // Put the actual ModeHandler in place of the namebase handler
+ curr.mh = mh;
}
+
+ ++i;
}
- newparms[1] = modelist;
- ServerInstance->Modes->Process(newparms, source);
- return MOD_RES_DENY;
+
+ return MOD_RES_PASSTHRU;
}
};