From 03a6749ec6e9bbed397a41846faac021b2f39e3f Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Sat, 18 May 2024 14:51:53 +0300 Subject: [PATCH] Add an assert to catch bg invited count underflowing. --- src/game/Battlegrounds/BattleGround.cpp | 57 +++++++++++++++++++++++++ src/game/Battlegrounds/BattleGround.h | 12 ++---- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/game/Battlegrounds/BattleGround.cpp b/src/game/Battlegrounds/BattleGround.cpp index 1f580180717..bb525b5490c 100644 --- a/src/game/Battlegrounds/BattleGround.cpp +++ b/src/game/Battlegrounds/BattleGround.cpp @@ -1168,6 +1168,63 @@ uint32 BattleGround::GetFreeSlotsForTeam(Team team) const return 0; } +void BattleGround::DecreaseInvitedCount(Team team) +{ + switch (team) + { + case ALLIANCE: + { + MANGOS_ASSERT(m_invitedAlliance-- > 0); + break; + } + case HORDE: + { + MANGOS_ASSERT(m_invitedHorde-- > 0); + break; + } + default: + { + sLog.Out(LOG_BG, LOG_LVL_ERROR, "BattleGround::DecreaseInvitedCount - Unknown player team %u.", team); + break; + } + } +} +void BattleGround::IncreaseInvitedCount(Team team) +{ + switch (team) + { + case ALLIANCE: + { + ++m_invitedAlliance; + break; + } + case HORDE: + { + ++m_invitedHorde; + break; + } + default: + { + sLog.Out(LOG_BG, LOG_LVL_ERROR, "BattleGround::IncreaseInvitedCount - Unknown player team %u.", team); + break; + } + } +} + +uint32 BattleGround::GetInvitedCount(Team team) const +{ + switch (team) + { + case ALLIANCE: + return m_invitedAlliance; + case HORDE: + return m_invitedHorde; + } + + sLog.Out(LOG_BG, LOG_LVL_ERROR, "BattleGround::GetInvitedCount - Unknown player team %u.", team); + return 0; +} + bool BattleGround::HasFreeSlots() const { return GetPlayersSize() < GetMaxPlayers(); diff --git a/src/game/Battlegrounds/BattleGround.h b/src/game/Battlegrounds/BattleGround.h index 8ddc9315869..8633862503c 100644 --- a/src/game/Battlegrounds/BattleGround.h +++ b/src/game/Battlegrounds/BattleGround.h @@ -147,15 +147,9 @@ class BattleGround void AddToBGFreeSlotQueue(); //this queue will be useful when more battlegrounds instances will be available void RemoveFromBGFreeSlotQueue(); //this method could delete whole BG instance, if another free is available - void DecreaseInvitedCount(Team team) { (team == ALLIANCE) ? --m_invitedAlliance : --m_invitedHorde; } - void IncreaseInvitedCount(Team team) { (team == ALLIANCE) ? ++m_invitedAlliance : ++m_invitedHorde; } - uint32 GetInvitedCount(Team team) const - { - if (team == ALLIANCE) - return m_invitedAlliance; - else - return m_invitedHorde; - } + void DecreaseInvitedCount(Team team); + void IncreaseInvitedCount(Team team); + uint32 GetInvitedCount(Team team) const; bool HasFreeSlots() const; uint32 GetFreeSlotsForTeam(Team team) const;