2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "core_oper.h"
25 CommandKill::CommandKill(Module* parent)
26 : Command(parent, "KILL", 2, 2)
27 , protoev(parent, name)
30 syntax = "<nickname> <reason>";
31 TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
34 class KillMessage : public ClientProtocol::Message
37 KillMessage(ClientProtocol::EventProvider& protoev, User* user, LocalUser* target, const std::string& text)
38 : ClientProtocol::Message("KILL", NULL)
40 if (ServerInstance->Config->HideKillsServer.empty())
43 SetSource(ServerInstance->Config->HideKillsServer);
45 PushParamRef(target->nick);
52 CmdResult CommandKill::Handle(User* user, const Params& parameters)
54 /* Allow comma seperated lists of users for /KILL (thanks w00t) */
55 if (CommandParser::LoopCall(user, this, parameters, 0))
57 // If we got a colon delimited list of nicks then the handler ran for each nick,
58 // and KILL commands were broadcast for remote targets.
62 User* target = ServerInstance->FindNick(parameters[0]);
65 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
70 * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
71 * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
73 * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
74 * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
80 * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
81 * and the other half not. This would be a bad thing. ;p -- w00t
84 FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, target, parameters[1]));
86 if (MOD_RESULT == MOD_RES_DENY)
89 killreason = "Killed (";
90 if (!ServerInstance->Config->HideKillsServer.empty())
92 // hidekills is on, use it
93 killreason += ServerInstance->Config->HideKillsServer;
97 // hidekills is off, do nothing
98 killreason += user->nick;
101 killreason += " (" + parameters[1] + "))";
105 /* Leave it alone, remote server has already formatted it */
106 killreason.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxQuit);
109 if ((!ServerInstance->Config->HideULineKills) || (!user->server->IsULine()))
111 if (IS_LOCAL(user) && IS_LOCAL(target))
112 ServerInstance->SNO->WriteGlobalSno('k', "Local kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
114 ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
117 if (IS_LOCAL(target))
119 LocalUser* localu = IS_LOCAL(target);
120 KillMessage msg(protoev, user, localu, killreason);
121 ClientProtocol::Event killevent(protoev, msg);
122 localu->Send(killevent);
124 this->lastuuid.clear();
128 this->lastuuid = target->uuid;
132 ServerInstance->Users->QuitUser(target, killreason);
137 RouteDescriptor CommandKill::GetRouting(User* user, const Params& parameters)
139 // FindNick() doesn't work here because we quit the target user in Handle() which
140 // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
141 // was for a local user, otherwise it contains the uuid of the user who was killed.
142 if (lastuuid.empty())
143 return ROUTE_LOCALONLY;
144 return ROUTE_BROADCAST;
148 void CommandKill::EncodeParameter(std::string& param, unsigned int index)
150 // Manually translate the nick -> uuid (see above), and also the reason (params[1])
151 // because we decorate it if the oper is local and want remote servers to see the
152 // decorated reason not the original.
153 param = ((index == 0) ? lastuuid : killreason);