diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-05-17 18:13:45 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-05-17 18:13:45 +0200 |
commit | 33137bba446212f89f7b94f50ace20db19b6d009 (patch) | |
tree | 525dcd06178f675011ad49a2f68da5a48c9a4d8c | |
parent | c715182bf86532d767c939a344bd4f304d25df09 (diff) |
Move InspIRCd::SendError() to cmd_die
Fix multiple ERROR messages being sent to unregistered users by removing the "Exiting with status..." message
-rw-r--r-- | include/inspircd.h | 5 | ||||
-rw-r--r-- | src/coremods/core_oper/cmd_die.cpp | 21 | ||||
-rw-r--r-- | src/coremods/core_oper/cmd_restart.cpp | 2 | ||||
-rw-r--r-- | src/coremods/core_oper/core_oper.h | 5 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 19 | ||||
-rw-r--r-- | src/server.cpp | 1 |
6 files changed, 26 insertions, 27 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index b90c0c797..d41d2919b 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -502,11 +502,6 @@ class CoreExport InspIRCd static const char* Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2); static const char* Format(va_list &vaList, const char* formatString) CUSTOM_PRINTF(2, 0); - /** Send an error notice to all local users, opered and unopered - * @param s The error string to send - */ - void SendError(const std::string &s); - /** Return true if a nickname is valid * @param n A nickname to verify * @return True if the nick is valid 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<std::string>& parameters, User *user) @@ -46,7 +65,7 @@ CmdResult CommandDie::Handle (const std::vector<std::string>& 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<std::string>& 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. diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 5cde46246..d636e2d89 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -79,25 +79,6 @@ Channel* InspIRCd::FindChan(const std::string &chan) return iter->second; } -/* Send an error notice to all users, registered or not */ -void InspIRCd::SendError(const std::string &s) -{ - const UserManager::LocalList& list = Users.GetLocalUsers(); - for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i) - { - User* u = *i; - if (u->registered == REG_ALL) - { - u->WriteNotice(s); - } - else - { - /* Unregistered connections receive ERROR, not a NOTICE */ - u->Write("ERROR :" + s); - } - } -} - bool InspIRCd::IsValidMask(const std::string &mask) { const char* dest = mask.c_str(); diff --git a/src/server.cpp b/src/server.cpp index 42dce1372..191a3d30f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -46,7 +46,6 @@ void InspIRCd::Exit(int status) #ifdef _WIN32 SetServiceStopped(status); #endif - this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")"); this->Cleanup(); ServerInstance = NULL; delete this; |