2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
5 * Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2013, 2017-2019 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
9 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 RPL_ENDOFPROPLIST = 960,
34 static void DisplayList(LocalUser* user, Channel* channel)
36 Numeric::ParamBuilder<1> numeric(user, RPL_PROPLIST);
37 numeric.AddStatic(channel->name);
39 const ModeParser::ModeHandlerMap& mhs = ServerInstance->Modes->GetModes(MODETYPE_CHANNEL);
40 for (ModeParser::ModeHandlerMap::const_iterator i = mhs.begin(); i != mhs.end(); ++i)
42 ModeHandler* mh = i->second;
43 if (!channel->IsModeSet(mh))
45 numeric.Add("+" + mh->name);
46 ParamModeBase* pm = mh->IsParameterMode();
49 if ((pm->IsParameterSecret()) && (!channel->HasUser(user)) && (!user->HasPrivPermission("channels/auspex")))
50 numeric.Add("<" + mh->name + ">");
52 numeric.Add(channel->GetModeParameter(mh));
56 user->WriteNumeric(RPL_ENDOFPROPLIST, channel->name, "End of mode list");
59 class CommandProp : public SplitCommand
62 CommandProp(Module* parent)
63 : SplitCommand(parent, "PROP", 1)
65 syntax = "<channel> [[(+|-)]<mode> [<value>]]";
68 CmdResult HandleLocal(LocalUser* src, const Params& parameters) CXX11_OVERRIDE
70 Channel* const chan = ServerInstance->FindChan(parameters[0]);
73 src->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
77 if (parameters.size() == 1)
79 DisplayList(src, chan);
83 Modes::ChangeList modes;
84 while (i < parameters.size())
86 std::string prop = parameters[i++];
89 bool plus = prop[0] != '-';
90 if (prop[0] == '+' || prop[0] == '-')
91 prop.erase(prop.begin());
93 ModeHandler* mh = ServerInstance->Modes->FindMode(prop, MODETYPE_CHANNEL);
96 if (mh->NeedsParam(plus))
98 if (i != parameters.size())
99 modes.push(mh, plus, parameters[i++]);
102 modes.push(mh, plus);
105 ServerInstance->Modes->ProcessSingle(src, chan, NULL, modes, ModeParser::MODE_CHECKACCESS);
110 class DummyZ : public ModeHandler
113 DummyZ(Module* parent) : ModeHandler(parent, "namebase", 'Z', PARAM_ALWAYS, MODETYPE_CHANNEL)
118 // Handle /MODE #chan Z
119 void DisplayList(User* user, Channel* chan) CXX11_OVERRIDE
121 LocalUser* luser = IS_LOCAL(user);
123 ::DisplayList(luser, chan);
127 class ModuleNamedModes : public Module
132 ModuleNamedModes() : cmd(this), dummyZ(this)
136 Version GetVersion() CXX11_OVERRIDE
138 return Version("Provides support for adding and removing modes via their long names.", VF_VENDOR);
141 void Prioritize() CXX11_OVERRIDE
143 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
146 ModResult OnPreMode(User* source, User* dest, Channel* channel, Modes::ChangeList& modes) CXX11_OVERRIDE
149 return MOD_RES_PASSTHRU;
151 Modes::ChangeList::List& list = modes.getlist();
152 for (Modes::ChangeList::List::iterator i = list.begin(); i != list.end(); )
154 Modes::Change& curr = *i;
155 // Replace all namebase (dummyZ) modes being changed with the actual
156 // mode handler and parameter. The parameter format of the namebase mode is
157 // <modename>[=<parameter>].
158 if (curr.mh == &dummyZ)
160 std::string name = curr.param;
162 std::string::size_type eq = name.find('=');
163 if (eq != std::string::npos)
165 value.assign(name, eq + 1, std::string::npos);
169 ModeHandler* mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL);
172 // Mode handler not found
178 if (mh->NeedsParam(curr.adding))
182 // Mode needs a parameter but there wasn't one
187 // Change parameter to the text after the '='
191 // Put the actual ModeHandler in place of the namebase handler
198 return MOD_RES_PASSTHRU;
202 MODULE_INIT(ModuleNamedModes)