]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kill.cpp
1001d4c8ae1c3567271b471e2aca1f5fd906ab62
[user/henk/code/inspircd.git] / src / commands / cmd_kill.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /** Handle /KILL. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandKill : public Command
22 {
23  public:
24         /** Constructor for kill.
25          */
26         CommandKill ( Module* parent) : Command(parent,"KILL",2,2) { flags_needed = 'o'; syntax = "<nickname> <reason>"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36 /** Handle /KILL
37  */
38 CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User *user)
39 {
40         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
41         if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
42                 return CMD_SUCCESS;
43
44         User *u = ServerInstance->FindNick(parameters[0]);
45         char killreason[MAXBUF];
46         ModResult MOD_RESULT;
47
48         if (u)
49         {
50                 /*
51                  * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
52                  * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
53                  *
54                  * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
55                  * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
56                  */
57                 if (IS_LOCAL(user))
58                 {
59                         /*
60                          * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
61                          * and the other half not. This would be a bad thing. ;p -- w00t
62                          */
63                         FIRST_MOD_RESULT(ServerInstance, OnKill, MOD_RESULT, (user, u, parameters[1]));
64
65                         if (MOD_RESULT == MOD_RES_DENY)
66                                 return CMD_FAILURE;
67
68                         if (*ServerInstance->Config->HideKillsServer)
69                         {
70                                 // hidekills is on, use it
71                                 snprintf(killreason, ServerInstance->Config->Limits.MaxQuit, "Killed (%s (%s))", ServerInstance->Config->HideKillsServer, parameters[1].c_str());
72                         }
73                         else
74                         {
75                                 // hidekills is off, do nothing
76                                 snprintf(killreason, ServerInstance->Config->Limits.MaxQuit, "Killed (%s (%s))", user->nick.c_str(), parameters[1].c_str());
77                         }
78                 }
79                 else
80                 {
81                         /* Leave it alone, remote server has already formatted it */
82                         strlcpy(killreason, parameters[1].c_str(), ServerInstance->Config->Limits.MaxQuit);
83                 }
84
85                 /*
86                  * Now we need to decide whether or not to send a local or remote snotice. Currently this checking is a little flawed.
87                  * No time to fix it right now, so left a note. -- w00t
88                  */
89                 if (!IS_LOCAL(u))
90                 {
91                         // remote kill
92                         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());
93                         FOREACH_MOD(I_OnRemoteKill, OnRemoteKill(user, u, killreason, killreason));
94                 }
95                 else
96                 {
97                         // local kill
98                         /*
99                          * 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
100                          * snotices, C will get a local kill snotice. this isn't accurate, and needs fixing at some stage. -- w00t
101                          */
102                         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());
103                         ServerInstance->Logs->Log("KILL",DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick.c_str(), ServerInstance->Config->ServerName, user->dhost.c_str(), user->nick.c_str(), parameters[1].c_str());
104                         /* 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
105                          * hidekillsserver as source if possible
106                          */
107                         if (!u->quitting)
108                         {
109                                 u->Write(":%s KILL %s :%s!%s!%s (%s)", *ServerInstance->Config->HideKillsServer ? ServerInstance->Config->HideKillsServer : user->GetFullHost().c_str(),
110                                                 u->nick.c_str(),
111                                                 ServerInstance->Config->ServerName,
112                                                 user->dhost.c_str(),
113                                                 *ServerInstance->Config->HideKillsServer ? ServerInstance->Config->HideKillsServer : user->nick.c_str(),
114                                                 parameters[1].c_str());
115                         }
116                 }
117
118                 // send the quit out
119                 ServerInstance->Users->QuitUser(u, killreason);
120         }
121         else
122         {
123                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
124                 return CMD_FAILURE;
125         }
126
127         return CMD_SUCCESS;
128 }
129
130
131 COMMAND_INIT(CommandKill)