Skip to content

Load with the new configuration - #171

Closed
PkllonG wants to merge 3 commits into
azerothcore:masterfrom
PkllonG:master
Closed

Load with the new configuration#171
PkllonG wants to merge 3 commits into
azerothcore:masterfrom
PkllonG:master

Conversation

@PkllonG

@PkllonG PkllonG commented Jun 23, 2026

Copy link
Copy Markdown

azerothcore/azerothcore-wotlk#21647

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor

    • Reworked battleground configuration loading to use a cached configuration layer for reliable access to feature flags and thresholds.
    • Added support for parsing and applying WG skip-class lists from the configured comma-separated values.
    • Updated configuration loading to accept an optional reload parameter.
  • Behavioral Updates

    • Config reload behavior is now respected during post-configuration load handling.
    • Balance/team setting values are now read from the cached source (including updated balance level range outputs).

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CFBG::LoadConfig transitions from direct sConfigMgr reads into stored member fields to a cache-backed model using ConfigValueCache. A CFBGOutConfig enum and CFBGOutConfigData class are introduced; all public CFBG accessors are rewired to read from the cache; stored config members are consolidated into _OutConfigData; a LoadWGSkipClasses helper parses the skip-classes string; and the reload signal is propagated through CFBG_World::OnAfterConfigLoad.

Changes

CFBG Config-Cache Refactor

Layer / File(s) Summary
CFBGOutConfig enum, CFBGOutConfigData class, and member field changes
src/CFBG.h
Adds Config.h and ConfigValueCache.h includes, declares the CFBGOutConfig enum with all config keys and CFBGOutConfigData (derived from ConfigValueCache<CFBGOutConfig>) with a BuildConfigCache hook, and replaces prior per-field stored members with a single _OutConfigData field plus _wgSkipClasses.
LoadConfig, BuildConfigCache, LoadWGSkipClasses, and accessor rewrites
src/CFBG.h, src/CFBG.cpp
Rewrites all public CFBG config accessors to read from _OutConfigData.GetConfigValue<...>(CFBGOutConfig::...) instead of member fields, updates LoadConfig signature to LoadConfig(bool reload) and delegates to _OutConfigData.Initialize, adds LoadWGSkipClasses declaration and set-based IsWGSkipClass, and implements LoadWGSkipClasses (comma-token parser) and CFBGOutConfigData::BuildConfigCache (registers all config entries via SetConfigValue with early-return guard when disabled).
Config reload parameter propagation
src/CFBG_SC.cpp
CFBG_World::OnAfterConfigLoad now forwards the Reload parameter to sCFBG->LoadConfig(Reload) instead of calling with no arguments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • azerothcore/mod-cfbg#169: Both PRs implement the Wintergrasp class-skip feature by parsing CFBG.Battlefield.SkipClasses into _wgSkipClasses and using it via IsWGSkipClass to bypass cross-faction/morph logic.
  • azerothcore/mod-cfbg#170: Both PRs touch the CFBG skip-classes parsing/tokenization in src/CFBG.cpp (main PR moves it into LoadWGSkipClasses/config caching while retrieved PR tweaks how CFBG.Battlefield.SkipClasses is tokenized into _wgSkipClasses).

Poem

🐇 Hoppity-hop through the config cache lane,
No more raw fields scattered like rain!
Each value now cached with a neat little key,
BuildConfigCache runs so tidy and free.
The rabbit approves — clean config is the way! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using non-descriptive phrasing that doesn't clearly convey the main changes being made to the codebase. Revise the title to be more specific about the actual changes, such as 'Refactor CFBG configuration to use cached config-data model' or 'Add LoadConfig reload parameter and config-cache architecture'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/CFBG.cpp`:
- Around line 109-119: The early return check on line 109 prevents the
LoadWGSkipClasses call on line 118 from executing when the system is disabled,
causing the _wgSkipClasses cache to retain stale values during a reload
transition from enabled to disabled. To fix this, ensure the skip-class cache is
cleared even when the system is disabled by either calling
sCFBG->LoadWGSkipClasses before the early return statement, or by adding a cache
clearing call in the early return path to reset _wgSkipClasses when the system
is disabled.

In `@src/CFBG.h`:
- Line 153: The LoadConfig() method signature in CFBG.h has been updated to
require a bool reload parameter, but the call to LoadConfig() in src/CFBG_SC.cpp
at line 406 (likely within the OnAfterConfigLoad function) was not updated and
still uses the old zero-argument syntax. Update this LoadConfig() call to pass
the bool reload parameter, using the Reload parameter available in the
OnAfterConfigLoad context.
- Around line 155-172: In all the getter methods between IsEnableSystem() and
RandomizeRaces() (18 methods total), replace the enum name
CrossFactionBGOutConfig with CFBGOutConfig. The _OutConfigData member is typed
as ConfigValueCache<CFBGOutConfig>, so all GetConfigValue template calls must
reference the correct enum CFBGOutConfig instead of the undefined
CrossFactionBGOutConfig. Update each inline method to use CFBGOutConfig:: as the
prefix for the configuration keys.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f5ba9957-15eb-44d0-b63c-49f9c6959837

📥 Commits

Reviewing files that changed from the base of the PR and between 902f3af and fce3ab6.

📒 Files selected for processing (2)
  • src/CFBG.cpp
  • src/CFBG.h

Comment thread src/CFBG.cpp
Comment thread src/CFBG.h
Comment thread src/CFBG.h Outdated
@PkllonG

PkllonG commented Jun 23, 2026

Copy link
Copy Markdown
Author

@coderabbitai

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

@PkllonG It looks like you tagged me without a specific request — I'll go ahead and review the changes in this PR!

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@PkllonG

PkllonG commented Jun 23, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@PkllonG PkllonG changed the title Add files via upload Load with the new configuration Jun 23, 2026
Comment thread src/CFBG.cpp
{
SetConfigValue<bool>(CFBGOutConfig::_IsEnableSystem, "CFBG.Enable", false);
if (!sCFBG->IsEnableSystem())
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this early return could crash the worldserver at startup when CFBG.Enable = 0:

because Initialize() calls VerifyAllConfigsLoaded() after BuildConfigCache() and it asserts on any config slot that was never set.

Running with the module compiled but disabled is a normal setup, so we should load all values unconditionally and keep the enable check at the call sites, like WorldConfig::BuildConfigCache does in the core.

Comment thread src/CFBG.cpp
_balanceClassMaxLevel = sConfigMgr->GetOption<uint8>("CFBG.BalancedTeams.Class.MaxLevel", 19);
_balanceClassLevelDiff = sConfigMgr->GetOption<uint8>("CFBG.BalancedTeams.Class.LevelDiff", 2);
_randomizeRaces = sConfigMgr->GetOption<bool>("CFBG.RandomRaceSelection", true);
SetConfigValue<bool>(CFBGOutConfig::_IsEnableWGSystem, "CFBG.Battlefield.Enable", false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old default for CFBG.Battlefield.Enable was true, with false here anyone without the key in their conf silently loses the Wintergrasp integration

Comment thread src/CFBG.cpp
sCFBG->LoadWGSkipClasses(sCFBG->IsEnableWGSkipClasses());

SetConfigValue<bool>(CFBGOutConfig::_IsEnableBalancedTeams, "CFBG.BalancedTeams", false);
SetConfigValue<bool>(CFBGOutConfig::_IsEnableBalanceClassLowLevel, "CFBG.BalancedTeams.Class.LowLevel", false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, the old default for CFBG.BalancedTeams.Class.LowLevel was true.

Comment thread src/CFBG.cpp
SetConfigValue<bool>(CFBGOutConfig::_IsEnableWGReapplyOnResurrect, "CFBG.Battlefield.ReapplyOnResurrect.Enable", true);

SetConfigValue<std::string>(CFBGOutConfig::_IsEnableWGSkipClasses, "CFBG.Battlefield.SkipClasses", "");
sCFBG->LoadWGSkipClasses(sCFBG->IsEnableWGSkipClasses());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this getter returns the skip class list rather than a flag, maybe GetWGSkipClasses would read better than IsEnableWGSkipClasses

@PkllonG PkllonG closed this Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants