diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-06 19:20:10 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-06 19:20:10 +0000 |
commit | 0675ffde8d774d9213ca2323faa9fce36c19bf74 (patch) | |
tree | 1027638491e7918ae2ccb6e55942c7a7325d063a /src | |
parent | c2a3ebea46f3527e0680f1258725f95ff13f0880 (diff) |
Add PROP command to m_namedmodes
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12388 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_check.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_namedmodes.cpp | 99 |
2 files changed, 82 insertions, 23 deletions
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index c1af8ead2..6f89f8cf4 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -250,7 +250,11 @@ class ModuleCheck : public Module public: ModuleCheck() : mycommand(this) { - ServerInstance->AddCommand(&mycommand); + } + + void init() + { + ServerInstance->Modules->AddService(mycommand); } ~ModuleCheck() diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp index 4d2363c4d..c113b502c 100644 --- a/src/modules/m_namedmodes.cpp +++ b/src/modules/m_namedmodes.cpp @@ -13,11 +13,87 @@ #include "inspircd.h" +static void DisplayList(User* user, Channel* channel) +{ + std::stringstream items; + for(char letter = 'A'; letter <= 'z'; letter++) + { + ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); + if (!mh || mh->IsListMode()) + continue; + if (!channel->IsModeSet(letter)) + continue; + std::string item = mh->name; + if (mh->GetNumParams(true)) + item += "=" + channel->GetModeParameter(letter); + items << item << " "; + } + char pfx[MAXBUF]; + snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str()); + user->SendText(std::string(pfx), items); + user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str()); +} + +class CommandProp : public Command +{ + public: + CommandProp(Module* parent) : Command(parent, "PROP", 1) + { + syntax = "<user|channel> [{+|-}<mode>[=value]]"; + TRANSLATE3(TR_TEXT, TR_TEXT, TR_END); + } + + CmdResult Handle(const std::vector<std::string> ¶meters, User *src) + { + if (parameters.size() == 1) + { + Channel* chan = ServerInstance->FindChan(parameters[0]); + if (chan) + DisplayList(src, chan); + return CMD_SUCCESS; + } + + std::string prop = parameters[1], value; + std::string::size_type eq = prop.find('='); + if (eq != std::string::npos) + { + value = prop.substr(eq + 1); + prop = prop.substr(0, eq); + } + bool plus = prop[0] != '-'; + if (prop[0] == '+' || prop[0] == '-') + prop.erase(prop.begin()); + + for(char letter = 'A'; letter <= 'z'; letter++) + { + ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); + if (mh && mh->name == prop) + { + if (mh->GetNumParams(plus) && value.empty()) + return CMD_FAILURE; + std::vector<std::string> modes; + modes.push_back(parameters[0]); + modes.push_back((plus ? "+" : "-") + std::string(1, letter)); + modes.push_back(value); + ServerInstance->SendGlobalMode(modes, src); + return CMD_SUCCESS; + } + } + return CMD_FAILURE; + } +}; + class ModuleNamedModes : public Module { + CommandProp cmd; public: - ModuleNamedModes() + ModuleNamedModes() : cmd(this) + { + } + + void init() { + ServerInstance->Modules->AddService(cmd); Implementation eventlist[] = { I_OnPreMode, I_On005Numeric }; ServerInstance->Modules->Attach(eventlist, this, 2); } @@ -44,27 +120,6 @@ class ModuleNamedModes : public Module } } - void DisplayList(User* user, Channel* channel) - { - std::stringstream items; - for(char letter = 'A'; letter <= 'z'; letter++) - { - ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); - if (!mh || mh->IsListMode()) - continue; - if (!channel->IsModeSet(letter)) - continue; - std::string item = mh->name; - if (mh->GetNumParams(true)) - item += "=" + channel->GetModeParameter(letter); - items << item << " "; - } - char pfx[MAXBUF]; - snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str()); - user->SendText(std::string(pfx), items); - user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str()); - } - ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters) { if (!channel) |