]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_kill.cpp
6b356d011cd93a7b28b43c6e41e33fac3c2d2dd4
[user/henk/code/inspircd.git] / src / coremods / core_oper / cmd_kill.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2016 Adam <Adam@anope.org>
6  *   Copyright (C) 2012-2014, 2018 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12  *   Copyright (C) 2007 Craig Edwards <brain@inspircd.org>
13  *
14  * This file is part of InspIRCd.  InspIRCd is free software: you can
15  * redistribute it and/or modify it under the terms of the GNU General Public
16  * License as published by the Free Software Foundation, version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but WITHOUT
19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21  * details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26
27
28 #include "inspircd.h"
29 #include "core_oper.h"
30
31 CommandKill::CommandKill(Module* parent)
32         : Command(parent, "KILL", 2, 2)
33         , protoev(parent, name)
34 {
35         flags_needed = 'o';
36         syntax = "<nick>[,<nick>]+ :<reason>";
37         TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
38 }
39
40 class KillMessage : public ClientProtocol::Message
41 {
42  public:
43         KillMessage(ClientProtocol::EventProvider& protoev, User* user, LocalUser* target, const std::string& text, const std::string& hidenick)
44                 : ClientProtocol::Message("KILL", NULL)
45         {
46                 if (hidenick.empty())
47                         SetSourceUser(user);
48                 else
49                         SetSource(hidenick);
50
51                 PushParamRef(target->nick);
52                 PushParamRef(text);
53         }
54 };
55
56 /** Handle /KILL
57  */
58 CmdResult CommandKill::Handle(User* user, const Params& parameters)
59 {
60         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
61         if (CommandParser::LoopCall(user, this, parameters, 0))
62         {
63                 // If we got a colon delimited list of nicks then the handler ran for each nick,
64                 // and KILL commands were broadcast for remote targets.
65                 return CMD_FAILURE;
66         }
67
68         User* target = ServerInstance->FindNick(parameters[0]);
69         if (!target)
70         {
71                 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
72                 return CMD_FAILURE;
73         }
74
75         /*
76          * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
77          * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
78          *
79          * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
80          * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
81          */
82
83         if (IS_LOCAL(user))
84         {
85                 /*
86                  * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
87                  * and the other half not. This would be a bad thing. ;p -- w00t
88                  */
89                 ModResult MOD_RESULT;
90                 FIRST_MOD_RESULT(OnKill, MOD_RESULT, (user, target, parameters[1]));
91
92                 if (MOD_RESULT == MOD_RES_DENY)
93                         return CMD_FAILURE;
94
95                 killreason = "Killed (";
96                 if (!hidenick.empty())
97                 {
98                         // hidekills is on, use it
99                         killreason += hidenick;
100                 }
101                 else
102                 {
103                         // hidekills is off, do nothing
104                         killreason += user->nick;
105                 }
106
107                 killreason += " (" + parameters[1] + "))";
108         }
109         else
110         {
111                 /* Leave it alone, remote server has already formatted it */
112                 killreason.assign(parameters[1], 0, ServerInstance->Config->Limits.MaxQuit);
113         }
114
115         if ((!hideuline) || (!user->server->IsULine()))
116         {
117                 if (IS_LOCAL(user) && IS_LOCAL(target))
118                         ServerInstance->SNO->WriteGlobalSno('k', "Local kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
119                 else
120                         ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), target->GetFullRealHost().c_str(), parameters[1].c_str());
121         }
122
123         if (IS_LOCAL(target))
124         {
125                 LocalUser* localu = IS_LOCAL(target);
126                 KillMessage msg(protoev, user, localu, killreason, hidenick);
127                 ClientProtocol::Event killevent(protoev, msg);
128                 localu->Send(killevent);
129
130                 this->lastuuid.clear();
131         }
132         else
133         {
134                 this->lastuuid = target->uuid;
135         }
136
137         // send the quit out
138         ServerInstance->Users->QuitUser(target, killreason);
139
140         return CMD_SUCCESS;
141 }
142
143 RouteDescriptor CommandKill::GetRouting(User* user, const Params& parameters)
144 {
145         // FindNick() doesn't work here because we quit the target user in Handle() which
146         // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
147         // was for a local user, otherwise it contains the uuid of the user who was killed.
148         if (lastuuid.empty())
149                 return ROUTE_LOCALONLY;
150         return ROUTE_BROADCAST;
151 }
152
153
154 void CommandKill::EncodeParameter(std::string& param, unsigned int index)
155 {
156         // Manually translate the nick -> uuid (see above), and also the reason (params[1])
157         // because we decorate it if the oper is local and want remote servers to see the
158         // decorated reason not the original.
159         param = ((index == 0) ? lastuuid : killreason);
160 }