Entities/Unit: Cleanup all the direct accesses to m_unitMovedByMe. Refactor the field to be protected. Add assertions to catch dangling pointers.

This commit is contained in:
Treeston
2019-06-23 16:44:37 +02:00
parent b3ee407707
commit 396f87c30d
8 changed files with 36 additions and 50 deletions

View File

@@ -66,7 +66,7 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
Player* pUser = _player;
// ignore for remote control state
if (pUser->m_unitMovedByMe != pUser)
if (pUser->GetUnitBeingMoved() != pUser)
return;
uint8 bagIndex, slot, castFlags;
@@ -177,7 +177,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
Player* player = GetPlayer();
// ignore for remote control state
if (player->m_unitMovedByMe != player)
if (player->GetUnitBeingMoved() != player)
return;
// additional check, client outputs message on its own
@@ -297,8 +297,8 @@ void WorldSession::HandleGameObjectUseOpcode(WorldPacket& recvData)
if (GameObject* obj = GetPlayer()->GetGameObjectIfCanInteractWith(guid))
{
// ignore for remote control state
if (GetPlayer()->m_unitMovedByMe != GetPlayer())
if (!(GetPlayer()->IsOnVehicle(GetPlayer()->m_unitMovedByMe) || GetPlayer()->IsMounted()) && !obj->GetGOInfo()->IsUsableMounted())
if (GetPlayer()->GetUnitBeingMoved() != GetPlayer())
if (!(GetPlayer()->IsOnVehicle(GetPlayer()->GetUnitBeingMoved()) || GetPlayer()->IsMounted()) && !obj->GetGOInfo()->IsUsableMounted())
return;
obj->Use(GetPlayer());
@@ -313,7 +313,7 @@ void WorldSession::HandleGameobjectReportUse(WorldPacket& recvPacket)
TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_GAMEOBJ_REPORT_USE Message [%s]", guid.ToString().c_str());
// ignore for remote control state
if (_player->m_unitMovedByMe != _player)
if (_player->GetUnitBeingMoved() != _player)
return;
if (GameObject* go = GetPlayer()->GetGameObjectIfCanInteractWith(guid))
@@ -335,7 +335,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("network", "WORLD: got cast spell packet, castCount: %u, spellId: %u, castFlags: %u, data length = %u", castCount, spellId, castFlags, (uint32)recvPacket.size());
// ignore for remote control state (for player case)
Unit* mover = _player->m_unitMovedByMe;
Unit* mover = _player->GetUnitBeingMoved();
if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER)
{
recvPacket.rfinish(); // prevent spam at ignore packet
@@ -549,7 +549,7 @@ void WorldSession::HandleCancelChanneling(WorldPacket& recvData)
recvData.read_skip<uint32>(); // spellid, not used
// ignore for remote control state (for player case)
Unit* mover = _player->m_unitMovedByMe;
Unit* mover = _player->GetUnitBeingMoved();
if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER)
return;
@@ -559,7 +559,7 @@ void WorldSession::HandleCancelChanneling(WorldPacket& recvData)
void WorldSession::HandleTotemDestroyed(WorldPacket& recvPacket)
{
// ignore for remote control state
if (_player->m_unitMovedByMe != _player)
if (_player->GetUnitBeingMoved() != _player)
return;
uint8 slotId;