]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_die.cpp
Refactor port binding, warning not yet tested fully
[user/henk/code/inspircd.git] / src / cmd_die.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 "configreader.h"
15 #include "users.h"
16 #include "commands/cmd_die.h"
17 #include "exitcodes.h"
18
19 extern "C" command_t* init_command(InspIRCd* Instance)
20 {
21         return new cmd_die(Instance);
22 }
23
24 /** Handle /DIE
25  */
26 CmdResult cmd_die::Handle (const char** parameters, int pcnt, userrec *user)
27 {
28         if (!strcmp(parameters[0],ServerInstance->Config->diepass))
29         {
30                 ServerInstance->Log(SPARSE, "/DIE command from %s!%s@%s, terminating in %d seconds...", user->nick, user->ident, user->host, ServerInstance->Config->DieDelay);
31                 
32                 /* This would just be WriteOpers(), but as we just sleep() and then die then the write buffers never get flushed.
33                  * so we iterate the oper list, writing the message and immediately trying to flush their write buffer.
34                  */
35                 
36                 for (std::vector<userrec*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
37                 {
38                         userrec* a = *i;
39                         
40                         if (IS_LOCAL(a) && (a->modes[UM_SERVERNOTICE]))
41                         {
42                                 a->WriteServ("NOTICE %s :*** DIE command from %s!%s@%s, terminating...", a->nick, a->nick, a->ident, a->host);
43                                 a->FlushWriteBuf();
44                         }
45                 }
46                 
47                 if (ServerInstance->Config->DieDelay)
48                         sleep(ServerInstance->Config->DieDelay);
49
50                 InspIRCd::Exit(EXIT_STATUS_DIE);
51         }
52         else
53         {
54                 ServerInstance->Log(SPARSE, "Failed /DIE command from %s!%s@%s", user->nick, user->ident, user->host);
55                 ServerInstance->WriteOpers("*** Failed DIE Command from %s!%s@%s.",user->nick,user->ident,user->host);
56                 return CMD_FAILURE;
57         }
58         return CMD_SUCCESS;
59 }