]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_restart.cpp
Clean up Command constructor
[user/henk/code/inspircd.git] / src / commands / cmd_restart.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /** Handle /RESTART
17  */
18 class CommandRestart : public Command
19 {
20  public:
21         /** Constructor for restart.
22          */
23         CommandRestart(Module* parent) : Command(parent,"RESTART",1,1) { flags_needed = 'o'; syntax = "<password>"; }
24         /** Handle command.
25          * @param parameters The parameters to the comamnd
26          * @param pcnt The number of parameters passed to teh command
27          * @param user The user issuing the command
28          * @return A value from CmdResult to indicate command success or failure.
29          */
30         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
31 };
32
33 CmdResult CommandRestart::Handle (const std::vector<std::string>& parameters, User *user)
34 {
35         ServerInstance->Logs->Log("COMMAND",DEFAULT,"Restart: %s",user->nick.c_str());
36         if (!ServerInstance->PassCompare(user, ServerInstance->Config->restartpass, parameters[0].c_str(), ServerInstance->Config->powerhash))
37         {
38                 ServerInstance->SNO->WriteGlobalSno('a', "RESTART command from %s!%s@%s, restarting server.", user->nick.c_str(), user->ident.c_str(), user->host.c_str());
39
40                 try
41                 {
42                         ServerInstance->Restart("Server restarting.");
43                 }
44                 catch (...)
45                 {
46                         /* We dont actually get here unless theres some fatal and unrecoverable error. */
47                         exit(0);
48                 }
49         }
50         else
51         {
52                 ServerInstance->SNO->WriteGlobalSno('a', "Failed RESTART Command from %s!%s@%s.", user->nick.c_str(), user->ident.c_str(), user->host.c_str());
53                 return CMD_FAILURE;
54         }
55
56         return CMD_SUCCESS;
57 }
58
59
60 COMMAND_INIT(CommandRestart)