]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_kill.cpp
01179d61dece15cf9effe4b55f288e5da545b28a
[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         , protoev(parent, name)
28 {
29         flags_needed = 'o';
30         syntax = "<nick>[,<nick>]+ :<reason>";
31         TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
32 }
33
34 class KillMessage : public ClientProtocol::Message
35 {
36  public:
37         KillMessage(ClientProtocol::EventProvider& protoev, User* user, LocalUser* target, const std::string& text, const std::string& hidenick)
38                 : ClientProtocol::Message("KILL", NULL)
39         {
40                 if (hidenick.empty())
41                         SetSourceUser(user);
42                 else
43                         SetSource(hidenick);
44
45                 PushParamRef(target->nick);
46                 PushParamRef(text);
47         }
48 };
49
50 /** Handle /KILL
51  */
52 CmdResult CommandKill::Handle(User* user, const Params& parameters)
53 {
54         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
55         if (CommandParser::LoopCall(user, this, parameters, 0))
56         {
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.
59                 return CMD_FAILURE;
60         }
61
62         User* target = ServerInstance->FindNick(parameters[0]);
63         if (!target)
64         {
65                 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
66                 return CMD_FAILURE;
67         }
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
77         if (IS_LOCAL(user))
78         {
79                 /*
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
82                  */
83                 ModResult MOD_RESULT;
84                 FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, target, parameters[1]));
85
86                 if (MOD_RESULT == MOD_RES_DENY)
87                         return CMD_FAILURE;
88
89                 killreason = "Killed (";
90                 if (!hidenick.empty())
91                 {
92                         // hidekills is on, use it
93                         killreason += hidenick;
94                 }
95                 else
96                 {
97                         // hidekills is off, do nothing
98                         killreason += user->nick;
99                 }
100
101                 killreason += " (" + parameters[1] + "))";
102         }
103         else
104         {
105                 /* Leave it alone, remote server has already formatted it */
106                 killreason.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxQuit);
107         }
108
109         if ((!hideuline) || (!user->server->IsULine()))
110         {
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());
113                 else
114                         ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
115         }
116
117         if (IS_LOCAL(target))
118         {
119                 LocalUser* localu = IS_LOCAL(target);
120                 KillMessage msg(protoev, user, localu, killreason, hidenick);
121                 ClientProtocol::Event killevent(protoev, msg);
122                 localu->Send(killevent);
123
124                 this->lastuuid.clear();
125         }
126         else
127         {
128                 this->lastuuid = target->uuid;
129         }
130
131         // send the quit out
132         ServerInstance->Users->QuitUser(target, killreason);
133
134         return CMD_SUCCESS;
135 }
136
137 RouteDescriptor CommandKill::GetRouting(User* user, const Params& parameters)
138 {
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;
145 }
146
147
148 void CommandKill::EncodeParameter(std::string& param, unsigned int index)
149 {
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);
154 }