From 39bb5825adbea6d76c2a8c40a8065ef4a3c2d6f6 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 22 Mar 2025 08:33:21 +0000 Subject: [PATCH] Deduplicate requirename code in os_shutdown. --- modules/operserv/os_shutdown.cpp | 41 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/modules/operserv/os_shutdown.cpp b/modules/operserv/os_shutdown.cpp index 5ca4898b2..96002439b 100644 --- a/modules/operserv/os_shutdown.cpp +++ b/modules/operserv/os_shutdown.cpp @@ -11,7 +11,22 @@ #include "module.h" -#define WRONG_NETWORK _("The network name you specified is incorrect. Did you mean to run %s on a different network?") +namespace +{ + bool NetworkNameGiven(Command *cmd, CommandSource &source, const std::vector ¶ms) + { + if (!Config->GetModule(cmd->owner).Get("requirename")) + return true; // Not necesary. + + if (params.empty()) + cmd->OnSyntaxError(source, source.command); + else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get("networkname"))) + source.Reply(_("The network name you specified is incorrect. Did you mean to run %s on a different network?"), source.command.c_str()); + else + return true; // Name was specified correctly + return false; // Network name was wrong or not specified. + } +} class CommandOSQuit final : public Command @@ -26,14 +41,8 @@ public: void Execute(CommandSource &source, const std::vector ¶ms) override { - if (Config->GetModule(this->owner).Get("requirename")) - { - if (params.empty()) - OnSyntaxError(source, source.command); - else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get("networkname"))) - source.Reply(WRONG_NETWORK, source.command.c_str()); + if (!NetworkNameGiven(this, source, params)) return; - } Log(LOG_ADMIN, source, this); Anope::QuitReason = source.command + " command received from " + source.GetNick(); @@ -66,14 +75,8 @@ public: void Execute(CommandSource &source, const std::vector ¶ms) override { - if (Config->GetModule(this->owner).Get("requirename")) - { - if (params.empty()) - OnSyntaxError(source, source.command); - else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get("networkname"))) - source.Reply(WRONG_NETWORK, source.command.c_str()); + if (!NetworkNameGiven(this, source, params)) return; - } Log(LOG_ADMIN, source, this); Anope::QuitReason = source.command + " command received from " + source.GetNick(); @@ -104,14 +107,8 @@ public: void Execute(CommandSource &source, const std::vector ¶ms) override { - if (Config->GetModule(this->owner).Get("requirename")) - { - if (params.empty()) - OnSyntaxError(source, source.command); - else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get("networkname"))) - source.Reply(WRONG_NETWORK, source.command.c_str()); + if (!NetworkNameGiven(this, source, params)) return; - } Log(LOG_ADMIN, source, this); Anope::QuitReason = source.command + " command received from " + source.GetNick();