From 33137bba446212f89f7b94f50ace20db19b6d009 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sun, 17 May 2015 18:13:45 +0200 Subject: Move InspIRCd::SendError() to cmd_die Fix multiple ERROR messages being sent to unregistered users by removing the "Exiting with status..." message --- src/coremods/core_oper/cmd_die.cpp | 21 ++++++++++++++++++++- src/coremods/core_oper/cmd_restart.cpp | 2 +- src/coremods/core_oper/core_oper.h | 5 +++++ 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/coremods') diff --git a/src/coremods/core_oper/cmd_die.cpp b/src/coremods/core_oper/cmd_die.cpp index 5e7a6afcf..4bc6c25db 100644 --- a/src/coremods/core_oper/cmd_die.cpp +++ b/src/coremods/core_oper/cmd_die.cpp @@ -37,6 +37,25 @@ static void QuitAll() 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) @@ -46,7 +65,7 @@ CmdResult CommandDie::Handle (const std::vector& parameters, User * { std::string diebuf = "*** DIE command from " + user->GetFullHost() + ". Terminating."; ServerInstance->Logs->Log("COMMAND", LOG_SPARSE, diebuf); - ServerInstance->SendError(diebuf); + DieRestart::SendError(diebuf); } QuitAll(); diff --git a/src/coremods/core_oper/cmd_restart.cpp b/src/coremods/core_oper/cmd_restart.cpp index 4fad752a2..3e219727f 100644 --- a/src/coremods/core_oper/cmd_restart.cpp +++ b/src/coremods/core_oper/cmd_restart.cpp @@ -35,7 +35,7 @@ CmdResult CommandRestart::Handle (const std::vector& parameters, Us { ServerInstance->SNO->WriteGlobalSno('a', "RESTART command from %s, restarting server.", user->GetFullRealHost().c_str()); - ServerInstance->SendError("Server restarting."); + DieRestart::SendError("Server restarting."); #ifndef _WIN32 /* XXX: This hack sets FD_CLOEXEC on all possible file descriptors, so they're closed if the execv() below succeeds. diff --git a/src/coremods/core_oper/core_oper.h b/src/coremods/core_oper/core_oper.h index 3b3dfd4b2..338a369f5 100644 --- a/src/coremods/core_oper/core_oper.h +++ b/src/coremods/core_oper/core_oper.h @@ -30,6 +30,11 @@ namespace DieRestart * @return True if the given password was correct, false if it was not */ bool CheckPass(User* user, const std::string& inputpass, const char* confkey); + + /** Send an ERROR to unregistered users and a NOTICE to all registered local users + * @param message Message to send + */ + void SendError(const std::string& message); } /** Handle /DIE. -- cgit v1.2.3