X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_namedmodes.cpp;h=5c0ffeea5510ca4e0e09b703f97e0039b4c4a8dd;hb=f45a8e2a14329860ad07b903797cef00a925e8cb;hp=9d92b8a44137c713d30439fdf7f2e555de14e1e3;hpb=c286b42418c3d7614225b1226632a25ac513994b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp index 9d92b8a44..5c0ffeea5 100644 --- a/src/modules/m_namedmodes.cpp +++ b/src/modules/m_namedmodes.cpp @@ -17,18 +17,15 @@ */ -/* $ModDesc: Provides the ability to manipulate modes via long names. */ - #include "inspircd.h" static void DisplayList(User* user, Channel* channel) { std::stringstream items; - for(char letter = 'A'; letter <= 'z'; letter++) + const ModeParser::ModeHandlerMap& mhs = ServerInstance->Modes->GetModes(MODETYPE_CHANNEL); + for (ModeParser::ModeHandlerMap::const_iterator i = mhs.begin(); i != mhs.end(); ++i) { - ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); - if (!mh || mh->IsListMode()) - continue; + ModeHandler* mh = i->second; if (!channel->IsModeSet(mh)) continue; items << " +" << mh->name; @@ -37,7 +34,7 @@ static void DisplayList(User* user, Channel* channel) } const std::string line = ":" + ServerInstance->Config->ServerName + " 961 " + user->nick + " " + channel->name; user->SendText(line, items); - user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str()); + user->WriteNumeric(960, "%s :End of mode list", channel->name.c_str()); } class CommandProp : public Command @@ -68,17 +65,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++]); } } } @@ -105,15 +100,6 @@ class ModuleNamedModes : public Module { } - void init() CXX11_OVERRIDE - { - ServerInstance->Modules->AddService(cmd); - ServerInstance->Modules->AddService(dummyZ); - - Implementation eventlist[] = { I_OnPreMode }; - ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); - } - Version GetVersion() CXX11_OVERRIDE { return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR); @@ -154,7 +140,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++]; @@ -164,31 +149,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()) {