]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_kill.cpp
8e8c4fadc5f5f08090cfda25a510ce7c03a3670c
[user/henk/code/inspircd.git] / src / coremods / core_oper / 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 #include "core_oper.h"
24
25 CommandKill::CommandKill(Module* parent)
26         : Command(parent, "KILL", 2, 2)
27 {
28         flags_needed = 'o';
29         syntax = "<nickname> <reason>";
30         TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
31 }
32
33
34 /** Handle /KILL
35  */
36 CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User *user)
37 {
38         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
39         if (CommandParser::LoopCall(user, this, parameters, 0))
40         {
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.
43                 return CMD_FAILURE;
44         }
45
46         User* target = ServerInstance->FindNick(parameters[0]);
47         if (!target)
48         {
49                 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
50                 return CMD_FAILURE;
51         }
52
53         /*
54          * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
55          * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
56          *
57          * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
58          * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
59          */
60
61         if (IS_LOCAL(user))
62         {
63                 /*
64                  * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
65                  * and the other half not. This would be a bad thing. ;p -- w00t
66                  */
67                 ModResult MOD_RESULT;
68                 FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, target, parameters[1]));
69
70                 if (MOD_RESULT == MOD_RES_DENY)
71                         return CMD_FAILURE;
72
73                 killreason = "Killed (";
74                 if (!ServerInstance->Config->HideKillsServer.empty())
75                 {
76                         // hidekills is on, use it
77                         killreason += ServerInstance->Config->HideKillsServer;
78                 }
79                 else
80                 {
81                         // hidekills is off, do nothing
82                         killreason += user->nick;
83                 }
84
85                 killreason += " (" + parameters[1] + "))";
86         }
87         else
88         {
89                 /* Leave it alone, remote server has already formatted it */
90                 killreason.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxQuit);
91         }
92
93         if ((!ServerInstance->Config->HideULineKills) || (!user->server->IsULine()))
94         {
95                 if (IS_LOCAL(user) && IS_LOCAL(target))
96                         ServerInstance->SNO->WriteGlobalSno('k', "Local kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
97                 else
98                         ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
99         }
100
101         if (IS_LOCAL(user) || IS_LOCAL(target))
102                 ServerInstance->Logs->Log("KILL", LOG_DEFAULT, "%s KILL: %s :%s!%s!%s (%s)",
103                                 IS_LOCAL(user) && IS_LOCAL(target) ? "LOCAL" : "REMOTE",
104                                 target->nick.c_str(),
105                                 ServerInstance->Config->ServerName.c_str(), user->dhost.c_str(), user->nick.c_str(),
106                                 parameters[1].c_str());
107
108         if (IS_LOCAL(target))
109         {
110                 target->Write(":%s KILL %s :%s",
111                                 ServerInstance->Config->HideKillsServer.empty() ? user->GetFullHost().c_str() : ServerInstance->Config->HideKillsServer.c_str(),
112                                 target->nick.c_str(),
113                                 parameters[1].c_str());
114
115                 this->lastuuid.clear();
116         }
117         else
118         {
119                 this->lastuuid = target->uuid;
120         }
121
122         // send the quit out
123         ServerInstance->Users->QuitUser(target, killreason);
124
125         return CMD_SUCCESS;
126 }
127
128 RouteDescriptor CommandKill::GetRouting(User* user, const std::vector<std::string>& parameters)
129 {
130         // FindNick() doesn't work here because we quit the target user in Handle() which
131         // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
132         // was for a local user, otherwise it contains the uuid of the user who was killed.
133         if (lastuuid.empty())
134                 return ROUTE_LOCALONLY;
135         return ROUTE_BROADCAST;
136 }
137
138
139 void CommandKill::EncodeParameter(std::string& param, int index)
140 {
141         // Manually translate the nick -> uuid (see above), and also the reason (params[1])
142         // because we decorate it if the oper is local and want remote servers to see the
143         // decorated reason not the original.
144         param = ((index == 0) ? lastuuid : killreason);
145 }