Skip to content

Commit

Permalink
LFG: Add safeguards against nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Nov 6, 2024
1 parent 492a0a0 commit f431038
Showing 1 changed file with 46 additions and 49 deletions.
95 changes: 46 additions & 49 deletions src/game/LFG/LFGQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ void LFGQueue::StopLookingForMore(ObjectGuid playerGuid)

sWorld.GetMessager().AddMessage([playerGuid](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

if (player)
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->m_lfgInfo.queued = false;
});
}
Expand All @@ -121,8 +119,7 @@ void LFGQueue::StartLookingForGroup(LFGPlayerQueueInfo info, ObjectGuid invokerP
sWorld.GetMessager().AddMessage([leaderGuid = info.leaderGuid, invokerPlayer](World* world)
{
Player* player = sObjectMgr.GetPlayer(invokerPlayer);

if (leaderGuid != invokerPlayer)
if (leaderGuid != invokerPlayer && player)
{
WorldPacket data(SMSG_LFG_LEADER_IS_LFM);
player->GetSession()->SendPacket(data);
Expand All @@ -137,9 +134,7 @@ void LFGQueue::StartLookingForGroup(LFGPlayerQueueInfo info, ObjectGuid invokerP

sWorld.GetMessager().AddMessage([invokerPlayer](World* world)
{
Player* player = sObjectMgr.GetPlayer(invokerPlayer);

if (player)
if (Player* player = sObjectMgr.GetPlayer(invokerPlayer))
player->GetSession()->m_lfgInfo.queued = true;
});

Expand All @@ -163,9 +158,7 @@ void LFGQueue::StopLookingForGroup(ObjectGuid leaderGuid, ObjectGuid playerGuid)

sWorld.GetMessager().AddMessage([playerGuid](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

if (player)
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->m_lfgInfo.queued = false;
});
}
Expand Down Expand Up @@ -198,9 +191,7 @@ void LFGQueue::SetLfgSlot(ObjectGuid leaderGuid, uint32 slot, uint16 entry, uint
{
sWorld.GetMessager().AddMessage([leaderGuid](World* world)
{
Player* player = sObjectMgr.GetPlayer(leaderGuid);

if (player)
if (Player* player = sObjectMgr.GetPlayer(leaderGuid))
player->GetSession()->m_lfgInfo.queued = false;
});
}
Expand All @@ -225,9 +216,7 @@ void LFGQueue::SetLfmData(ObjectGuid leaderGuid, uint16 entry, uint16 type)
{
sWorld.GetMessager().AddMessage([leaderGuid](World* world)
{
Player* player = sObjectMgr.GetPlayer(leaderGuid);

if (player)
if (Player* player = sObjectMgr.GetPlayer(leaderGuid))
player->GetSession()->m_lfgInfo.queued = false;
});
}
Expand Down Expand Up @@ -263,9 +252,8 @@ void LFGQueue::TryJoin(ObjectGuid playerGuid, bool initial)
{
sWorld.GetMessager().AddMessage([playerGuid](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

player->GetSession()->SendMeetingStoneInProgress();
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->SendMeetingStoneInProgress();
});
}
}
Expand Down Expand Up @@ -301,9 +289,8 @@ void LFGQueue::TryFill(ObjectGuid leaderGuid, bool initial)
{
sWorld.GetMessager().AddMessage([leaderGuid](World* world)
{
Player* player = sObjectMgr.GetPlayer(leaderGuid);

player->GetSession()->SendMeetingStoneInProgress();
if (Player* player = sObjectMgr.GetPlayer(leaderGuid))
player->GetSession()->SendMeetingStoneInProgress();
});
}
}
Expand All @@ -324,7 +311,7 @@ bool LFGQueue::AddMember(LFGPlayerQueueInfo& info, LFGPlayerQueueInfo& playerInf
{
Player* player = sObjectMgr.GetPlayer(playerGuid);
Player* leader = sObjectMgr.GetPlayer(leaderGuid);
Group* grp = leader->GetGroup();
Group* grp = leader ? leader->GetGroup() : nullptr;

if (grp && grp->IsFull())
{
Expand Down Expand Up @@ -360,6 +347,20 @@ void LFGQueue::HandlePendingJoin(ObjectGuid playerGuid, bool accept)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);
Player* leader = sObjectMgr.GetPlayer(leaderGuid);
if (!leader)
{
auto playerString = playerGuid.GetString(); auto leaderString = leaderGuid.GetString();
sLog.outError("LFGQueue::HandlePendingJoin failed for guids %s %s due to offline leader", playerString.c_str(), leaderString.c_str());
return;
}

if (!player)
{
auto playerString = playerGuid.GetString(); auto leaderString = leaderGuid.GetString();
sLog.outError("LFGQueue::HandlePendingJoin failed for guids %s %s due to offline player", playerString.c_str(), leaderString.c_str());
return;
}

Group* grp = leader->GetGroup();

Group* group = player->GetGroup();
Expand All @@ -370,7 +371,7 @@ void LFGQueue::HandlePendingJoin(ObjectGuid playerGuid, bool accept)
if (!grp)
{
grp = new Group();
if (!grp->Create(leader->GetObjectGuid(), leader->GetName()))
if (!grp->Create(leaderGuid, leader->GetName()))
{
delete grp;
grp = nullptr;
Expand Down Expand Up @@ -475,9 +476,7 @@ void LFGQueue::PendingJoinSuccess(ObjectGuid leaderGuid, ObjectGuid playerGuid,
{
sWorld.GetMessager().AddMessage([playerGuid](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

if (player)
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->m_lfgInfo.queued = false;
});
}
Expand Down Expand Up @@ -509,9 +508,7 @@ void LFGQueue::SendLFGUpdate(ObjectGuid leaderGuid, ObjectGuid playerGuid) const

sWorld.GetMessager().AddMessage([playerGuid, response](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

if (player)
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->SendPacket(response);
});
}
Expand All @@ -531,9 +528,8 @@ void LFGQueue::SendLFGUpdateLFG(ObjectGuid playerGuid) const

sWorld.GetMessager().AddMessage([playerGuid, response](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

player->GetSession()->SendPacket(response);
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->SendPacket(response);
});
}

Expand All @@ -556,9 +552,8 @@ void LFGQueue::SendLFGUpdateLFM(ObjectGuid playerGuid) const

sWorld.GetMessager().AddMessage([playerGuid, response](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

player->GetSession()->SendPacket(response);
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->SendPacket(response);
});
}

Expand Down Expand Up @@ -638,9 +633,8 @@ void LFGQueue::SendLFGListQueryResponse(ObjectGuid playerGuid, Team playerTeam,

sWorld.GetMessager().AddMessage([playerGuid, response](World* world)
{
Player* player = sObjectMgr.GetPlayer(playerGuid);

player->GetSession()->SendPacket(response);
if (Player* player = sObjectMgr.GetPlayer(playerGuid))
player->GetSession()->SendPacket(response);
});
}

Expand Down Expand Up @@ -687,20 +681,23 @@ bool LFGQueue::GroupUpdateQueueStatus(ObjectGuid playerGuid, ObjectGuid leaderGu

sWorld.GetMessager().AddMessage([leaderGuid, data, message, lfm, members](World* world)
{
Player* player = sObjectMgr.GetPlayer(leaderGuid);

player->GetSession()->SendPacket(data);

if (lfm)
player->GetSession()->SendPacket(message);

for (auto& member : members) // TODO: Ignore players in bg here?
if (Player* player = sObjectMgr.GetPlayer(leaderGuid))
{
player->GetSession()->SendPacket(data);

if (lfm)
player->GetSession()->SendPacket(message);
}

for (auto& memberGuid : members) // TODO: Ignore players in bg here?
{
if (Player* member = sObjectMgr.GetPlayer(memberGuid))
{
member->GetSession()->SendPacket(data);

if (lfm)
member->GetSession()->SendPacket(message);
}
}
});
return true;
}
Expand Down

0 comments on commit f431038

Please sign in to comment.