diff options
| author | 2026-02-27 01:24:57 +0000 | |
|---|---|---|
| committer | 2026-02-27 01:45:40 +0000 | |
| commit | ff18ee420e229a34b874a1a03ae302fdf60fe149 (patch) | |
| tree | 8cabc848ea796dc03fd2e616588f1a451aad2106 /src/commands.cpp | |
| parent | Merge branch 'insp4' into master. (diff) | |
Implement support for per-command maximum targets.
Closes #2157.
Diffstat (limited to 'src/commands.cpp')
| -rw-r--r-- | src/commands.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
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<size_t>(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."); |
