2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2016 Adam <Adam@anope.org>
6 * Copyright (C) 2012-2014, 2018 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2007 Craig Edwards <brain@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "core_oper.h"
31 CommandKill::CommandKill(Module* parent)
32 : Command(parent, "KILL", 2, 2)
33 , protoev(parent, name)
36 syntax = "<nick>[,<nick>]+ :<reason>";
37 TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
40 class KillMessage : public ClientProtocol::Message
43 KillMessage(ClientProtocol::EventProvider& protoev, User* user, LocalUser* target, const std::string& text, const std::string& hidenick)
44 : ClientProtocol::Message("KILL", NULL)
51 PushParamRef(target->nick);
58 CmdResult CommandKill::Handle(User* user, const Params& parameters)
60 /* Allow comma separated lists of users for /KILL (thanks w00t) */
61 if (CommandParser::LoopCall(user, this, parameters, 0))
63 // If we got a colon delimited list of nicks then the handler ran for each nick,
64 // and KILL commands were broadcast for remote targets.
68 User* target = ServerInstance->FindNick(parameters[0]);
71 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
76 * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
77 * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
79 * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
80 * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
86 * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
87 * and the other half not. This would be a bad thing. ;p -- w00t
90 FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, target, parameters[1]));
92 if (MOD_RESULT == MOD_RES_DENY)
95 killreason = "Killed (";
96 if (!hidenick.empty())
98 // hidekills is on, use it
99 killreason += hidenick;
103 // hidekills is off, do nothing
104 killreason += user->nick;
107 killreason += " (" + parameters[1] + "))";
111 /* Leave it alone, remote server has already formatted it */
112 killreason.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxQuit);
115 if ((!hideuline) || (!user->server->IsULine()))
117 if (IS_LOCAL(user) && IS_LOCAL(target))
118 ServerInstance->SNO->WriteGlobalSno('k', "Local kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
120 ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
123 if (IS_LOCAL(target))
125 LocalUser* localu = IS_LOCAL(target);
126 KillMessage msg(protoev, user, localu, killreason, hidenick);
127 ClientProtocol::Event killevent(protoev, msg);
128 localu->Send(killevent);
130 this->lastuuid.clear();
134 this->lastuuid = target->uuid;
138 ServerInstance->Users->QuitUser(target, killreason);
143 RouteDescriptor CommandKill::GetRouting(User* user, const Params& parameters)
145 // FindNick() doesn't work here because we quit the target user in Handle() which
146 // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
147 // was for a local user, otherwise it contains the uuid of the user who was killed.
148 if (lastuuid.empty())
149 return ROUTE_LOCALONLY;
150 return ROUTE_BROADCAST;
154 void CommandKill::EncodeParameter(std::string& param, unsigned int index)
156 // Manually translate the nick -> uuid (see above), and also the reason (params[1])
157 // because we decorate it if the oper is local and want remote servers to see the
158 // decorated reason not the original.
159 param = ((index == 0) ? lastuuid : killreason);