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 %s :End of mode list", user->nick.c_str(), 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 void init() CXX11_OVERRIDE
108 ServerInstance->Modules->AddService(cmd);
109 ServerInstance->Modules->AddService(dummyZ);
112 Version GetVersion() CXX11_OVERRIDE
114 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
119 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
122 ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
125 return MOD_RES_PASSTHRU;
126 if (parameters[1].find('Z') == std::string::npos)
127 return MOD_RES_PASSTHRU;
128 if (parameters.size() <= 2)
130 DisplayList(source, channel);
134 std::vector<std::string> newparms;
135 newparms.push_back(parameters[0]);
136 newparms.push_back(parameters[1]);
138 std::string modelist = newparms[1];
140 unsigned int param_at = 2;
141 for(unsigned int i = 0; i < modelist.length(); i++)
143 unsigned char modechar = modelist[i];
144 if (modechar == '+' || modechar == '-')
146 adding = (modechar == '+');
149 ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL);
153 std::string name, value;
154 if (param_at < parameters.size())
155 name = parameters[param_at++];
156 std::string::size_type eq = name.find('=');
157 if (eq != std::string::npos)
159 value = name.substr(eq + 1);
160 name = name.substr(0, eq);
162 for(char letter = 'A'; modechar == 0 && letter <= 'z'; letter++)
164 mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
165 if (mh && mh->name == name)
167 if (mh->GetNumParams(adding))
171 newparms.push_back(value);
184 modelist[i] = modechar;
186 modelist.erase(i--, 1);
188 else if (mh && mh->GetNumParams(adding) && param_at < parameters.size())
190 newparms.push_back(parameters[param_at++]);
193 newparms[1] = modelist;
194 ServerInstance->Modes->Process(newparms, source);
199 MODULE_INIT(ModuleNamedModes)