]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_die.cpp
Remove an extern, partly because it's unused, partly because it then gets shadowed...
[user/henk/code/inspircd.git] / src / cmd_die.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 <unistd.h>
18 #include <string>
19 #include <vector>
20 #include "configreader.h"
21 #include "users.h"
22 #include "commands.h"
23 #include "helperfuncs.h"
24 #include "cmd_die.h"
25
26 extern ServerConfig* Config;
27 extern std::vector<userrec*> all_opers;
28
29 void cmd_die::Handle (char **parameters, int pcnt, userrec *user)
30 {
31         if (!strcmp(parameters[0],Config->diepass))
32         {
33                 log(SPARSE, "/DIE command from %s!%s@%s, terminating in %d seconds...", user->nick, user->ident, user->host, Config->DieDelay);
34                 
35                 /* This would just be WriteOpers(), but as we just sleep() and then die then the write buffers never get flushed.
36                  * so we iterate the oper list, writing the message and immediately trying to flush their write buffer.
37                  */
38                 
39                 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
40                 {
41                         userrec* a = *i;
42                         
43                         if (IS_LOCAL(a) && (a->modebits & UM_SERVERNOTICE))
44                         {
45                                 WriteServ(a->fd, "NOTICE %s :*** DIE command from %s!%s@%s, terminating...", a->nick, a->nick, a->ident, a->host);
46                                 a->FlushWriteBuf();
47                         }
48                 }
49                 
50                 sleep(Config->DieDelay);
51                 Exit(ERROR);
52         }
53         else
54         {
55                 log(SPARSE, "Failed /DIE command from %s!%s@%s", user->nick, user->ident, user->host);
56                 WriteOpers("*** Failed DIE Command from %s!%s@%s.",user->nick,user->ident,user->host);
57         }
58 }