summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-03-22 08:33:21 +0000
committerSadie Powell <sadie@witchery.services>2025-03-22 08:33:21 +0000
commit39bb5825adbea6d76c2a8c40a8065ef4a3c2d6f6 (patch)
tree904d8de0f7957a6d44052b4b1a26866976b43ab2 /modules
parent602ff60e21bdfef37ca2508e2400cc985e200582 (diff)
Deduplicate requirename code in os_shutdown.
Diffstat (limited to 'modules')
-rw-r--r--modules/operserv/os_shutdown.cpp41
1 files 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<Anope::string> &params)
+ {
+ if (!Config->GetModule(cmd->owner).Get<bool>("requirename"))
+ return true; // Not necesary.
+
+ if (params.empty())
+ cmd->OnSyntaxError(source, source.command);
+ else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get<Anope::string>("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<Anope::string> &params) override
{
- if (Config->GetModule(this->owner).Get<bool>("requirename"))
- {
- if (params.empty())
- OnSyntaxError(source, source.command);
- else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get<Anope::string>("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<Anope::string> &params) override
{
- if (Config->GetModule(this->owner).Get<bool>("requirename"))
- {
- if (params.empty())
- OnSyntaxError(source, source.command);
- else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get<Anope::string>("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<Anope::string> &params) override
{
- if (Config->GetModule(this->owner).Get<bool>("requirename"))
- {
- if (params.empty())
- OnSyntaxError(source, source.command);
- else if (!params[0].equals_cs(Config->GetBlock("networkinfo").Get<Anope::string>("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();