]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_kill.cpp
Cut down on debug on restart
[user/henk/code/inspircd.git] / src / cmd_kill.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "configreader.h"
16 #include "users.h"
17 #include "modules.h"
18 #include "wildcard.h"
19 #include "commands/cmd_kill.h"
20
21 extern "C" command_t* init_command(InspIRCd* Instance)
22 {
23         return new cmd_kill(Instance);
24 }
25
26 /** Handle /KILL
27  */
28 CmdResult cmd_kill::Handle (const char** parameters, int pcnt, userrec *user)
29 {
30         /* Allow comma seperated lists of users for /KILL (thanks w00t) */
31         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
32                 return CMD_SUCCESS;
33
34         userrec *u = ServerInstance->FindNick(parameters[0]);
35         char killreason[MAXBUF];
36         int MOD_RESULT = 0;
37
38         ServerInstance->Log(DEBUG,"kill: %s %s", parameters[0], parameters[1]);
39
40         if (u)
41         {
42                 ServerInstance->Log(DEBUG, "into kill mechanism");
43                 FOREACH_RESULT(I_OnKill, OnKill(user, u, parameters[1]));
44
45                 if (MOD_RESULT)
46                 {
47                         ServerInstance->Log(DEBUG, "A module prevented the kill with result %d", MOD_RESULT);
48                         return CMD_FAILURE;
49                 }
50
51                 if (!IS_LOCAL(u))
52                 {
53                         // remote kill
54                         ServerInstance->SNO->WriteToSnoMask('k',"Remote kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]);
55                         snprintf(killreason, MAXQUIT,"[%s] Killed (%s (%s))", ServerInstance->Config->ServerName, user->nick, parameters[1]);
56                         u->WriteCommonExcept("QUIT :%s", killreason);
57                         FOREACH_MOD(I_OnRemoteKill, OnRemoteKill(user, u, killreason));
58                         
59                         user_hash::iterator iter = ServerInstance->clientlist.find(u->nick);
60
61                         if (iter != ServerInstance->clientlist.end())
62                         {
63                                 ServerInstance->Log(DEBUG,"deleting user hash value %d", iter->second);
64                                 ServerInstance->clientlist.erase(iter);
65                         }
66
67                         if (u->registered == REG_ALL)
68                         {
69                                 u->PurgeEmptyChannels();
70                         }
71
72                         if (u == user)
73                         {
74                                 std::string original_command = std::string("KILL ") + u->nick + " :"+parameters[1];
75                                 FOREACH_MOD(I_OnPostCommand,OnPostCommand("KILL", parameters, pcnt, user, CMD_SUCCESS,original_command));
76                                 return CMD_USER_DELETED;
77                         }
78                         DELETE(u);
79                 }
80                 else
81                 {
82                         // local kill
83                         ServerInstance->Log(DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick, ServerInstance->Config->ServerName, user->dhost, user->nick, parameters[1]);
84                         user->WriteTo(u, "KILL %s :%s!%s!%s (%s)", u->nick, ServerInstance->Config->ServerName, user->dhost, user->nick, parameters[1]);
85                         ServerInstance->SNO->WriteToSnoMask('k',"Local Kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]);
86                         snprintf(killreason,MAXQUIT,"Killed (%s (%s))", user->nick, parameters[1]);
87                         userrec::QuitUser(ServerInstance, u, killreason);
88
89                         if (u == user)
90                                 return CMD_USER_DELETED;
91                 }
92         }
93         else
94         {
95                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick, parameters[0]);
96                 return CMD_FAILURE;
97         }
98
99         return CMD_SUCCESS;
100 }
101