2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 static void DisplayList(User* user, Channel* channel)
24 std::stringstream items;
25 for(char letter = 'A'; letter <= 'z'; letter++)
27 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
28 if (!mh || mh->IsListMode())
30 if (!channel->IsModeSet(mh))
32 items << " +" << mh->name;
33 if (mh->GetNumParams(true))
34 items << " " << channel->GetModeParameter(mh);
36 const std::string line = ":" + ServerInstance->Config->ServerName + " 961 " + user->nick + " " + channel->name;
37 user->SendText(line, items);
38 user->WriteNumeric(960, "%s :End of mode list", channel->name.c_str());
41 class CommandProp : public Command
44 CommandProp(Module* parent) : Command(parent, "PROP", 1)
46 syntax = "<user|channel> {[+-]<mode> [<value>]}*";
49 CmdResult Handle(const std::vector<std::string> ¶meters, User *src)
51 if (parameters.size() == 1)
53 Channel* chan = ServerInstance->FindChan(parameters[0]);
55 DisplayList(src, chan);
59 std::vector<std::string> modes;
60 modes.push_back(parameters[0]);
62 while (i < parameters.size())
64 std::string prop = parameters[i++];
65 bool plus = prop[0] != '-';
66 if (prop[0] == '+' || prop[0] == '-')
67 prop.erase(prop.begin());
69 for(char letter = 'A'; letter <= 'z'; letter++)
71 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
72 if (mh && mh->name == prop)
74 modes[1].append((plus ? "+" : "-") + std::string(1, letter));
75 if (mh->GetNumParams(plus))
77 if (i != parameters.size())
78 modes.push_back(parameters[i++]);
83 ServerInstance->Modes->Process(modes, src);
88 class DummyZ : public ModeHandler
91 DummyZ(Module* parent) : ModeHandler(parent, "namebase", 'Z', PARAM_ALWAYS, MODETYPE_CHANNEL)
97 class ModuleNamedModes : public Module
102 ModuleNamedModes() : cmd(this), dummyZ(this)
106 Version GetVersion() CXX11_OVERRIDE
108 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
113 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
116 ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
119 return MOD_RES_PASSTHRU;
120 if (parameters[1].find('Z') == std::string::npos)
121 return MOD_RES_PASSTHRU;
122 if (parameters.size() <= 2)
124 DisplayList(source, channel);
128 std::vector<std::string> newparms;
129 newparms.push_back(parameters[0]);
130 newparms.push_back(parameters[1]);
132 std::string modelist = newparms[1];
134 unsigned int param_at = 2;
135 for(unsigned int i = 0; i < modelist.length(); i++)
137 unsigned char modechar = modelist[i];
138 if (modechar == '+' || modechar == '-')
140 adding = (modechar == '+');
143 ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL);
147 std::string name, value;
148 if (param_at < parameters.size())
149 name = parameters[param_at++];
150 std::string::size_type eq = name.find('=');
151 if (eq != std::string::npos)
153 value = name.substr(eq + 1);
154 name = name.substr(0, eq);
156 for(char letter = 'A'; modechar == 0 && letter <= 'z'; letter++)
158 mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
159 if (mh && mh->name == name)
161 if (mh->GetNumParams(adding))
165 newparms.push_back(value);
178 modelist[i] = modechar;
180 modelist.erase(i--, 1);
182 else if (mh && mh->GetNumParams(adding) && param_at < parameters.size())
184 newparms.push_back(parameters[param_at++]);
187 newparms[1] = modelist;
188 ServerInstance->Modes->Process(newparms, source);
193 MODULE_INIT(ModuleNamedModes)