[Fix issue #1528] Close small window where the “in a BG/arena” state can change between the check (InBattleground() / InArena()) and grabbing the pointer (GetBattleground()), which leads to a null dereference. (#1530)

* Harden playerbot logout & packet dispatch; add null-safety in chat hooks and RPG checks

* Fix Issue 1528
This commit is contained in:
Alex Dcnh
2025-08-11 16:27:38 +02:00
committed by GitHub
parent e4ea8e2694
commit 2e0a161623

View File

@@ -994,9 +994,18 @@ void RandomPlayerbotMgr::CheckBgQueue()
isRated = ginfo.IsRated; isRated = ginfo.IsRated;
} }
if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID()) || /*if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID()) ||
(player->InArena() && player->GetBattleground()->isRated())) (player->InArena() && player->GetBattleground()->isRated()))
isRated = true;*/
if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID())) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528
{
isRated = true; isRated = true;
}
else if (Battleground const* bg = player->GetBattleground())
{
if (player->InArena() && bg->isRated())
isRated = true;
}
if (isRated) if (isRated)
BattlegroundData[queueTypeId][bracketId].ratedArenaPlayerCount++; BattlegroundData[queueTypeId][bracketId].ratedArenaPlayerCount++;
@@ -1011,15 +1020,24 @@ void RandomPlayerbotMgr::CheckBgQueue()
else else
BattlegroundData[queueTypeId][bracketId].bgHordePlayerCount++; BattlegroundData[queueTypeId][bracketId].bgHordePlayerCount++;
// If a player has joined the BG, update the instance count in BattlegroundData (for consistency) /*// If a player has joined the BG, update the instance count in BattlegroundData (for consistency)
if (player->InBattleground()) if (player->InBattleground())
{ {
std::vector<uint32>* instanceIds = nullptr; std::vector<uint32>* instanceIds = nullptr;
uint32 instanceId = player->GetBattleground()->GetInstanceID(); uint32 instanceId = player->GetBattleground()->GetInstanceID();
instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances; instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances;*/
if (instanceIds && // If a player has joined the BG, update the instance count in BattlegroundData (for consistency)
if (Battleground const* bg = player->GetBattleground()) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528
{
std::vector<uint32>* instanceIds = nullptr;
uint32 instanceId = bg->GetInstanceID();
instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances;
if (instanceIds &&
std::find(instanceIds->begin(), instanceIds->end(), instanceId) == instanceIds->end()) std::find(instanceIds->begin(), instanceIds->end(), instanceId) == instanceIds->end())
instanceIds->push_back(instanceId); instanceIds->push_back(instanceId);
BattlegroundData[queueTypeId][bracketId].bgInstanceCount = instanceIds->size(); BattlegroundData[queueTypeId][bracketId].bgInstanceCount = instanceIds->size();
@@ -1082,10 +1100,20 @@ void RandomPlayerbotMgr::CheckBgQueue()
isRated = ginfo.IsRated; isRated = ginfo.IsRated;
} }
if (bgQueue.IsPlayerInvitedToRatedArena(guid) || (bot->InArena() && bot->GetBattleground()->isRated())) /*if (bgQueue.IsPlayerInvitedToRatedArena(guid) || (bot->InArena() && bot->GetBattleground()->isRated()))
isRated = true;*/
if (bgQueue.IsPlayerInvitedToRatedArena(guid)) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528
{
isRated = true; isRated = true;
}
if (isRated) else if (Battleground const* bg = bot->GetBattleground())
{
if (bot->InArena() && bg->isRated())
isRated = true;
}
// END [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528
if (isRated)
BattlegroundData[queueTypeId][bracketId].ratedArenaBotCount++; BattlegroundData[queueTypeId][bracketId].ratedArenaBotCount++;
else else
BattlegroundData[queueTypeId][bracketId].skirmishArenaBotCount++; BattlegroundData[queueTypeId][bracketId].skirmishArenaBotCount++;
@@ -1098,10 +1126,15 @@ void RandomPlayerbotMgr::CheckBgQueue()
BattlegroundData[queueTypeId][bracketId].bgHordeBotCount++; BattlegroundData[queueTypeId][bracketId].bgHordeBotCount++;
} }
if (bot->InBattleground()) /*if (bot->InBattleground())
{ {
std::vector<uint32>* instanceIds = nullptr; std::vector<uint32>* instanceIds = nullptr;
uint32 instanceId = bot->GetBattleground()->GetInstanceID(); uint32 instanceId = bot->GetBattleground()->GetInstanceID();*/
if (Battleground const* bg = bot->GetBattleground()) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528
{
std::vector<uint32>* instanceIds = nullptr;
uint32 instanceId = bg->GetInstanceID();
//END [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528
bool isArena = false; bool isArena = false;
bool isRated = false; bool isRated = false;
@@ -1109,7 +1142,8 @@ void RandomPlayerbotMgr::CheckBgQueue()
if (bot->InArena()) if (bot->InArena())
{ {
isArena = true; isArena = true;
if (bot->GetBattleground()->isRated()) // if (bot->GetBattleground()->isRated())
if (bg->isRated()) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528
{ {
isRated = true; isRated = true;
instanceIds = &BattlegroundData[queueTypeId][bracketId].ratedArenaInstances; instanceIds = &BattlegroundData[queueTypeId][bracketId].ratedArenaInstances;