From 58b67038b16cce3751ff3678eaf233dbea6c0861 Mon Sep 17 00:00:00 2001 From: NoxMax <50133316+NoxMax@users.noreply.github.com> Date: Fri, 12 Jun 2026 14:06:41 -0600 Subject: [PATCH] Fix: Prevent user error when using lower than needed value for RandomBotAccountCount (#2438) ## Pull Request Description The required number of accounts is now always calculated on server start. The manual value of RandomBotAccountCount is only used when it's >= the calculated value. This prevents user error of using lower than needed value, during initial account creation or after. Moved `AddClassAccountPoolSize` and `RandomBotAccountPrefix` up. They belong with the other account creation configs. Minor comment edits in `CalculateAvailableCharsPerAccount`; no code change there. ## Feature Evaluation - Describe the **minimum logic** required to achieve the intended behavior. - Describe the **processing cost** when this logic executes across many bots. Logic is at minimum to prevent this user error. Required number of accounts is now always calculated, but the calculation only happens on server start. ## How to Test the Changes - Make sure to have a snapshot of your server as this testing involves account deletions, so that it's easier to revert things. - The functional change is only in RandomPlayerbotFactory.cpp, so you can quickly copy/paste the whole of `CalculateTotalAccountCount` to run this test 1. First delete your accounts `DeleteRandomBotAccounts = 1` 2. Then reboot with ``` AiPlayerbot.MaxRandomBots = 500 RandomBotAccountCount = 0 DeleteRandomBotAccounts = 0 AddClassAccountPoolSize = 10 ``` server should create the correct number of accounts needed: (500/10) +10 = 60 3. Reboot with a `RandomBotAccountCount` value equal to 100, server should create for you 50 new accounts, for a total of 110. 4. Delete your accounts again. 5. Reboot with a `RandomBotAccountCount = 30` (which is 20 less than required), server should give you a terminal warning and proceed to create 50+10 accounts. The 500 randombots should login and behave normally. ## Impact Assessment - Does this change increase per-bot/per-tick processing or risk scaling poorly with thousands of bots? - - [ ] No, not at all - - [x] Minimal impact (**explain below**) - - [ ] Moderate impact (**explain below**) Account calculations will always be done on boot. No effect on the rest of the runtime. - Does this change modify default bot behavior? - - [x] No - - [ ] Yes (**explain why**) - Does this change add new decision branches or increase maintenance complexity? - - [x] No - - [ ] Yes (**explain below**) ## AI Assistance Was AI assistance used while working on this change? - - [x] No - - [ ] Yes (**explain below**) ## Final Checklist - - [x] Stability is not compromised. - - [x] Performance impact is understood, tested, and acceptable. - - [x] Added logic complexity is justified and explained. - - [x] Any new bot dialogue lines are translated. - - [x] Documentation updated if needed (Conf comments, WiKi commands). ## Notes for Reviewers --- conf/playerbots.conf.dist | 20 +++++++++------ src/Bot/Factory/RandomPlayerbotFactory.cpp | 29 +++++++++++----------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index d673cd53e..69c84b4f2 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -89,11 +89,21 @@ AiPlayerbot.MinRandomBots = 500 AiPlayerbot.MaxRandomBots = 500 # Randombot accounts -# If you are not using any expansion at all, you may have to set this manually, in which case please -# ensure that RandomBotAccountCount is at least greater than (MaxRandomBots / 10 + AddClassAccountPoolSize) +# Set to 0 to automatically calculate needed accounts based on MaxRandomBots, EnablePeriodicOnlineOffline +# and its ratio, and AddClassAccountPoolSize. Set manually if you want to create more accounts than needed. +# If the manual value is less than the required, the system will override it with the required value. # Default: 0 (automatic) AiPlayerbot.RandomBotAccountCount = 0 +# Addclass accounts +# Number of accounts created for bots reserved for the addclass command. As with randombots, each account has +# 10 bots (or 9 if WotLK is disabled), one bot for each class. +AiPlayerbot.AddClassAccountPoolSize = 50 + +# Prefix for created bot accounts (of any type). +# Do not change this prefix while there are existing bot accounts. +AiPlayerbot.RandomBotAccountPrefix = "rndbot" + # Delete all randombot accounts # To apply this, set the number to 1 and run the Worldserver. Once deletion is complete, if you would # like to recreate randombots, set the number back to 0 and rerun the Worldserver. @@ -128,9 +138,6 @@ AiPlayerbot.MaxAddedBots = 40 # Default: 1 (enabled) AiPlayerbot.AddClassCommand = 1 -# Set the addclass command account pool size -AiPlayerbot.AddClassAccountPoolSize = 50 - # Bot group invitation permission level (0 = GM only, 1 = accept based on level, 2 = always accept) # Default: 1 (accept based on level) AiPlayerbot.GroupInvitationPermission = 1 @@ -680,9 +687,6 @@ AiPlayerbot.EndFishingWithMaster = 30.0 # Enable/Disable randomly generated password for randombot accounts AiPlayerbot.RandomBotRandomPassword = 0 -# Prefix for account names to create for randombots -AiPlayerbot.RandomBotAccountPrefix = "rndbot" - # Minimum and maximum levels for randombots AiPlayerbot.RandomBotMinLevel = 1 AiPlayerbot.RandomBotMaxLevel = 80 diff --git a/src/Bot/Factory/RandomPlayerbotFactory.cpp b/src/Bot/Factory/RandomPlayerbotFactory.cpp index 530715191..6e5005723 100644 --- a/src/Bot/Factory/RandomPlayerbotFactory.cpp +++ b/src/Bot/Factory/RandomPlayerbotFactory.cpp @@ -334,18 +334,12 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount() sPlayerbotAIConfig.addClassAccountPoolSize == 0 ? 2 : -1); if (!res || res->Fetch()[0].Get() == 0) - { break; - } std::this_thread::sleep_for(std::chrono::milliseconds(50)); // Extra 50ms fixed delay for safety. } } - // Checks if randomBotAccountCount is set, otherwise calculate it dynamically. - if (sPlayerbotAIConfig.randomBotAccountCount > 0) - return sPlayerbotAIConfig.randomBotAccountCount; - // Check existing account types uint32 existingRndBotAccounts = 0; uint32 existingAddClassAccounts = 0; @@ -366,16 +360,14 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount() } while (typeCheck->NextRow()); } - // Determine divisor based on Death Knight login eligibility and requested A&H faction ratio + // Determine divisor based on Death Knight availability and requested A&H faction ratio int divisor = CalculateAvailableCharsPerAccount(); // Calculate max bots int maxBots = sPlayerbotAIConfig.maxRandomBots; - // Take periodic online - offline into account + // Take periodic online/offline into account if (sPlayerbotAIConfig.enablePeriodicOnlineOffline) - { maxBots *= sPlayerbotAIConfig.periodicOnlineOfflineRatio; - } // Calculate number of accounts needed for RNDbots // Result is rounded up for maxBots not cleanly divisible by the divisor @@ -416,11 +408,22 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount() } // Return existing total plus any additional accounts needed - return existingTotal + additionalAccountsNeeded; + uint32 calculatedTotal = existingTotal + additionalAccountsNeeded; + + // Manually set randomBotAccountCount meets the requirements + if (sPlayerbotAIConfig.randomBotAccountCount >= calculatedTotal) + return sPlayerbotAIConfig.randomBotAccountCount; + // Manually set randomBotAccountCount doesn't meet the requirements. Using calculated value + if (sPlayerbotAIConfig.randomBotAccountCount > 0) + LOG_WARN("playerbots", "RandomBotAccountCount ({}) is lower than the required calculated value ({}). Using the calculated value instead.", + sPlayerbotAIConfig.randomBotAccountCount, calculatedTotal); + + return calculatedTotal; } uint32 RandomPlayerbotFactory::CalculateAvailableCharsPerAccount() { + // Death Knight availability according to their login eligibility, and if WotLK is enabled at all. bool noDK = sPlayerbotAIConfig.disableDeathKnightLogin || sWorld->getIntConfig(CONFIG_EXPANSION) != EXPANSION_WRATH_OF_THE_LICH_KING; uint32 availableChars = noDK ? 9 : 10; @@ -434,11 +437,9 @@ uint32 RandomPlayerbotFactory::CalculateAvailableCharsPerAccount() float unavailableRatio = static_cast((std::max(hordeRatio, allianceRatio) - std::min(hordeRatio, allianceRatio))) / (std::max(hordeRatio, allianceRatio) * 2); + // Conservative floor to ensure enough characters (may result in more accounts than needed). if (unavailableRatio != 0) - { - // conservative floor to ensure enough chars (may result in more accounts than needed) availableChars = availableChars - availableChars * unavailableRatio; - } return availableChars; }