From 8ea5a7ffd29796c120924449a73d9a8db080237e Mon Sep 17 00:00:00 2001 From: agatho Date: Tue, 3 Feb 2026 09:55:35 +0100 Subject: [PATCH] fix(bg): Fix BG queue count using wrong data source (selection pool vs queued groups) ROOT CAUSE: QueueStatePoller was using BattlegroundQueue::GetPlayersInQueue() which returns from m_SelectionPools (populated during matchmaking), not from m_QueuedGroups (the actual queue). This caused the system to always see 0 players in queue even after bots were successfully queued. SYMPTOMS: - Bots logged "Successfully queued for BG" but next poll showed 0/10 in queue - BG queue population kept trying to fill already-filled queues - BGs took forever to start due to count mismatch FIX: - Added GetQueuedPlayersCount(teamId, bracketId) to BattlegroundQueue - This function iterates m_QueuedGroups for the specific bracket and team - Only counts players not already invited to a BG instance - Updated QueueStatePoller to use the new function instead of GetPlayersInQueue() TESTING: Verified bots are queued and count now reflects actual queued players Co-Authored-By: Claude Opus 4.5 Signed-off-by: luis --- .../Lifecycle/Instance/QueueStatePoller.cpp | 8 ++++-- .../game/Battlegrounds/BattlegroundQueue.cpp | 28 +++++++++++++++++++ .../game/Battlegrounds/BattlegroundQueue.h | 3 ++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/modules/Playerbot/Lifecycle/Instance/QueueStatePoller.cpp b/src/modules/Playerbot/Lifecycle/Instance/QueueStatePoller.cpp index dda8bf774..43293d40c 100644 --- a/src/modules/Playerbot/Lifecycle/Instance/QueueStatePoller.cpp +++ b/src/modules/Playerbot/Lifecycle/Instance/QueueStatePoller.cpp @@ -438,9 +438,11 @@ void QueueStatePoller::DoPollBGQueue(BattlegroundTypeId bgTypeId, BattlegroundBr BattlegroundQueue& queue = sBattlegroundMgr->GetBattlegroundQueue(queueTypeId); - // Read queue counts (READ-ONLY API) - uint32 allianceCount = queue.GetPlayersInQueue(TEAM_ALLIANCE); - uint32 hordeCount = queue.GetPlayersInQueue(TEAM_HORDE); + // Read queue counts using the correct function that counts from m_QueuedGroups + // CRITICAL FIX: GetPlayersInQueue() returns from selection pool (matchmaking only) + // GetQueuedPlayersCount() returns actual queued players for the specific bracket + uint32 allianceCount = queue.GetQueuedPlayersCount(TEAM_ALLIANCE, bracket); + uint32 hordeCount = queue.GetQueuedPlayersCount(TEAM_HORDE, bracket); // Get requirements from template (READ-ONLY) BattlegroundTemplate const* bgTemplate = sBattlegroundMgr->GetBattlegroundTemplateByTypeId(bgTypeId); diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.cpp b/src/server/game/Battlegrounds/BattlegroundQueue.cpp index 1cf44b7a6..53a0129db 100644 --- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp +++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp @@ -422,6 +422,34 @@ uint32 BattlegroundQueue::GetPlayersInQueue(TeamId id) return m_SelectionPools[id].GetPlayerCount(); } +uint32 BattlegroundQueue::GetQueuedPlayersCount(TeamId teamId, BattlegroundBracketId bracketId) const +{ + // Count players from the actual queue, not the selection pool + // Selection pool is only populated during matchmaking + uint32 count = 0; + + // Determine which queue type to check based on team + uint32 queueType = (teamId == TEAM_ALLIANCE) ? BG_QUEUE_NORMAL_ALLIANCE : BG_QUEUE_NORMAL_HORDE; + + // Count players in normal queue for this bracket + for (GroupQueueInfo const* ginfo : m_QueuedGroups[bracketId][queueType]) + { + // Only count players not already invited to a BG + if (!ginfo->IsInvitedToBGInstanceGUID) + count += static_cast(ginfo->Players.size()); + } + + // Also check premade queue for this team + queueType = (teamId == TEAM_ALLIANCE) ? BG_QUEUE_PREMADE_ALLIANCE : BG_QUEUE_PREMADE_HORDE; + for (GroupQueueInfo const* ginfo : m_QueuedGroups[bracketId][queueType]) + { + if (!ginfo->IsInvitedToBGInstanceGUID) + count += static_cast(ginfo->Players.size()); + } + + return count; +} + bool BattlegroundQueue::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, Team side) { // set side if needed diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.h b/src/server/game/Battlegrounds/BattlegroundQueue.h index 65c4c9d57..e542e4edc 100644 --- a/src/server/game/Battlegrounds/BattlegroundQueue.h +++ b/src/server/game/Battlegrounds/BattlegroundQueue.h @@ -121,6 +121,9 @@ class TC_GAME_API BattlegroundQueue SelectionPool m_SelectionPools[PVP_TEAMS_COUNT]; uint32 GetPlayersInQueue(TeamId id); + // Count all queued players for a specific team and bracket (not just selection pool) + uint32 GetQueuedPlayersCount(TeamId teamId, BattlegroundBracketId bracketId) const; + BattlegroundQueueTypeId GetQueueId() const { return m_queueId; } private: