Skip to content

Commit

Permalink
Add an assert to catch bg invited count underflowing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed May 18, 2024
1 parent 7a2d912 commit 03a6749
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
57 changes: 57 additions & 0 deletions src/game/Battlegrounds/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 3 additions & 9 deletions src/game/Battlegrounds/BattleGround.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 03a6749

Please sign in to comment.