From bc6b943603dfe2a5f4ac9b2ba1d149eabe545e94 Mon Sep 17 00:00:00 2001 From: Karrz1 <127596890+Karrz1@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:30:09 +0000 Subject: [PATCH] Bots: one .reload config reloads the bot settings, conf.d wins `.playerbot reload` re-added playerbot.conf on top of the merged config. Any key in playerbot.conf then beat the same key in worldserver.conf.d (test runs set Playerbot.World.SoakAnchors, PlayerbotV2.SnapshotBuildSplitMap and the like there), so a test setting could vanish on reload. And `.reload config` alone did not refresh the module's cached settings, so a run needed both commands. - playerbot.conf is loaded as a base file: worldserver.conf.d overrides it, at startup and after every reload. - `.playerbot reload` reads every config file again in that order and takes the values; `.reload config` now also refreshes the module's settings (OnConfigLoad), so it is enough on its own. - after every load and reload the log, and the `.playerbot reload` reply, show the effective ParallelSnapshotBuild, SnapshotBuildSplitMap, World.Enable and World.SoakAnchors. Changes for a realm that has the same key in playerbot.conf and in worldserver.conf.d with different values: the conf.d value now wins. --- .../PlayerbotV2/Commands/cs_playerbot_v2.cpp | 4 +- .../PlayerbotV2/PlayerbotV2Scripts.cpp | 11 +++++ src/modules/PlayerbotV2/Util/ConfigReader.cpp | 40 ++++++++++++++++--- src/modules/PlayerbotV2/Util/ConfigReader.h | 5 +++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp b/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp index 45e895a5c0..ee887ce248 100644 --- a/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp +++ b/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp @@ -3005,13 +3005,15 @@ public: handler->SendSysMessage("PlayerbotV2 not initialized."); return false; } - // ConfigReader::reload re-reads playerbot.conf via sConfigMgr. HR-yes + // ConfigReader::reload re-reads every config file via sConfigMgr + // (worldserver.conf, playerbot.conf, worldserver.conf.d). HR-yes // keys take effect immediately on next read; HR-no keys are cached // by the subsystems that consumed them at init and won't update // until a worldserver restart. See playerbot.conf.dist for the per- // key HR tag. const bool ok = Playerbot::Services::Config().reload(); handler->PSendSysMessage("playerbot.conf reload: %s", ok ? "ok" : "failed (see server log)"); + handler->PSendSysMessage("%s", Playerbot::Services::Config().effective_summary().c_str()); return true; } diff --git a/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp b/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp index 184baaf9e5..dc9e7904d2 100644 --- a/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp +++ b/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp @@ -21,6 +21,8 @@ #include "Player.h" #include "PlayerbotMovement.h" #include "ScriptMgr.h" +#include "Services.h" +#include "Util/ConfigReader.h" // Services::Config().refresh() on `.reload config` #include "SharedDefines.h" #include "Spell.h" #include "SpellAuras.h" @@ -92,6 +94,15 @@ public: Module::instance().Shutdown(); } + // `.reload config` has just read every config file again (playerbot.conf included): the module takes the new values too, + // so one reload is enough for a bot setting in worldserver.conf.d. + void OnConfigLoad(bool reload) override + { + if (!reload || !Playerbot::Services::Initialized()) + return; + Playerbot::Services::Config().refresh(); + } + // A real player is about to take a place in a running battleground (a bot is leaving for them): no second instance // is opened for this queue meanwhile. bool CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId) override diff --git a/src/modules/PlayerbotV2/Util/ConfigReader.cpp b/src/modules/PlayerbotV2/Util/ConfigReader.cpp index 51a3379af5..55dcb42e2e 100644 --- a/src/modules/PlayerbotV2/Util/ConfigReader.cpp +++ b/src/modules/PlayerbotV2/Util/ConfigReader.cpp @@ -1,7 +1,9 @@ #include "ConfigReader.h" #include "../Bot/ThreatLimits.h" #include "Config.h" +#include "ConfigBaseFile.h" #include "Log.h" +#include "StringFormat.h" #include "StringConvert.h" #include "Util.h" #include @@ -16,12 +18,21 @@ bool ConfigReader::load(std::string const& file_path) std::string err; // TrinityCore's sConfigMgr is a singleton; we layer our keys onto its state. - // If the file doesn't exist, fall through to defaults silently. - if (!file_path_.empty() && !sConfigMgr->LoadAdditionalFile(file_path_, true, err)) + // playerbot.conf goes in as a BASE file: its keys beat worldserver.conf, and + // every worldserver.conf.d file beats it, at startup and after every reload + // (it used to be added after conf.d, so a playerbot.conf key silently beat + // a conf.d override). If the file doesn't exist, fall through to defaults. + if (!file_path_.empty() && !Trinity::Config::LoadBaseFile(file_path_, err)) { TC_LOG_WARN("playerbot.v2", "[PlayerbotV2] playerbot.conf missing or unreadable ({}): {}", file_path_, err); // Defaults are acceptable; not a hard failure. } + refresh(); + return true; +} + +void ConfigReader::refresh() +{ apply_from_loaded_config(); // B-1 observability: playerbot.conf is layered with override=true, so @@ -31,16 +42,35 @@ bool ConfigReader::load(std::string const& file_path) // the precedence once per load/reload so the log answers it. TC_LOG_INFO("playerbot.v2", "[Config] effective population: TotalTarget={} " - "HordePct={} Shape={} MaxHeavyFactor={:.2f} (Playerbot.* keys in '{}' override worldserver.conf)", + "HordePct={} Shape={} MaxHeavyFactor={:.2f} (keys in '{}' override worldserver.conf; worldserver.conf.d overrides both)", pop_target_, pop_horde_pct_, pop_shape_, pop_max_heavy_factor_, file_path_.empty() ? "" : file_path_); - return true; + TC_LOG_INFO("playerbot.v2", "[Config] {}", effective_summary()); +} + +std::string ConfigReader::effective_summary() const +{ + // The keys a test run flips most, read back from the merged config so a + // reload shows at once whether a conf.d change arrived. + return Trinity::StringFormat("effective: ParallelSnapshotBuild={} SnapshotBuildSplitMap={} World.Enable={} World.SoakAnchors=\"{}\"", + parallel_snapshot_build_ ? 1 : 0, snapshot_build_split_map_ ? 1 : 0, + sConfigMgr->GetBoolDefault("Playerbot.World.Enable", false, true) ? 1 : 0, + sConfigMgr->GetStringDefault("Playerbot.World.SoakAnchors", "", true)); } bool ConfigReader::reload() { - return load(file_path_); + // Read every config file again in its normal order (worldserver.conf, + // playerbot.conf, worldserver.conf.d, environment), then take the values. + // Re-adding playerbot.conf on top, as this did before, made its keys beat + // the conf.d overrides until the next restart. + std::vector errors; + bool const ok = sConfigMgr->Reload(errors); + for (std::string const& e : errors) + TC_LOG_ERROR("playerbot.v2", "[Config] reload: {}", e); + refresh(); + return ok; } void ConfigReader::apply_from_loaded_config() diff --git a/src/modules/PlayerbotV2/Util/ConfigReader.h b/src/modules/PlayerbotV2/Util/ConfigReader.h index c3fbc64c8a..83f51b5ddb 100644 --- a/src/modules/PlayerbotV2/Util/ConfigReader.h +++ b/src/modules/PlayerbotV2/Util/ConfigReader.h @@ -20,7 +20,12 @@ class ConfigReader public: // Returns true if config loaded (or default values acceptable for missing keys). bool load(std::string const& file_path); + // .playerbot reload: reads all config files again (sConfigMgr->Reload), then refresh(). bool reload(); + // Takes the values from the config as it is loaded now (after `.reload config`, OnConfigLoad). + void refresh(); + // One line with the effective values of the keys test runs flip (log + .playerbot reload reply). + std::string effective_summary() const; // ----- Accessors (HR-yes unless noted) ---- // Threading