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)
29 syntax = "<nickname> <reason>";
30 TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
36 CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User *user)
38 /* Allow comma seperated lists of users for /KILL (thanks w00t) */
39 if (CommandParser::LoopCall(user, this, parameters, 0))
41 // If we got a colon delimited list of nicks then the handler ran for each nick,
42 // and KILL commands were broadcast for remote targets.
46 User *u = ServerInstance->FindNick(parameters[0]);
47 if ((u) && (!IS_SERVER(u)))
50 * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
51 * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
53 * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
54 * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
60 * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
61 * and the other half not. This would be a bad thing. ;p -- w00t
64 FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, u, parameters[1]));
66 if (MOD_RESULT == MOD_RES_DENY)
69 killreason = "Killed (";
70 if (!ServerInstance->Config->HideKillsServer.empty())
72 // hidekills is on, use it
73 killreason += ServerInstance->Config->HideKillsServer;
77 // hidekills is off, do nothing
78 killreason += user->nick;
81 killreason += " (" + parameters[1] + "))";
85 /* Leave it alone, remote server has already formatted it */
86 killreason.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxQuit);
90 * Now we need to decide whether or not to send a local or remote snotice. Currently this checking is a little flawed.
91 * No time to fix it right now, so left a note. -- w00t
96 if (!user->server->IsULine())
97 ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
98 this->lastuuid = u->uuid;
104 * XXX - this isn't entirely correct, servers A - B - C, oper on A, client on C. Oper kills client, A and B will get remote kill
105 * snotices, C will get a local kill snotice. this isn't accurate, and needs fixing at some stage. -- w00t
107 if (!user->server->IsULine())
110 ServerInstance->SNO->WriteGlobalSno('k',"Local Kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
112 ServerInstance->SNO->WriteToSnoMask('k',"Local Kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
115 ServerInstance->Logs->Log("KILL", LOG_DEFAULT, "LOCAL KILL: %s :%s!%s!%s (%s)", u->nick.c_str(), ServerInstance->Config->ServerName.c_str(), user->dhost.c_str(), user->nick.c_str(), parameters[1].c_str());
117 u->Write(":%s KILL %s :%s!%s!%s (%s)", ServerInstance->Config->HideKillsServer.empty() ? user->GetFullHost().c_str() : ServerInstance->Config->HideKillsServer.c_str(),
119 ServerInstance->Config->ServerName.c_str(),
121 ServerInstance->Config->HideKillsServer.empty() ? user->nick.c_str() : ServerInstance->Config->HideKillsServer.c_str(),
122 parameters[1].c_str());
124 this->lastuuid.clear();
128 ServerInstance->Users->QuitUser(u, killreason);
132 user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
139 RouteDescriptor CommandKill::GetRouting(User* user, const std::vector<std::string>& parameters)
141 // FindNick() doesn't work here because we quit the target user in Handle() which
142 // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
143 // was for a local user, otherwise it contains the uuid of the user who was killed.
144 if (lastuuid.empty())
145 return ROUTE_LOCALONLY;
146 return ROUTE_BROADCAST;
150 void CommandKill::EncodeParameter(std::string& param, int index)
152 // Manually translate the nick -> uuid (see above), and also the reason (params[1])
153 // because we decorate it if the oper is local and want remote servers to see the
154 // decorated reason not the original.
155 param = ((index == 0) ? lastuuid : killreason);