]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_oper/cmd_die.cpp
Change type of log messages to MODNAME in several modules
[user/henk/code/inspircd.git] / src / coremods / core_oper / cmd_die.cpp
index 63e4c596a82a47b11f40108e1f1c1493e43075c7..5fe64352058c615ef9065444f7df1082f37e41f7 100644 (file)
 
 
 #include "inspircd.h"
+#include "exitcodes.h"
+#include "core_oper.h"
 
-/** Handle /DIE.
- */
-class CommandDie : public Command
+CommandDie::CommandDie(Module* parent)
+       : Command(parent, "DIE", 1)
 {
- public:
-       /** Constructor for die.
-        */
-       CommandDie ( Module* parent) : Command(parent,"DIE",1) { flags_needed = 'o'; syntax = "<password>"; }
-       /** Handle command.
-        * @param parameters The parameters to the command
-        * @param user The user issuing the command
-        * @return A value from CmdResult to indicate command success or failure.
-        */
-       CmdResult Handle(const std::vector<std::string>& parameters, User *user);
-};
+       flags_needed = 'o';
+       syntax = "<server>";
+}
 
-#include "exitcodes.h"
+static void QuitAll()
+{
+       const std::string quitmsg = "Server shutdown";
+       const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
+       while (!list.empty())
+               ServerInstance->Users.QuitUser(list.front(), quitmsg);
+}
+
+void DieRestart::SendError(const std::string& message)
+{
+       const std::string unregline = "ERROR :" + message;
+       const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
+       for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i)
+       {
+               LocalUser* user = *i;
+               if (user->registered == REG_ALL)
+               {
+                       user->WriteNotice(message);
+               }
+               else
+               {
+                       // Unregistered connections receive ERROR, not a NOTICE
+                       user->Write(unregline);
+               }
+       }
+}
 
 /** Handle /DIE
  */
 CmdResult CommandDie::Handle (const std::vector<std::string>& parameters, User *user)
 {
-       if (ServerInstance->PassCompare(user, ServerInstance->Config->diepass, parameters[0], ServerInstance->Config->powerhash))
+       if (DieRestart::CheckPass(user, parameters[0], "diepass"))
        {
                {
                        std::string diebuf = "*** DIE command from " + user->GetFullHost() + ". Terminating.";
-                       ServerInstance->Logs->Log("COMMAND", LOG_SPARSE, diebuf);
-                       ServerInstance->SendError(diebuf);
+                       ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, diebuf);
+                       DieRestart::SendError(diebuf);
                }
 
+               QuitAll();
                ServerInstance->Exit(EXIT_STATUS_DIE);
        }
        else
        {
-               ServerInstance->Logs->Log("COMMAND", LOG_SPARSE, "Failed /DIE command from %s", user->GetFullRealHost().c_str());
+               ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Failed /DIE command from %s", user->GetFullRealHost().c_str());
                ServerInstance->SNO->WriteGlobalSno('a', "Failed DIE Command from %s.", user->GetFullRealHost().c_str());
                return CMD_FAILURE;
        }
        return CMD_SUCCESS;
 }
-
-COMMAND_INIT(CommandDie)