summaryrefslogtreecommitdiff
path: root/src/modules/m_namedmodes.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-06 19:20:10 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-06 19:20:10 +0000
commit0675ffde8d774d9213ca2323faa9fce36c19bf74 (patch)
tree1027638491e7918ae2ccb6e55942c7a7325d063a /src/modules/m_namedmodes.cpp
parentc2a3ebea46f3527e0680f1258725f95ff13f0880 (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/modules/m_namedmodes.cpp')
-rw-r--r--src/modules/m_namedmodes.cpp99
1 files changed, 77 insertions, 22 deletions
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> &parameters, 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)