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/>.
25 RPL_ENDOFPROPLIST = 960,
29 static void DisplayList(LocalUser* user, Channel* channel)
31 Numeric::ParamBuilder<1> numeric(user, RPL_PROPLIST);
32 numeric.AddStatic(channel->name);
34 const ModeParser::ModeHandlerMap& mhs = ServerInstance->Modes->GetModes(MODETYPE_CHANNEL);
35 for (ModeParser::ModeHandlerMap::const_iterator i = mhs.begin(); i != mhs.end(); ++i)
37 ModeHandler* mh = i->second;
38 if (!channel->IsModeSet(mh))
40 numeric.Add("+" + mh->name);
41 if (mh->NeedsParam(true))
43 if ((mh->name == "key") && (!channel->HasUser(user)) && (!user->HasPrivPermission("channels/auspex")))
46 numeric.Add(channel->GetModeParameter(mh));
50 user->WriteNumeric(RPL_ENDOFPROPLIST, channel->name, "End of mode list");
53 class CommandProp : public SplitCommand
56 CommandProp(Module* parent)
57 : SplitCommand(parent, "PROP", 1)
59 syntax = "<user|channel> {[+-]<mode> [<value>]}*";
62 CmdResult HandleLocal(LocalUser* src, const Params& parameters) CXX11_OVERRIDE
64 Channel* const chan = ServerInstance->FindChan(parameters[0]);
67 src->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
71 if (parameters.size() == 1)
73 DisplayList(src, chan);
77 Modes::ChangeList modes;
78 while (i < parameters.size())
80 std::string prop = parameters[i++];
83 bool plus = prop[0] != '-';
84 if (prop[0] == '+' || prop[0] == '-')
85 prop.erase(prop.begin());
87 ModeHandler* mh = ServerInstance->Modes->FindMode(prop, MODETYPE_CHANNEL);
90 if (mh->NeedsParam(plus))
92 if (i != parameters.size())
93 modes.push(mh, plus, parameters[i++]);
99 ServerInstance->Modes->ProcessSingle(src, chan, NULL, modes, ModeParser::MODE_CHECKACCESS);
104 class DummyZ : public ModeHandler
107 DummyZ(Module* parent) : ModeHandler(parent, "namebase", 'Z', PARAM_ALWAYS, MODETYPE_CHANNEL)
112 // Handle /MODE #chan Z
113 void DisplayList(User* user, Channel* chan) CXX11_OVERRIDE
116 ::DisplayList(static_cast<LocalUser*>(user), chan);
120 class ModuleNamedModes : public Module
125 ModuleNamedModes() : cmd(this), dummyZ(this)
129 Version GetVersion() CXX11_OVERRIDE
131 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
134 void Prioritize() CXX11_OVERRIDE
136 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
139 ModResult OnPreMode(User* source, User* dest, Channel* channel, Modes::ChangeList& modes) CXX11_OVERRIDE
142 return MOD_RES_PASSTHRU;
144 Modes::ChangeList::List& list = modes.getlist();
145 for (Modes::ChangeList::List::iterator i = list.begin(); i != list.end(); )
147 Modes::Change& curr = *i;
148 // Replace all namebase (dummyZ) modes being changed with the actual
149 // mode handler and parameter. The parameter format of the namebase mode is
150 // <modename>[=<parameter>].
151 if (curr.mh == &dummyZ)
153 std::string name = curr.param;
155 std::string::size_type eq = name.find('=');
156 if (eq != std::string::npos)
158 value.assign(name, eq + 1, std::string::npos);
162 ModeHandler* mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL);
165 // Mode handler not found
171 if (mh->NeedsParam(curr.adding))
175 // Mode needs a parameter but there wasn't one
180 // Change parameter to the text after the '='
184 // Put the actual ModeHandler in place of the namebase handler
191 return MOD_RES_PASSTHRU;
195 MODULE_INIT(ModuleNamedModes)