]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kill.cpp
Merge pull request #591 from SaberUK/master+config-tweaks
[user/henk/code/inspircd.git] / src / commands / cmd_kill.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /** Handle /KILL. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandKill : public Command
30 {
31         std::string lastuuid;
32         std::string killreason;
33
34  public:
35         /** Constructor for kill.
36          */
37         CommandKill ( Module* parent) : Command(parent,"KILL",2,2) {
38                 flags_needed = 'o';
39                 syntax = "<nickname> <reason>";
40                 TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
41         }
42         /** Handle command.
43          * @param parameters The parameters to the comamnd
44          * @param pcnt The number of parameters passed to teh command
45          * @param user The user issuing the command
46          * @return A value from CmdResult to indicate command success or failure.
47          */
48         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
49         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
50         {
51                 // FindNick() doesn't work here because we quit the target user in Handle() which
52                 // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
53                 // was for a local user, otherwise it contains the uuid of the user who was killed.
54                 if (lastuuid.empty())
55                         return ROUTE_LOCALONLY;
56                 return ROUTE_BROADCAST;
57         }
58
59         void EncodeParameter(std::string& param, int index)
60         {
61                 // Manually translate the nick -> uuid (see above), and also the reason (params[1])
62                 // because we decorate it if the oper is local and want remote servers to see the
63                 // decorated reason not the original.
64                 param = ((index == 0) ? lastuuid : killreason);
65         }
66 };
67
68 /** Handle /KILL
69  */
70 CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User *user)
71 {
72         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
73         if (CommandParser::LoopCall(user, this, parameters, 0))
74         {
75                 // If we got a colon delimited list of nicks then the handler ran for each nick,
76                 // and KILL commands were broadcast for remote targets.
77                 return CMD_FAILURE;
78         }
79
80         User *u = ServerInstance->FindNick(parameters[0]);
81         if ((u) && (!IS_SERVER(u)))
82         {
83                 /*
84                  * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
85                  * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
86                  *
87                  * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
88                  * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
89                  */
90
91                 if (IS_LOCAL(user))
92                 {
93                         /*
94                          * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
95                          * and the other half not. This would be a bad thing. ;p -- w00t
96                          */
97                         ModResult MOD_RESULT;
98                         FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, u, parameters[1]));
99
100                         if (MOD_RESULT == MOD_RES_DENY)
101                                 return CMD_FAILURE;
102
103                         killreason = "Killed (";
104                         if (!ServerInstance->Config->HideKillsServer.empty())
105                         {
106                                 // hidekills is on, use it
107                                 killreason += ServerInstance->Config->HideKillsServer;
108                         }
109                         else
110                         {
111                                 // hidekills is off, do nothing
112                                 killreason += user->nick;
113                         }
114
115                         killreason += " (" + parameters[1] + "))";
116                 }
117                 else
118                 {
119                         /* Leave it alone, remote server has already formatted it */
120                         killreason.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxQuit);
121                 }
122
123                 /*
124                  * Now we need to decide whether or not to send a local or remote snotice. Currently this checking is a little flawed.
125                  * No time to fix it right now, so left a note. -- w00t
126                  */
127                 if (!IS_LOCAL(u))
128                 {
129                         // remote kill
130                         ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
131                         this->lastuuid = u->uuid;
132                 }
133                 else
134                 {
135                         // local kill
136                         /*
137                          * 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
138                          * snotices, C will get a local kill snotice. this isn't accurate, and needs fixing at some stage. -- w00t
139                          */
140                         if (IS_LOCAL(user))
141                                 ServerInstance->SNO->WriteGlobalSno('k',"Local Kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
142                         else
143                                 ServerInstance->SNO->WriteToSnoMask('k',"Local Kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
144                         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());
145                         /* Bug #419, make sure this message can only occur once even in the case of multiple KILL messages crossing the network, and change to show
146                          * hidekillsserver as source if possible
147                          */
148                         if (!u->quitting)
149                         {
150                                 u->Write(":%s KILL %s :%s!%s!%s (%s)", ServerInstance->Config->HideKillsServer.empty() ? user->GetFullHost().c_str() : ServerInstance->Config->HideKillsServer.c_str(),
151                                                 u->nick.c_str(),
152                                                 ServerInstance->Config->ServerName.c_str(),
153                                                 user->dhost.c_str(),
154                                                 ServerInstance->Config->HideKillsServer.empty() ? user->nick.c_str() : ServerInstance->Config->HideKillsServer.c_str(),
155                                                 parameters[1].c_str());
156                         }
157
158                         this->lastuuid.clear();
159                 }
160
161                 // send the quit out
162                 ServerInstance->Users->QuitUser(u, killreason);
163         }
164         else
165         {
166                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
167                 return CMD_FAILURE;
168         }
169
170         return CMD_SUCCESS;
171 }
172
173
174 COMMAND_INIT(CommandKill)