From aa60def6acd9b15267cf3c95f9a7e65531838796 Mon Sep 17 00:00:00 2001 From: QAston Date: Sat, 1 Aug 2009 20:23:23 +0200 Subject: *Teleport player to homebind if instance can't be created in WorldSession::HandleMoveWorldportAckOpcode. --HG-- branch : trunk --- src/game/GameObject.cpp | 9 +++++---- src/game/GameObject.h | 2 +- src/game/MovementHandler.cpp | 2 +- src/game/ObjectAccessor.h | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index e6ff16f251c..f934d3d1fe7 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -123,8 +123,7 @@ void GameObject::RemoveFromWorld() // Possible crash at access to deleted GO in Unit::m_gameobj if(uint64 owner_guid = GetOwnerGUID()) { - Unit* owner = ObjectAccessor::GetUnit(*this,owner_guid); - if(owner) + if(Unit * owner = GetOwner(false)) owner->RemoveGameObject(this,false); else if(!IS_PLAYER_GUID(owner_guid)) sLog.outError("Delete GameObject (GUID: %u Entry: %u ) that have references in not found creature %u GO list. Crash possible later.",GetGUIDLow(),GetGOInfo()->id,GUID_LOPART(owner_guid)); @@ -707,9 +706,11 @@ bool GameObject::IsTransport() const return gInfo->type == GAMEOBJECT_TYPE_TRANSPORT || gInfo->type == GAMEOBJECT_TYPE_MO_TRANSPORT; } -Unit* GameObject::GetOwner() const +Unit* GameObject::GetOwner(bool inWorld) const { - return ObjectAccessor::GetUnit(*this, GetOwnerGUID()); + if (inWorld) + return ObjectAccessor::GetUnit(*this, GetOwnerGUID()); + return ObjectAccessor::GetUnitInOrOutOfWorld(*this, GetOwnerGUID()); } void GameObject::SaveRespawnTime() diff --git a/src/game/GameObject.h b/src/game/GameObject.h index 97c532605d3..b96213bfad5 100644 --- a/src/game/GameObject.h +++ b/src/game/GameObject.h @@ -593,7 +593,7 @@ class TRINITY_DLL_SPEC GameObject : public WorldObject void SetOwnerGUID(uint64 owner); uint64 GetOwnerGUID() const { return GetUInt64Value(OBJECT_FIELD_CREATED_BY); } - Unit* GetOwner() const; + Unit* GetOwner(bool inWorld = true) const; uint32 GetDBTableGUIDLow() const { return m_DBTableGuid; } diff --git a/src/game/MovementHandler.cpp b/src/game/MovementHandler.cpp index 68deb5af9f4..5ec73f9cb48 100644 --- a/src/game/MovementHandler.cpp +++ b/src/game/MovementHandler.cpp @@ -72,7 +72,7 @@ void WorldSession::HandleMoveWorldportAckOpcode() Map * newMap = MapManager::Instance().CreateMap(loc.mapid, GetPlayer(), 0); // the CanEnter checks are done in TeleporTo but conditions may change // while the player is in transit, for example the map may get full - if (!newMap->CanEnter(GetPlayer())) + if (!newMap || !newMap->CanEnter(GetPlayer())) { sLog.outError("Map %d could not be created for player %d, porting player to homebind", loc.mapid, GetPlayer()->GetGUIDLow()); GetPlayer()->RelocateToHomebind(loc.mapid); diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index 2dd1b56641f..403470f9446 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -121,6 +121,24 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton::Find(guid); } + static Unit* GetUnitInOrOutOfWorld(uint64 guid, Unit* /*fake*/) + { + if(!guid) + return NULL; + + if (IS_PLAYER_GUID(guid)) + { + Unit * u = (Unit*)HashMapHolder::Find(guid); + if(!u) + return NULL; + + return u; + } + // Other object types than player are unloaded while out of world + return GetObjectInWorld(guid, ((Unit*)NULL)); + } + + template static T* GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/) { T* obj = HashMapHolder::Find(guid); @@ -150,6 +168,7 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton