]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kill.cpp
Merge pull request #301 from Adam-/insp20+bindrehash
[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  public:
32         /** Constructor for kill.
33          */
34         CommandKill ( Module* parent) : Command(parent,"KILL",2,2) {
35                 flags_needed = 'o';
36                 syntax = "<nickname> <reason>";
37                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
38         }
39         /** Handle command.
40          * @param parameters The parameters to the comamnd
41          * @param pcnt The number of parameters passed to teh command
42          * @param user The user issuing the command
43          * @return A value from CmdResult to indicate command success or failure.
44          */
45         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
46         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
47         {
48                 // local kills of remote users are routed via the OnRemoteKill hook
49                 if (IS_LOCAL(user))
50                         return ROUTE_LOCALONLY;
51                 return ROUTE_BROADCAST;
52         }
53 };
54
55 /** Handle /KILL
56  */
57 CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User *user)
58 {
59         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
60         if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
61                 return CMD_SUCCESS;
62
63         User *u = ServerInstance->FindNick(parameters[0]);
64         char killreason[MAXBUF];
65         ModResult MOD_RESULT;
66
67         if (u)
68         {
69                 /*
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.
72                  *
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
75                  */
76                 if (IS_LOCAL(user))
77                 {
78                         /*
79                          * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
80                          * and the other half not. This would be a bad thing. ;p -- w00t
81                          */
82                         FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, u, parameters[1]));
83
84                         if (MOD_RESULT == MOD_RES_DENY)
85                                 return CMD_FAILURE;
86
87                         if (!ServerInstance->Config->HideKillsServer.empty())
88                         {
89                                 // hidekills is on, use it
90                                 snprintf(killreason, ServerInstance->Config->Limits.MaxQuit, "Killed (%s (%s))", ServerInstance->Config->HideKillsServer.c_str(), parameters[1].c_str());
91                         }
92                         else
93                         {
94                                 // hidekills is off, do nothing
95                                 snprintf(killreason, ServerInstance->Config->Limits.MaxQuit, "Killed (%s (%s))", user->nick.c_str(), parameters[1].c_str());
96                         }
97                 }
98                 else
99                 {
100                         /* Leave it alone, remote server has already formatted it */
101                         strlcpy(killreason, parameters[1].c_str(), ServerInstance->Config->Limits.MaxQuit);
102                 }
103
104                 /*
105                  * Now we need to decide whether or not to send a local or remote snotice. Currently this checking is a little flawed.
106                  * No time to fix it right now, so left a note. -- w00t
107                  */
108                 if (!IS_LOCAL(u))
109                 {
110                         // remote kill
111                         ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s!%s@%s (%s)", user->nick.c_str(), u->nick.c_str(), u->ident.c_str(), u->host.c_str(), parameters[1].c_str());
112                         FOREACH_MOD(I_OnRemoteKill, OnRemoteKill(user, u, killreason, killreason));
113                 }
114                 else
115                 {
116                         // local kill
117                         /*
118                          * 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
119                          * snotices, C will get a local kill snotice. this isn't accurate, and needs fixing at some stage. -- w00t
120                          */
121                         ServerInstance->SNO->WriteToSnoMask('k',"Local Kill by %s: %s!%s@%s (%s)", user->nick.c_str(), u->nick.c_str(), u->ident.c_str(), u->host.c_str(), parameters[1].c_str());
122                         ServerInstance->Logs->Log("KILL",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());
123                         /* 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
124                          * hidekillsserver as source if possible
125                          */
126                         if (!u->quitting)
127                         {
128                                 u->Write(":%s KILL %s :%s!%s!%s (%s)", ServerInstance->Config->HideKillsServer.empty() ? user->GetFullHost().c_str() : ServerInstance->Config->HideKillsServer.c_str(),
129                                                 u->nick.c_str(),
130                                                 ServerInstance->Config->ServerName.c_str(),
131                                                 user->dhost.c_str(),
132                                                 ServerInstance->Config->HideKillsServer.empty() ? user->nick.c_str() : ServerInstance->Config->HideKillsServer.c_str(),
133                                                 parameters[1].c_str());
134                         }
135                 }
136
137                 // send the quit out
138                 ServerInstance->Users->QuitUser(u, killreason);
139         }
140         else
141         {
142                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
143                 return CMD_FAILURE;
144         }
145
146         return CMD_SUCCESS;
147 }
148
149
150 COMMAND_INIT(CommandKill)