Skip to content

Commit e588638

Browse files
authored
refactor(Core/Wintergrasp): Use helper to clear tracking references (azerothcore#26003)
1 parent ae8866a commit e588638

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

src/server/game/Battlefield/Battlefield.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,20 @@ Battlefield::~Battlefield()
7474
CapturePoints.clear();
7575
}
7676

77-
void Battlefield::HandlePlayerEnterZone(Player* player, uint32 /*zone*/)
77+
void Battlefield::RemovePlayerFromTracking(ObjectGuid playerGuid)
7878
{
79-
// Clear any stale entries from a prior visit that did not unwind cleanly.
80-
// Runs before the script hook so scripts see a clean state if they read any
81-
// of these containers.
8279
for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
8380
{
84-
PlayersInWar[i].erase(player->GetGUID());
85-
InvitedPlayers[i].erase(player->GetGUID());
86-
PlayersInQueue[i].erase(player->GetGUID());
87-
PlayersWillBeKick[i].erase(player->GetGUID());
88-
Players[i].erase(player->GetGUID());
81+
InvitedPlayers[i].erase(playerGuid);
82+
PlayersInQueue[i].erase(playerGuid);
83+
PlayersWillBeKick[i].erase(playerGuid);
84+
Players[i].erase(playerGuid);
8985
}
86+
}
87+
88+
void Battlefield::HandlePlayerEnterZone(Player* player, uint32 /*zone*/)
89+
{
90+
RemovePlayerFromTracking(player->GetGUID());
9091

9192
// Allow scripts to adjust the player's effective team or appearance before
9293
// any team-based battlefield containers (such as player lists or queues) are updated.
@@ -141,13 +142,7 @@ void Battlefield::HandlePlayerLeaveZone(Player* player, uint32 /*zone*/)
141142
for (BfCapturePoint* cp : CapturePoints)
142143
cp->HandlePlayerLeave(player);
143144

144-
for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
145-
{
146-
InvitedPlayers[i].erase(player->GetGUID());
147-
PlayersInQueue[i].erase(player->GetGUID());
148-
PlayersWillBeKick[i].erase(player->GetGUID());
149-
Players[i].erase(player->GetGUID());
150-
}
145+
RemovePlayerFromTracking(player->GetGUID());
151146
SendRemoveWorldStates(player);
152147
RemovePlayerFromResurrectQueue(player->GetGUID());
153148
OnPlayerLeaveZone(player);

src/server/game/Battlefield/Battlefield.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ class Battlefield : public ZoneScript
444444
/// Returns true if the player is already tracked as actively in the war or invited to join it.
445445
bool IsPlayerInWarOrInvited(Player* player) const;
446446

447+
void RemovePlayerFromTracking(ObjectGuid playerGuid);
448+
447449
// Player-iteration helpers: resolve each GUID to a live Player* and call fn(player).
448450
// Using templates avoids std::function overhead and works naturally with lambdas.
449451
template<typename Func>

0 commit comments

Comments
 (0)