]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_kill.cpp
c1b282bfafbe7b7ef4bf5a536c94a31b3cb2c839
[user/henk/code/inspircd.git] / src / cmd_kill.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain.net>
8  *                <Craig.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "inspircd_io.h"
22 #include <time.h>
23 #include <string>
24 #ifdef GCC3
25 #include <ext/hash_map>
26 #else
27 #include <hash_map>
28 #endif
29 #include <map>
30 #include <sstream>
31 #include <vector>
32 #include <deque>
33 #include "users.h"
34 #include "ctables.h"
35 #include "globals.h"
36 #include "modules.h"
37 #include "dynamic.h"
38 #include "wildcard.h"
39 #include "message.h"
40 #include "commands.h"
41 #include "mode.h"
42 #include "xline.h"
43 #include "inspstring.h"
44 #include "dnsqueue.h"
45 #include "helperfuncs.h"
46 #include "hashcomp.h"
47 #include "socketengine.h"
48 #include "typedefs.h"
49 #include "command_parse.h"
50 #include "cmd_kill.h"
51
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
54 extern int MODCOUNT;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
57 extern time_t TIME;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern whowas_hash whowas;
61 extern std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[65536];
64
65 void cmd_kill::Handle (char **parameters, int pcnt, userrec *user)
66 {
67         userrec *u = Find(parameters[0]);
68         char killreason[MAXBUF];
69
70         log(DEBUG,"kill: %s %s",parameters[0],parameters[1]);
71         if (u)
72         {
73                 log(DEBUG,"into kill mechanism");
74                 int MOD_RESULT = 0;
75                 FOREACH_RESULT(OnKill(user,u,parameters[1]));
76                 if (MOD_RESULT) {
77                         log(DEBUG,"A module prevented the kill with result %d",MOD_RESULT);
78                         return;
79                 }
80
81                 if (u->fd < 0)
82                 {
83                         // remote kill
84                         WriteOpers("*** Remote kill by %s: %s!%s@%s (%s)",user->nick,u->nick,u->ident,u->host,parameters[1]);
85                         snprintf(killreason,MAXBUF,"[%s] Killed (%s (%s))",Config->ServerName,user->nick,parameters[1]);
86                         WriteCommonExcept(u,"QUIT :%s",killreason);
87
88                         FOREACH_MOD OnRemoteKill(user,u,killreason);
89                         
90                         user_hash::iterator iter = clientlist.find(u->nick);
91                         if (iter != clientlist.end())
92                         {
93                                 log(DEBUG,"deleting user hash value %d",iter->second);
94                                 clientlist.erase(iter);
95                         }
96                         if (u->registered == 7)
97                         {
98                                 purge_empty_chans(u);
99                         }
100                         if (u->fd > -1)
101                                 fd_ref_table[u->fd] = NULL;
102                         delete u;
103                 }
104                 else
105                 {
106                         // local kill
107                         log(DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick, Config->ServerName,user->dhost,user->nick,parameters[1]);
108                         WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, Config->ServerName,user->dhost,user->nick,parameters[1]);
109                         WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)",user->nick,u->nick,u->ident,u->host,parameters[1]);
110                         snprintf(killreason,MAXBUF,"Killed (%s (%s))",user->nick,parameters[1]);
111                         kill_link(u,killreason);
112                 }
113         }
114         else
115         {
116                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
117         }
118 }
119
120