2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2005, 2007 Robin Burchell <robin+git@viroteck.net>
8 * Copyright (C) 2005-2006 Craig Edwards <craigedwards@brainbox.cc>
9 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
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/>.
28 * This module supports the use of the +q and +a usermodes, but should work without them too.
29 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
30 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
33 /** Base class for /FPART and /REMOVE
35 class RemoveBase : public Command
38 ChanModeReference& nokicksmode;
41 unsigned int protectedrank;
43 RemoveBase(Module* Creator, bool& snk, ChanModeReference& nkm, const char* cmdn)
44 : Command(Creator, cmdn, 2, 3)
50 CmdResult HandleRMB(const std::vector<std::string>& parameters, User *user, bool fpart)
56 // If the command is a /REMOVE then detect the parameter order
57 bool neworder = ((fpart) || (parameters[0][0] == '#'));
59 /* Set these to the parameters needed, the new version of this module switches it's parameters around
60 * supplying a new command with the new order while keeping the old /remove with the older order.
61 * /remove <nick> <channel> [reason ...]
62 * /fpart <channel> <nick> [reason ...]
64 const std::string& channame = parameters[neworder ? 0 : 1];
65 const std::string& username = parameters[neworder ? 1 : 0];
67 /* Look up the user we're meant to be removing from the channel */
69 target = ServerInstance->FindNickOnly(username);
71 target = ServerInstance->FindNick(username);
73 /* And the channel we're meant to be removing them from */
74 channel = ServerInstance->FindChan(channame);
76 /* Fix by brain - someone needs to learn to validate their input! */
77 if ((!target) || (target->registered != REG_ALL) || (!channel))
79 user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", !channel ? channame.c_str() : username.c_str());
83 if (!channel->HasUser(target))
85 user->WriteNotice(InspIRCd::Format("*** The user %s is not on channel %s", target->nick.c_str(), channel->name.c_str()));
89 if (target->server->IsULine())
91 user->WriteNumeric(482, "%s :Only a u-line may remove a u-line from a channel.", channame.c_str());
95 /* We support the +Q channel mode via. the m_nokicks module, if the module is loaded and the mode is set then disallow the /remove */
96 if ((!IS_LOCAL(user)) || (!supportnokicks) || (!channel->IsModeSet(nokicksmode)))
98 /* We'll let everyone remove their level and below, eg:
99 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
100 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
101 * Nobody may remove people with >= protectedrank rank.
103 unsigned int ulevel = channel->GetPrefixValue(user);
104 unsigned int tlevel = channel->GetPrefixValue(target);
105 if ((!IS_LOCAL(user)) || ((ulevel > VOICE_VALUE) && (ulevel >= tlevel) && ((protectedrank == 0) || (tlevel < protectedrank))))
107 // REMOVE will be sent to the target's server and it will reply with a PART (or do nothing if it doesn't understand the command)
108 if (!IS_LOCAL(target))
110 // Send an ENCAP REMOVE with parameters being in the old <user> <chan> order which is
111 // compatible with both 2.0 and 2.2. This also turns FPART into REMOVE.
112 std::vector<std::string> p;
113 p.push_back(target->uuid);
114 p.push_back(channel->name);
115 if (parameters.size() > 2)
116 p.push_back(":" + parameters[2]);
117 ServerInstance->PI->SendEncapsulatedData(target->server->GetName(), "REMOVE", p, user);
122 std::string reasonparam;
124 /* If a reason is given, use it */
125 if(parameters.size() > 2)
126 reasonparam = parameters[2];
128 reasonparam = "No reason given";
130 /* Build up the part reason string. */
131 reason = "Removed by " + user->nick + ": " + reasonparam;
133 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s removed %s from the channel", channel->name.c_str(), user->nick.c_str(), target->nick.c_str());
134 target->WriteNotice("*** " + user->nick + " removed you from " + channel->name + " with the message: " + reasonparam);
136 channel->PartUser(target, reason);
140 user->WriteNotice(InspIRCd::Format("*** You do not have access to /remove %s from %s", target->nick.c_str(), channel->name.c_str()));
146 /* m_nokicks.so was loaded and +Q was set, block! */
147 user->WriteNumeric(ERR_RESTRICTED, "%s :Can't remove user %s from channel (nokicks mode is set)", channel->name.c_str(), target->nick.c_str());
157 class CommandRemove : public RemoveBase
160 CommandRemove(Module* Creator, bool& snk, ChanModeReference& nkm)
161 : RemoveBase(Creator, snk, nkm, "REMOVE")
163 syntax = "<channel> <nick> [<reason>]";
164 TRANSLATE3(TR_NICK, TR_TEXT, TR_TEXT);
167 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
169 return HandleRMB(parameters, user, false);
175 class CommandFpart : public RemoveBase
178 CommandFpart(Module* Creator, bool& snk, ChanModeReference& nkm)
179 : RemoveBase(Creator, snk, nkm, "FPART")
181 syntax = "<channel> <nick> [<reason>]";
182 TRANSLATE3(TR_TEXT, TR_NICK, TR_TEXT);
185 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
187 return HandleRMB(parameters, user, true);
191 class ModuleRemove : public Module
193 ChanModeReference nokicksmode;
200 : nokicksmode(this, "nokick")
201 , cmd1(this, supportnokicks, nokicksmode)
202 , cmd2(this, supportnokicks, nokicksmode)
206 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
211 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
213 ConfigTag* tag = ServerInstance->Config->ConfValue("remove");
214 supportnokicks = tag->getBool("supportnokicks");
215 cmd1.protectedrank = cmd2.protectedrank = tag->getInt("protectedrank", 50000);
218 Version GetVersion() CXX11_OVERRIDE
220 return Version("Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel", VF_OPTCOMMON | VF_VENDOR);
224 MODULE_INIT(ModuleRemove)