From ff18ee420e229a34b874a1a03ae302fdf60fe149 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 27 Feb 2026 01:24:57 +0000 Subject: Implement support for per-command maximum targets. Closes #2157. --- src/commands.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/commands.cpp') diff --git a/src/commands.cpp b/src/commands.cpp index 43e8e7360..8d195e761 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -29,6 +29,12 @@ bool CommandParser::LoopCall(User* user, Command* handler, const CommandBase::Params& parameters, unsigned int splithere, int extra, bool usemax) { + if (!handler->accepts_multiple_targets) + { + ServerInstance->Logs.Debug("COMMAND", "BUG: {} called CommandParser::LoopCall with !accepts_multiple_targets", handler->name); + return false; + } + if (splithere >= parameters.size()) return false; @@ -63,7 +69,7 @@ bool CommandParser::LoopCall(User* user, Command* handler, const CommandBase::Pa * left to parse. */ CommandBase::Params splitparams(parameters); - while (items1.GetToken(item) && (!usemax || max++ < ServerInstance->Config->MaxTargets)) + while (items1.GetToken(item) && (!usemax || max++ < handler->GetMaxTargets())) { if ((!check_dupes) || (dupes.insert(item).second)) { @@ -431,6 +437,20 @@ void Command::RegisterService() throw ModuleException(creator, "Command already exists: " + name); } +size_t Command::GetMaxTargets() +{ + if (!this->accepts_multiple_targets) + return 0; + + if (!this->max_targets || this->max_targets_checked != ServerInstance->Config->ReadTime) + { + const auto& tag = ServerInstance->Config->ConfValue("maxtargets"); + this->max_targets = tag->getNum(this->name, tag->getNum("default", 5, 1), 1); + this->max_targets_checked = ServerInstance->Config->ReadTime; + } + return this->max_targets; +} + void Command::TellNotEnoughParameters(LocalUser* user, const Params& parameters) { user->WriteNumeric(ERR_NEEDMOREPARAMS, name, "Not enough parameters."); -- cgit v1.3.1-10-gc9f91