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.
This commit is contained in:
Karrz1
2026-11-15 21:26:39 +00:00
parent c425a1912e
commit bc6b943603
4 changed files with 54 additions and 6 deletions
@@ -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;
}
@@ -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
+35 -5
View File
@@ -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 <algorithm>
@@ -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() ? "<none>" : 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<std::string> 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()
@@ -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