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(letter))
32 items << " +" << mh->name;
33 if (mh->GetNumParams(true))
34 items << " " << channel->GetModeParameter(letter);
37 snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str());
38 user->SendText(std::string(pfx), items);
39 user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
42 class CommandProp : public Command
45 CommandProp(Module* parent) : Command(parent, "PROP", 1)
47 syntax = "<user|channel> {[+-]<mode> [<value>]}*";
50 CmdResult Handle(const std::vector<std::string> ¶meters, User *src)
52 if (parameters.size() == 1)
54 Channel* chan = ServerInstance->FindChan(parameters[0]);
56 DisplayList(src, chan);
60 std::vector<std::string> modes;
61 modes.push_back(parameters[0]);
63 while (i < parameters.size())
65 std::string prop = parameters[i++];
66 bool plus = prop[0] != '-';
67 if (prop[0] == '+' || prop[0] == '-')
68 prop.erase(prop.begin());
70 for(char letter = 'A'; letter <= 'z'; letter++)
72 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
73 if (mh && mh->name == prop)
75 modes[1].append((plus ? "+" : "-") + std::string(1, letter));
76 if (mh->GetNumParams(plus))
78 if (i != parameters.size())
79 modes.push_back(parameters[i++]);
84 ServerInstance->SendGlobalMode(modes, src);
89 class DummyZ : public ModeHandler
92 DummyZ(Module* parent) : ModeHandler(parent, "namebase", 'Z', PARAM_ALWAYS, MODETYPE_CHANNEL)
98 class ModuleNamedModes : public Module
103 ModuleNamedModes() : cmd(this), dummyZ(this)
109 ServerInstance->Modules->AddService(cmd);
110 ServerInstance->Modules->AddService(dummyZ);
112 Implementation eventlist[] = { I_OnPreMode };
113 ServerInstance->Modules->Attach(eventlist, this, 1);
118 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
123 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
126 ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters)
129 return MOD_RES_PASSTHRU;
130 if (parameters[1].find('Z') == std::string::npos)
131 return MOD_RES_PASSTHRU;
132 if (parameters.size() <= 2)
134 DisplayList(source, channel);
138 std::vector<std::string> newparms;
139 newparms.push_back(parameters[0]);
140 newparms.push_back(parameters[1]);
142 std::string modelist = newparms[1];
144 unsigned int param_at = 2;
145 for(unsigned int i = 0; i < modelist.length(); i++)
147 unsigned char modechar = modelist[i];
148 if (modechar == '+' || modechar == '-')
150 adding = (modechar == '+');
153 ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL);
157 std::string name, value;
158 if (param_at < parameters.size())
159 name = parameters[param_at++];
160 std::string::size_type eq = name.find('=');
161 if (eq != std::string::npos)
163 value = name.substr(eq + 1);
164 name = name.substr(0, eq);
166 for(char letter = 'A'; modechar == 0 && letter <= 'z'; letter++)
168 mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
169 if (mh && mh->name == name)
171 if (mh->GetNumParams(adding))
175 newparms.push_back(value);
188 modelist[i] = modechar;
190 modelist.erase(i--, 1);
192 else if (mh && mh->GetNumParams(adding) && param_at < parameters.size())
194 newparms.push_back(parameters[param_at++]);
197 newparms[1] = modelist;
198 ServerInstance->Modes->Process(newparms, source, false);
203 MODULE_INIT(ModuleNamedModes)