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