]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_kill.cpp
Change includes, use --libs_r rather than mysql_config --libs, we want re-enterant...
[user/henk/code/inspircd.git] / src / cmd_kill.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.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 #include <vector>
18 #include "inspircd_config.h"
19 #include "hash_map.h"
20 #include "configreader.h"
21 #include "users.h"
22 #include "modules.h"
23 #include "commands.h"
24 #include "helperfuncs.h"
25 #include "commands/cmd_kill.h"
26
27 extern ServerConfig* Config;
28 extern int MODCOUNT;
29 extern std::vector<Module*> modules;
30 extern std::vector<ircd_module*> factory;
31 extern user_hash clientlist;
32
33 void cmd_kill::Handle (const char** parameters, int pcnt, userrec *user)
34 {
35         userrec *u = Find(parameters[0]);
36         char killreason[MAXBUF];
37         int MOD_RESULT = 0;
38
39         log(DEBUG,"kill: %s %s", parameters[0], parameters[1]);
40
41         if (u)
42         {
43                 log(DEBUG, "into kill mechanism");
44                 FOREACH_RESULT(I_OnKill, OnKill(user, u, parameters[1]));
45
46                 if (MOD_RESULT)
47                 {
48                         log(DEBUG, "A module prevented the kill with result %d", MOD_RESULT);
49                         return;
50                 }
51
52                 if (!IS_LOCAL(u))
53                 {
54                         // remote kill
55                         WriteOpers("*** Remote kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]);
56                         snprintf(killreason, MAXQUIT,"[%s] Killed (%s (%s))", Config->ServerName, user->nick, parameters[1]);
57                         WriteCommonExcept(u, "QUIT :%s", killreason);
58                         FOREACH_MOD(I_OnRemoteKill, OnRemoteKill(user, u, killreason));
59                         
60                         user_hash::iterator iter = clientlist.find(u->nick);
61
62                         if (iter != clientlist.end())
63                         {
64                                 log(DEBUG,"deleting user hash value %d", iter->second);
65                                 clientlist.erase(iter);
66                         }
67
68                         if (u->registered == 7)
69                         {
70                                 purge_empty_chans(u);
71                         }
72
73                         DELETE(u);
74                 }
75                 else
76                 {
77                         // local kill
78                         log(DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick, Config->ServerName, user->dhost, user->nick, parameters[1]);
79                         WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, Config->ServerName, user->dhost, user->nick, parameters[1]);
80                         WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]);
81                         snprintf(killreason,MAXQUIT,"Killed (%s (%s))", user->nick, parameters[1]);
82                         kill_link(u, killreason);
83                 }
84         }
85         else
86         {
87                 WriteServ(user->fd, "401 %s %s :No such nick/channel", user->nick, parameters[0]);
88         }
89 }