Skip to content

refactor(WG): read core PlayersInWar instead of parallel bucket#154

Merged
Nyeriah merged 1 commit into
azerothcore:masterfrom
Nyeriah:refactor/wg-drop-parallel-bucket
May 30, 2026
Merged

refactor(WG): read core PlayersInWar instead of parallel bucket#154
Nyeriah merged 1 commit into
azerothcore:masterfrom
Nyeriah:refactor/wg-drop-parallel-bucket

Conversation

@Nyeriah

@Nyeriah Nyeriah commented May 30, 2026

Copy link
Copy Markdown
Member

Summary

  • Drop the module-owned _wgWarPlayers bucket in CFBG_Battlefield. WG balance and end-of-war fake cleanup now read core's Battlefield::GetPlayersInWarSet(team) directly.
  • Remove OnBattlefieldPlayerLeaveWar and OnBattlefieldPlayerLeaveZone subscriptions — they existed only to drain the parallel bucket.

Why

The bucket mirrored Battlefield::PlayersInWar but had its own lifecycle, which opened a real divergence race: OnBattlefieldPlayerJoinWar fires before core's PlayersInWar.insert, and if the subsequent AddOrSetPlayerToCorrectBfGroup call rejected the join, the module had already inserted into _wgWarPlayers (and morphed the player) while core had not. Reading GetPlayersInWarSet directly eliminates that window — the candidate is genuinely in neither side at hook time, and we only mutate module state if core actually commits the join afterward.

Hook-timing notes preserved in code comments:

  • OnBattlefieldPlayerJoinWar fires before PlayersInWar.insert, so the new GetPlayersInWarSet reads give the same pre-candidate snapshot the bucket used to.
  • OnBattlefieldWarEnd fires before OnBattleEnd clears PlayersInWar (paired core change), so the war set is still iterable for fake cleanup.

⚠️ Paired core dependency

This PR requires the paired AzerothCore PR azerothcore/azerothcore-wotlk#26030, which reorders sScriptMgr->OnBattlefieldWarEnd(...) to fire before OnBattleEnd(...) in Battlefield::EndBattle. Without it, the new OnBattlefieldWarEnd body reads an empty PlayersInWar and fake players never get cleaned up at war end.

Do not merge this until azerothcore/azerothcore-wotlk#26030 is merged.

Test plan

  • Build cleanly against the paired core change.
  • Wintergrasp starts; balance gate at OnBattlefieldPlayerJoinWar continues to flip Alliance/Horde candidates when one side is heavier (verify with .bf list before/after a few accepts).
  • At war end, every faked WG participant has their real race/team/faction restored (check with .cfbg debug <name> immediately after the war ends and on a player who stays in the zone).
  • A player who logs out mid-war and reconnects after war end is restored on relog (existing OnPlayerLogout path, unchanged).
  • A player who walks out of the WG zone during war still has fake cleared at zone change (OnPlayerUpdateZone path, unchanged).

🤖 Generated with Claude Code

The WG balance + cleanup paths used a module-owned _wgWarPlayers set
populated/drained from the BattlefieldScript join/leave-war/leave-zone
hooks. The parallel bucket existed only because OnBattlefieldWarEnd
previously fired after OnBattleEnd had already cleared PlayersInWar,
leaving the module no authoritative source to iterate at war end.

With the BATTLEFIELDHOOK_ON_WAR_END timing change in core
(azerothcore/azerothcore-wotlk, paired PR), the hook now fires while
PlayersInWar is still populated. That lets the module:

- read bf->GetPlayersInWarSet(team).size() in OnBattlefieldPlayerJoinWar
  for balance decisions -- identical pre-candidate snapshot as the bucket
  provided, but eliminates the AddOrSetPlayerToCorrectBfGroup divergence
  race where module state was mutated for a join core then rejected,
- iterate bf->GetPlayersInWarSet(team) at war end to restore fakes,
- drop OnBattlefieldPlayerLeaveWar and OnBattlefieldPlayerLeaveZone
  subscriptions entirely -- they only existed to drain the bucket.

NOTE: requires the paired core PR. Module will not function correctly
against upstream master until that lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Nyeriah Nyeriah merged commit 4a2d396 into azerothcore:master May 30, 2026
1 check passed
@Nyeriah Nyeriah deleted the refactor/wg-drop-parallel-bucket branch May 30, 2026 22:42
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.

1 participant