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/>.
27 /* $ModDesc: Provides a /remove command, this is mostly an alternative to /kick, except makes users appear to have parted the channel */
30 * This module supports the use of the +q and +a usermodes, but should work without them too.
31 * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself.
32 * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes.
35 /** Base class for /FPART and /REMOVE
37 class RemoveBase : public Command
43 RemoveBase(Module* Creator, bool& snk, const char* cmdn)
44 : Command(Creator, cmdn, 2, 3), supportnokicks(snk)
48 CmdResult HandleRMB(const std::vector<std::string>& parameters, User *user, bool neworder)
55 std::string protectkey;
56 std::string founderkey;
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 channame = parameters[ neworder ? 0 : 1].c_str();
65 username = parameters[ neworder ? 1 : 0].c_str();
67 /* Look up the user we're meant to be removing from the channel */
68 target = ServerInstance->FindNick(username);
70 /* And the channel we're meant to be removing them from */
71 channel = ServerInstance->FindChan(channame);
73 /* Fix by brain - someone needs to learn to validate their input! */
74 if (!target || !channel)
76 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), !target ? username : channame);
80 if (!channel->HasUser(target))
82 user->WriteServ( "NOTICE %s :*** The user %s is not on channel %s", user->nick.c_str(), target->nick.c_str(), channel->name.c_str());
86 int ulevel = channel->GetPrefixValue(user);
87 int tlevel = channel->GetPrefixValue(target);
89 hasnokicks = (ServerInstance->Modules->Find("m_nokicks.so") && channel->IsModeSet('Q'));
91 if((ServerInstance->ULine(target->server) || ServerInstance->ULine(target->nick.c_str()))){
92 user->WriteNumeric(482, "%s %s :Only a u-line may remove a u-line from a channel.", user->nick.c_str(), channame);
96 /* 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 */
97 if ((!IS_LOCAL(user)) || (!supportnokicks || !hasnokicks))
99 /* We'll let everyone remove their level and below, eg:
100 * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1)
101 * a ulined target will get a higher level than it's possible for a /remover to get..so they're safe.
102 * Nobody may remove a founder.
104 if ((!IS_LOCAL(user)) || ((ulevel > VOICE_VALUE) && (ulevel >= tlevel) && (tlevel != 50000)))
106 // no you can't just go from a std::ostringstream to a std::string, Om. -nenolod
107 // but you can do this, nenolod -brain
109 std::string reasonparam("No reason given");
111 /* If a reason is given, use it */
112 if(parameters.size() > 2)
114 /* Join params 2 ... pcnt - 1 (inclusive) into one */
115 irc::stringjoiner reason_join(" ", parameters, 2, parameters.size() - 1);
116 reasonparam = reason_join.GetJoined();
119 /* Build up the part reason string. */
120 reason = "Removed by " + user->nick + ": " + reasonparam;
122 channel->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s removed %s from the channel", channel->name.c_str(), user->nick.c_str(), target->nick.c_str());
123 target->WriteServ("NOTICE %s :*** %s removed you from %s with the message: %s", target->nick.c_str(), user->nick.c_str(), channel->name.c_str(), reasonparam.c_str());
125 channel->PartUser(target, reason);
129 user->WriteServ( "NOTICE %s :*** You do not have access to /remove %s from %s", user->nick.c_str(), target->nick.c_str(), channel->name.c_str());
135 /* m_nokicks.so was loaded and +Q was set, block! */
136 user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick.c_str(), channel->name.c_str(), target->nick.c_str());
142 virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) = 0;
147 class CommandRemove : public RemoveBase
150 CommandRemove(Module* Creator, bool& snk)
151 : RemoveBase(Creator, snk, "REMOVE")
153 syntax = "<nick> <channel> [<reason>]";
154 TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
157 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
159 return HandleRMB(parameters, user, false);
162 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
164 User* dest = ServerInstance->FindNick(parameters[0]);
166 return ROUTE_OPT_UCAST(dest->server);
167 return ROUTE_LOCALONLY;
173 class CommandFpart : public RemoveBase
176 CommandFpart(Module* Creator, bool& snk)
177 : RemoveBase(Creator, snk, "FPART")
179 syntax = "<channel> <nick> [<reason>]";
180 TRANSLATE4(TR_TEXT, TR_NICK, TR_TEXT, TR_END);
183 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
185 return HandleRMB(parameters, user, true);
188 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
190 User* dest = ServerInstance->FindNick(parameters[1]);
192 return ROUTE_OPT_UCAST(dest->server);
193 return ROUTE_LOCALONLY;
197 class ModuleRemove : public Module
205 ModuleRemove() : cmd1(this, supportnokicks), cmd2(this, supportnokicks)
207 ServerInstance->AddCommand(&cmd1);
208 ServerInstance->AddCommand(&cmd2);
210 Implementation eventlist[] = { I_On005Numeric, I_OnRehash };
211 ServerInstance->Modules->Attach(eventlist, this, 2);
215 virtual void On005Numeric(std::string &output)
217 output.append(" REMOVE");
220 virtual void OnRehash(User* user)
223 supportnokicks = conf.ReadFlag("remove", "supportnokicks", 0);
226 virtual ~ModuleRemove()
230 virtual Version GetVersion()
232 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);
237 MODULE_INIT(ModuleRemove)