X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_oper%2Fcmd_die.cpp;h=5fe64352058c615ef9065444f7df1082f37e41f7;hb=55fa754510a00ea6691b9448389b006136d9e628;hp=63e4c596a82a47b11f40108e1f1c1493e43075c7;hpb=c67d3103e9f7397f0ab9631bf07a5e5547deb2c3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/coremods/core_oper/cmd_die.cpp b/src/coremods/core_oper/cmd_die.cpp index 63e4c596a..5fe643520 100644 --- a/src/coremods/core_oper/cmd_die.cpp +++ b/src/coremods/core_oper/cmd_die.cpp @@ -19,46 +19,63 @@ #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 = ""; } - /** 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& parameters, User *user); -}; + flags_needed = 'o'; + syntax = ""; +} -#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& 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)