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(LocalUser* user, Channel* channel)
24 Numeric::ParamBuilder<1> numeric(user, 961);
25 numeric.AddStatic(channel->name);
27 const ModeParser::ModeHandlerMap& mhs = ServerInstance->Modes->GetModes(MODETYPE_CHANNEL);
28 for (ModeParser::ModeHandlerMap::const_iterator i = mhs.begin(); i != mhs.end(); ++i)
30 ModeHandler* mh = i->second;
31 if (!channel->IsModeSet(mh))
33 numeric.Add("+" + mh->name);
34 if (mh->GetNumParams(true))
36 if ((mh->name == "key") && (!channel->HasUser(user)) && (!user->HasPrivPermission("channels/auspex")))
39 numeric.Add(channel->GetModeParameter(mh));
43 user->WriteNumeric(960, channel->name, "End of mode list");
46 class CommandProp : public SplitCommand
49 CommandProp(Module* parent)
50 : SplitCommand(parent, "PROP", 1)
52 syntax = "<user|channel> {[+-]<mode> [<value>]}*";
55 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* src)
57 Channel* const chan = ServerInstance->FindChan(parameters[0]);
60 src->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
64 if (parameters.size() == 1)
66 DisplayList(src, chan);
70 Modes::ChangeList modes;
71 while (i < parameters.size())
73 std::string prop = parameters[i++];
76 bool plus = prop[0] != '-';
77 if (prop[0] == '+' || prop[0] == '-')
78 prop.erase(prop.begin());
80 ModeHandler* mh = ServerInstance->Modes->FindMode(prop, MODETYPE_CHANNEL);
83 if (mh->GetNumParams(plus))
85 if (i != parameters.size())
86 modes.push(mh, plus, parameters[i++]);
92 ServerInstance->Modes->ProcessSingle(src, chan, NULL, modes, ModeParser::MODE_CHECKACCESS);
97 class DummyZ : public ModeHandler
100 DummyZ(Module* parent) : ModeHandler(parent, "namebase", 'Z', PARAM_ALWAYS, MODETYPE_CHANNEL)
105 // Handle /MODE #chan Z
106 void DisplayList(User* user, Channel* chan)
109 ::DisplayList(static_cast<LocalUser*>(user), chan);
113 class ModuleNamedModes : public Module
118 ModuleNamedModes() : cmd(this), dummyZ(this)
122 Version GetVersion() CXX11_OVERRIDE
124 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
129 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
132 ModResult OnPreMode(User* source, User* dest, Channel* channel, Modes::ChangeList& modes) CXX11_OVERRIDE
135 return MOD_RES_PASSTHRU;
137 Modes::ChangeList::List& list = modes.getlist();
138 for (Modes::ChangeList::List::iterator i = list.begin(); i != list.end(); )
140 Modes::Change& curr = *i;
141 // Replace all namebase (dummyZ) modes being changed with the actual
142 // mode handler and parameter. The parameter format of the namebase mode is
143 // <modename>[=<parameter>].
144 if (curr.mh == &dummyZ)
146 std::string name = curr.param;
148 std::string::size_type eq = name.find('=');
149 if (eq != std::string::npos)
151 value.assign(name, eq + 1, std::string::npos);
155 ModeHandler* mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL);
158 // Mode handler not found
164 if (mh->GetNumParams(curr.adding))
168 // Mode needs a parameter but there wasn't one
173 // Change parameter to the text after the '='
177 // Put the actual ModeHandler in place of the namebase handler
184 return MOD_RES_PASSTHRU;
188 MODULE_INIT(ModuleNamedModes)