diff --git a/src/game/BattleGround/BattleGroundMgr.cpp b/src/game/BattleGround/BattleGroundMgr.cpp index 1ea31f484a..132a6c63e3 100644 --- a/src/game/BattleGround/BattleGroundMgr.cpp +++ b/src/game/BattleGround/BattleGroundMgr.cpp @@ -1153,32 +1153,6 @@ void BattleGroundMgr::ToggleArenaTesting() sWorld.SendWorldText(LANG_DEBUG_ARENA_OFF); } -/** - Method that schedules queue update - - @param arena rating - @param arena type - @param battleground queue type id - @param battleground type id - @param bracket id -*/ -void BattleGroundMgr::ScheduleQueueUpdate(uint32 arenaRating, ArenaType arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BattleGroundBracketId bracketId) -{ - // we will use only 1 number created of bgTypeId and bracket_id - uint64 schedule_id = (uint64(arenaRating) << 32) | (uint64(arenaType) << 24) | (uint64(bgQueueTypeId) << 16) | (uint64(bgTypeId) << 8) | bracketId; - bool found = false; - for (unsigned long long i : m_queueUpdateScheduler) - { - if (i == schedule_id) - { - found = true; - break; - } - } - if (!found) - m_queueUpdateScheduler.push_back(schedule_id); -} - /** Function that returns max arena rating difference */ diff --git a/src/game/BattleGround/BattleGroundMgr.h b/src/game/BattleGround/BattleGroundMgr.h index f609fb677c..2659fe4280 100644 --- a/src/game/BattleGround/BattleGroundMgr.h +++ b/src/game/BattleGround/BattleGroundMgr.h @@ -77,7 +77,6 @@ class BattleGroundMgr void SendToBattleGround(Player* /*player*/, uint32 /*instanceId*/, BattleGroundTypeId /*bgTypeId*/); - void ScheduleQueueUpdate(uint32 /*arenaRating*/, ArenaType /*arenaType*/, BattleGroundQueueTypeId /*bgQueueTypeId*/, BattleGroundTypeId /*bgTypeId*/, BattleGroundBracketId /*bracketId*/); uint32 GetMaxRatingDifference() const; uint32 GetRatingDiscardTimer() const; uint32 GetPrematureFinishTime() const; diff --git a/src/game/BattleGround/BattleGroundQueue.cpp b/src/game/BattleGround/BattleGroundQueue.cpp index 3016b7f2e8..d20e888cf0 100644 --- a/src/game/BattleGround/BattleGroundQueue.cpp +++ b/src/game/BattleGround/BattleGroundQueue.cpp @@ -1199,26 +1199,31 @@ bool BgQueueRemoveEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) // battleground can be deleted already when we are removing queue info // bg pointer can be nullptr! so use it carefully! + bool isBattleGround = bg && bg->IsBattleGround(); + uint32 queueSlot = plr->GetBattleGroundQueueIndex(event.m_bgQueueTypeId); if (queueSlot < PLAYER_MAX_BATTLEGROUND_QUEUES) // player is in queue, or in Battleground { - // check if player is in queue for this BG and if we are removing his invite event - BattleGroundQueueItem& bgQueue = sBattleGroundMgr.m_battleGroundQueues[event.m_bgQueueTypeId]; - if (bgQueue.IsPlayerInvited(event.m_playerGuid, event.m_bgInstanceGuid, event.m_removeTime)) + sWorld.GetBGueue().GetMessager().AddMessage([bgQueueTypeId = event.m_bgQueueTypeId, bgTypeId = , playerGuid = event.m_playerGuid, instanceGuid = event.m_bgInstanceGuid, removeTime = event.m_removeTime, isBattleGround](BattleGroundQueue* queue) { - DEBUG_LOG("Battleground: removing player %u from bg queue for instance %u because of not pressing enter battle in time.", plr->GetGUIDLow(), event.m_bgInstanceGuid); + // check if player is in queue for this BG and if we are removing his invite event + BattleGroundQueueItem& bgQueue = queue->m_battleGroundQueues[bgQueueTypeId]; + if (bgQueue.IsPlayerInvited(playerGuid, instanceGuid, removeTime)) + { + DEBUG_LOG("Battleground: removing player %u from bg queue for instance %u because of not pressing enter battle in time.", playerGuid.GetCounter(), instanceGuid); - plr->RemoveBattleGroundQueueId(event.m_bgQueueTypeId); - bgQueue.RemovePlayer(event.m_playerGuid, true); + plr->RemoveBattleGroundQueueId(bgTypeId); + bgQueue.RemovePlayer(playerGuid, true); - // update queues if battleground isn't ended - if (bg && bg->IsBattleGround() && bg->GetStatus() != STATUS_WAIT_LEAVE) - sBattleGroundMgr.ScheduleQueueUpdate(0, ARENA_TYPE_NONE, event.m_bgQueueTypeId, event.m_bgTypeId, bg->GetBracketId()); + // update queues if battleground isn't ended + if (isBattleGround && bg->GetStatus() != STATUS_WAIT_LEAVE) + queue->ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, bg->GetBracketId()); - WorldPacket data; - sBattleGroundMgr.BuildBattleGroundStatusPacket(data, bg, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE); - plr->GetSession()->SendPacket(data); - } + WorldPacket data; + sBattleGroundMgr.BuildBattleGroundStatusPacket(data, bg, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE); + plr->GetSession()->SendPacket(data); + } + }); } }); @@ -1355,3 +1360,29 @@ void BattleGroundQueue::InitAutomaticArenaPointDistribution() } } } + +/** + Method that schedules queue update + + @param arena rating + @param arena type + @param battleground queue type id + @param battleground type id + @param bracket id +*/ +void BattleGroundQueue::ScheduleQueueUpdate(uint32 arenaRating, ArenaType arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BattleGroundBracketId bracketId) +{ + // we will use only 1 number created of bgTypeId and bracket_id + uint64 schedule_id = (uint64(arenaRating) << 32) | (uint64(arenaType) << 24) | (uint64(bgQueueTypeId) << 16) | (uint64(bgTypeId) << 8) | bracketId; + bool found = false; + for (unsigned long long i : m_queueUpdateScheduler) + { + if (i == schedule_id) + { + found = true; + break; + } + } + if (!found) + m_queueUpdateScheduler.push_back(schedule_id); +} diff --git a/src/game/BattleGround/BattleGroundQueue.h b/src/game/BattleGround/BattleGroundQueue.h index 4de3d41947..a50b1478c4 100644 --- a/src/game/BattleGround/BattleGroundQueue.h +++ b/src/game/BattleGround/BattleGroundQueue.h @@ -166,6 +166,8 @@ class BgQueueRemoveEvent : public BasicEvent class BattleGroundQueue { + friend class BgQueueInviteEvent; + friend class BgQueueRemoveEvent; public: BattleGroundQueue(); @@ -174,6 +176,8 @@ class BattleGroundQueue Messager& GetMessager() { return m_messager; } void InitAutomaticArenaPointDistribution(); + + void ScheduleQueueUpdate(uint32 /*arenaRating*/, ArenaType /*arenaType*/, BattleGroundQueueTypeId /*bgQueueTypeId*/, BattleGroundTypeId /*bgTypeId*/, BattleGroundBracketId /*bracketId*/); private: BattleGroundQueueItem m_battleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code diff --git a/src/game/World/World.h b/src/game/World/World.h index 45fd6282e6..ba7679c32b 100644 --- a/src/game/World/World.h +++ b/src/game/World/World.h @@ -31,6 +31,7 @@ #include "Multithreading/Messager.h" #include "Globals/GraveyardManager.h" #include "LFG/LFGQueue.h" +#include "BattleGround/BattleGroundQueue.h" #include #include @@ -682,6 +683,7 @@ class World void SendGMTextFlags(uint32 accountFlag, int32 stringId, std::string type, const char* message); LFGQueue& GetLFGQueue() { return m_lfgQueue; } + BattleGroundQueue& GetBGueue() { return m_bgQueue; } void StartLFGQueueThread(); void StartBGQueueThread(); protected: