refactor(WG): read core PlayersInWar instead of parallel bucket#154
Merged
Nyeriah merged 1 commit intoMay 30, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_wgWarPlayersbucket inCFBG_Battlefield. WG balance and end-of-war fake cleanup now read core'sBattlefield::GetPlayersInWarSet(team)directly.OnBattlefieldPlayerLeaveWarandOnBattlefieldPlayerLeaveZonesubscriptions — they existed only to drain the parallel bucket.Why
The bucket mirrored
Battlefield::PlayersInWarbut had its own lifecycle, which opened a real divergence race:OnBattlefieldPlayerJoinWarfires before core'sPlayersInWar.insert, and if the subsequentAddOrSetPlayerToCorrectBfGroupcall rejected the join, the module had already inserted into_wgWarPlayers(and morphed the player) while core had not. ReadingGetPlayersInWarSetdirectly 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:
OnBattlefieldPlayerJoinWarfires beforePlayersInWar.insert, so the newGetPlayersInWarSetreads give the same pre-candidate snapshot the bucket used to.OnBattlefieldWarEndfires beforeOnBattleEndclearsPlayersInWar(paired core change), so the war set is still iterable for fake cleanup.This PR requires the paired AzerothCore PR azerothcore/azerothcore-wotlk#26030, which reorders
sScriptMgr->OnBattlefieldWarEnd(...)to fire beforeOnBattleEnd(...)inBattlefield::EndBattle. Without it, the newOnBattlefieldWarEndbody reads an emptyPlayersInWarand fake players never get cleaned up at war end.Do not merge this until azerothcore/azerothcore-wotlk#26030 is merged.
Test plan
OnBattlefieldPlayerJoinWarcontinues to flip Alliance/Horde candidates when one side is heavier (verify with.bf listbefore/after a few accepts)..cfbg debug <name>immediately after the war ends and on a player who stays in the zone).OnPlayerLogoutpath, unchanged).OnPlayerUpdateZonepath, unchanged).🤖 Generated with Claude Code