]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kill.cpp
Make User:: nick/ident/dhost/fullname and some other things std::string instead of...
[user/henk/code/inspircd.git] / src / commands / cmd_kill.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "commands/cmd_kill.h"
16
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
18 {
19         return new CommandKill(Instance);
20 }
21
22 /** Handle /KILL
23  */
24 CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User *user)
25 {
26         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
27         if (ServerInstance->Parser->LoopCall(user, this, parameters, 0))
28                 return CMD_SUCCESS;
29
30         User *u = ServerInstance->FindNick(parameters[0]);
31         char killreason[MAXBUF];
32         int MOD_RESULT = 0;
33
34         if (u)
35         {
36                 /*
37                  * Here, we need to decide how to munge kill messages. Whether to hide killer, what to show opers, etc.
38                  * We only do this when the command is being issued LOCALLY, for remote KILL, we just copy the message we got.
39                  *
40                  * This conditional is so that we only append the "Killed (" prefix ONCE. If killer is remote, then the kill
41                  * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
42                  */
43                 if (IS_LOCAL(user))
44                 {
45                         /*
46                          * Moved this event inside the IS_LOCAL check also, we don't want half the network killing a user
47                          * and the other half not. This would be a bad thing. ;p -- w00t
48                          */
49                         FOREACH_RESULT(I_OnKill, OnKill(user, u, parameters[1]));
50
51                         if (MOD_RESULT)
52                                 return CMD_FAILURE;
53
54                         if (*ServerInstance->Config->HideKillsServer)
55                         {
56                                 // hidekills is on, use it
57                                 snprintf(killreason, MAXQUIT, "Killed (%s (%s))", ServerInstance->Config->HideKillsServer, parameters[1].c_str());
58                         }
59                         else
60                         {
61                                 // hidekills is off, do nothing
62                                 snprintf(killreason, MAXQUIT, "Killed (%s (%s))", user->nick.c_str(), parameters[1].c_str());
63                         }
64                 }
65                 else
66                 {
67                         /* Leave it alone, remote server has already formatted it */
68                         strlcpy(killreason, parameters[1].c_str(), MAXQUIT);
69                 }
70
71                 /*
72                  * Now we need to decide whether or not to send a local or remote snotice. Currently this checking is a little flawed.
73                  * No time to fix it right now, so left a note. -- w00t
74                  */
75                 if (!IS_LOCAL(u))
76                 {
77                         // remote kill
78                         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, parameters[1].c_str());
79                         FOREACH_MOD(I_OnRemoteKill, OnRemoteKill(user, u, killreason, killreason));
80                 }
81                 else
82                 {
83                         // local kill
84                         /*
85                          * 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
86                          * snotices, C will get a local kill snotice. this isn't accurate, and needs fixing at some stage. -- w00t
87                          */
88                         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, parameters[1].c_str());
89                         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());
90                         /* 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
91                          * hidekillsserver as source if possible
92                          */
93                         if (!u->quitting)
94                         {
95                                 u->Write(":%s KILL %s :%s!%s!%s (%s)", *ServerInstance->Config->HideKillsServer ? ServerInstance->Config->HideKillsServer : user->GetFullHost().c_str(),
96                                                 u->nick.c_str(),
97                                                 ServerInstance->Config->ServerName,
98                                                 user->dhost.c_str(),
99                                                 *ServerInstance->Config->HideKillsServer ? ServerInstance->Config->HideKillsServer : user->nick.c_str(),
100                                                 parameters[1].c_str());
101                         }
102                 }
103
104                 // send the quit out
105                 ServerInstance->Users->QuitUser(u, killreason);
106         }
107         else
108         {
109                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
110                 return CMD_FAILURE;
111         }
112
113         return CMD_SUCCESS;
114 }
115