From 0675ffde8d774d9213ca2323faa9fce36c19bf74 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 6 Feb 2010 19:20:10 +0000 Subject: Add PROP command to m_namedmodes git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12388 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_check.cpp | 6 ++- 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 = " [{+|-}[=value]]"; + TRANSLATE3(TR_TEXT, TR_TEXT, TR_END); + } + + CmdResult Handle(const std::vector ¶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 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& parameters) { if (!channel) -- cgit v1.2.3