From 9155b99389542c42cf706bca2acab7c4bfb56aa9 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 13 Sep 2022 14:26:25 +0100 Subject: Rework the snotices sent when a rehash loads/unloads a module. - Fix sending a duplicate load/unload message when rehashed from the terminal. - Avoid formatting the log message twice. --- src/configreader.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/configreader.cpp') diff --git a/src/configreader.cpp b/src/configreader.cpp index efe3af94d..1c8a181ca 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -512,21 +512,22 @@ void ServerConfig::ApplyModules(User* user) // Don't remove core_*, just remove m_* if (InspIRCd::Match(modname, "core_*", ascii_case_insensitive_map)) continue; + if (ServerInstance->Modules.Unload(mod)) { - ServerInstance->SNO.WriteGlobalSno('r', "*** REHASH UNLOADED MODULE: %s", modname.c_str()); - + const std::string message = InspIRCd::Format("The %s module was unloaded.", modname.c_str()); if (user) - user->WriteNumeric(RPL_UNLOADEDMODULE, modname, InspIRCd::Format("The %s module was unloaded.", modname.c_str())); - else - ServerInstance->SNO.WriteGlobalSno('r', "The %s module was unloaded.", modname.c_str()); + user->WriteNumeric(RPL_UNLOADEDMODULE, modname, message); + + ServerInstance->SNO.WriteGlobalSno('r', message); } else { + const std::string message = InspIRCd::Format("Failed to unload the %s module: %s", modname.c_str(), ServerInstance->Modules.LastError().c_str()); if (user) - user->WriteNumeric(ERR_CANTUNLOADMODULE, modname, InspIRCd::Format("Failed to unload the %s module: %s", modname.c_str(), ServerInstance->Modules.LastError().c_str())); - else - ServerInstance->SNO.WriteGlobalSno('r', "Failed to unload the %s module: %s", modname.c_str(), ServerInstance->Modules.LastError().c_str()); + user->WriteNumeric(ERR_CANTUNLOADMODULE, modname, message); + + ServerInstance->SNO.WriteGlobalSno('r', message); } } @@ -538,18 +539,19 @@ void ServerConfig::ApplyModules(User* user) if (ServerInstance->Modules.Load(modname)) { - ServerInstance->SNO.WriteGlobalSno('r', "*** REHASH LOADED MODULE: %s", modname.c_str()); + const std::string message = InspIRCd::Format("The %s module was loaded.", modname.c_str()); if (user) - user->WriteNumeric(RPL_LOADEDMODULE, modname, InspIRCd::Format("The %s module was loaded.", modname.c_str())); - else - ServerInstance->SNO.WriteGlobalSno('r', "The %s module was loaded.", modname.c_str()); + user->WriteNumeric(RPL_LOADEDMODULE, modname, message); + + ServerInstance->SNO.WriteGlobalSno('r', message); } else { + const std::string message = InspIRCd::Format("Failed to load the %s module: %s", modname.c_str(), ServerInstance->Modules.LastError().c_str()); if (user) - user->WriteNumeric(ERR_CANTLOADMODULE, modname, InspIRCd::Format("Failed to load the %s module: %s", modname.c_str(), ServerInstance->Modules.LastError().c_str())); - else - ServerInstance->SNO.WriteGlobalSno('r', "Failed to load the %s module: %s", modname.c_str(), ServerInstance->Modules.LastError().c_str()); + user->WriteNumeric(ERR_CANTLOADMODULE, modname, message); + + ServerInstance->SNO.WriteGlobalSno('r', message); } } } -- cgit v1.3.1-10-gc9f91