From 04183cb8de5b6ad63741868c14426cb91b79417a Mon Sep 17 00:00:00 2001 From: Kandera Date: Fri, 18 Nov 2011 16:47:06 -0500 Subject: Core/LFG: Fix being unable to enter an instance to retrieve body when you have 5 or more instances in the database. --- src/server/game/Maps/MapManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server/game/Maps/MapManager.cpp') diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index 78aeb32ab2d..22eaa77cc94 100755 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -248,7 +248,7 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck) instaceIdToCheck = save->GetInstanceId(); // instanceId can never be 0 - will not be found - if (!player->CheckInstanceCount(instaceIdToCheck)) + if (!player->CheckInstanceCount(instaceIdToCheck) && !player->isDead()) { player->SendTransferAborted(mapid, TRANSFER_ABORT_TOO_MANY_INSTANCES); return false; -- cgit v1.2.3 From 298c162c86130d59c6c60f2fedc7a9b2af034a8d Mon Sep 17 00:00:00 2001 From: megamage Date: Wed, 23 Nov 2011 09:34:08 -0500 Subject: Do not allow an instance map to be created twice if it already exists. Fix #4018. --- src/server/game/Instances/InstanceSaveMgr.cpp | 2 +- src/server/game/Maps/MapInstanced.cpp | 12 ++++++++---- src/server/game/Maps/MapInstanced.h | 15 ++++++--------- src/server/game/Maps/MapManager.cpp | 5 +++-- 4 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src/server/game/Maps/MapManager.cpp') diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index bc2648ed02b..c4df7d647c3 100755 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -521,7 +521,7 @@ void InstanceSaveManager::_ResetInstance(uint32 mapid, uint32 instanceId) DeleteInstanceFromDB(instanceId); // even if save not loaded - Map* iMap = ((MapInstanced*)map)->FindMap(instanceId); + Map* iMap = ((MapInstanced*)map)->FindInstanceMap(instanceId); if (iMap && iMap->IsDungeon()) ((InstanceMap*)iMap)->Reset(INSTANCE_RESET_RESPAWN_DELAY); diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp index bbade4c9dc3..a56a193ba64 100755 --- a/src/server/game/Maps/MapInstanced.cpp +++ b/src/server/game/Maps/MapInstanced.cpp @@ -110,7 +110,7 @@ void MapInstanced::UnloadAll() - create the instance if it's not created already - the player is not actually added to the instance (only in InstanceMap::Add) */ -Map* MapInstanced::CreateInstance(const uint32 mapId, Player* player) +Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player) { if (GetId() != mapId || !player) return NULL; @@ -124,7 +124,7 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player* player) // the instance id is set in battlegroundid NewInstanceId = player->GetBattlegroundId(); if (!NewInstanceId) return NULL; - map = _FindMap(NewInstanceId); + map = FindInstanceMap(NewInstanceId); if (!map) map = CreateBattleground(NewInstanceId, player->GetBattleground()); } @@ -151,7 +151,7 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player* player) { // solo/perm/group NewInstanceId = pSave->GetInstanceId(); - map = _FindMap(NewInstanceId); + map = FindInstanceMap(NewInstanceId); // it is possible that the save exists but the map doesn't if (!map) map = CreateInstance(NewInstanceId, pSave, pSave->GetDifficulty()); @@ -163,7 +163,11 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player* player) NewInstanceId = sMapMgr->GenerateInstanceId(); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); - map = CreateInstance(NewInstanceId, NULL, diff); + //Seems it is now possible, but I do not know if it should be allowed + //ASSERT(!FindInstanceMap(NewInstanceId)); + map = FindInstanceMap(NewInstanceId); + if (!map) + map = CreateInstance(NewInstanceId, NULL, diff); } } diff --git a/src/server/game/Maps/MapInstanced.h b/src/server/game/Maps/MapInstanced.h index af303ed0e9e..9b714cb7fb3 100755 --- a/src/server/game/Maps/MapInstanced.h +++ b/src/server/game/Maps/MapInstanced.h @@ -39,8 +39,12 @@ class MapInstanced : public Map void UnloadAll(); bool CanEnter(Player* player); - Map* CreateInstance(const uint32 mapId, Player* player); - Map* FindMap(uint32 InstanceId) const { return _FindMap(InstanceId); } + Map* CreateInstanceForPlayer(const uint32 mapId, Player* player); + Map* FindInstanceMap(uint32 instanceId) const + { + InstancedMaps::const_iterator i = m_InstancedMaps.find(instanceId); + return(i == m_InstancedMaps.end() ? NULL : i->second); + } bool DestroyInstance(InstancedMaps::iterator &itr); void AddGridMapReference(const GridCoord &p) @@ -60,18 +64,11 @@ class MapInstanced : public Map virtual void InitVisibilityDistance(); private: - InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty); BattlegroundMap* CreateBattleground(uint32 InstanceId, Battleground* bg); InstancedMaps m_InstancedMaps; - Map* _FindMap(uint32 InstanceId) const - { - InstancedMaps::const_iterator i = m_InstancedMaps.find(InstanceId); - return(i == m_InstancedMaps.end() ? NULL : i->second); - } - uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]; }; #endif diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index 22eaa77cc94..2533096cc22 100755 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -125,7 +125,8 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj, uint32 /*instanceI //if (!obj->IsInWorld()) sLog->outError("GetMap: called for map %d with object (typeid %d, guid %d, mapid %d, instanceid %d) who is not in world!", id, obj->GetTypeId(), obj->GetGUIDLow(), obj->GetMapId(), obj->GetInstanceId()); Map* m = _createBaseMap(id); - if (m && (obj->GetTypeId() == TYPEID_PLAYER) && m->Instanceable()) m = ((MapInstanced*)m)->CreateInstance(id, (Player*)obj); + if (m && obj->GetTypeId() == TYPEID_PLAYER && m->Instanceable()) + m = ((MapInstanced*)m)->CreateInstanceForPlayer(id, (Player*)obj); return m; } @@ -139,7 +140,7 @@ Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const if (!map->Instanceable()) return instanceId == 0 ? map : NULL; - return ((MapInstanced*)map)->FindMap(instanceId); + return ((MapInstanced*)map)->FindInstanceMap(instanceId); } bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck) -- cgit v1.2.3 From 98be413ce02d6c8420458f3df55e3061a9901034 Mon Sep 17 00:00:00 2001 From: megamage Date: Wed, 23 Nov 2011 12:45:59 -0500 Subject: Clean up very some confusing MapManager functions (create/find map/base map). --- src/server/game/Entities/Player/Player.cpp | 10 +++++----- src/server/game/Entities/Transport/Transport.cpp | 4 ++-- src/server/game/Maps/MapManager.cpp | 16 +++++++--------- src/server/game/Maps/MapManager.h | 21 +++++++++------------ .../WaypointMovementGenerator.cpp | 2 +- .../Server/Protocol/Handlers/MovementHandler.cpp | 2 +- 6 files changed, 25 insertions(+), 30 deletions(-) (limited to 'src/server/game/Maps/MapManager.cpp') diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 82e4ffe6769..bf68ec34b9d 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -940,7 +940,7 @@ bool Player::Create(uint32 guidlow, CharacterCreateInfo* createInfo) return false; } - SetMap(sMapMgr->CreateMap(info->mapId, this, 0)); + SetMap(sMapMgr->CreateMap(info->mapId, this)); uint8 powertype = cEntry->powerType; @@ -2205,7 +2205,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati if (!sMapMgr->CanPlayerEnter(mapid, this, false)) return false; - Map* map = sMapMgr->CreateMap(mapid, this, 0); + Map* map = sMapMgr->CreateMap(mapid, this); if (!map || map->CanEnter(this)) { //lets reset near teleport flag if it wasn't reset during chained teleports @@ -16790,7 +16790,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) // NOW player must have valid map // load the player's map here if it's not already loaded - Map* map = sMapMgr->CreateMap(mapId, this, instanceId); + Map* map = sMapMgr->CreateMap(mapId, this); if (!map) { @@ -16808,14 +16808,14 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) RelocateToHomebind(); } - map = sMapMgr->CreateMap(mapId, this, 0); + map = sMapMgr->CreateMap(mapId, this); if (!map) { PlayerInfo const* info = sObjectMgr->GetPlayerInfo(getRace(), getClass()); mapId = info->mapId; Relocate(info->positionX, info->positionY, info->positionZ, 0.0f); sLog->outError("Player (guidlow %d) have invalid coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.", guid, GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); - map = sMapMgr->CreateMap(mapId, this, 0); + map = sMapMgr->CreateMap(mapId, this); if (!map) { sLog->outError("Player (guidlow %d) has invalid default map coordinates (X: %f Y: %f Z: %f O: %f). or instance couldn't be created", guid, GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index b7f000a6c72..b92e1ad21dc 100755 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -98,7 +98,7 @@ void MapManager::LoadTransports() m_TransportsByMap[*i].insert(t); //If we someday decide to use the grid to track transports, here: - t->SetMap(sMapMgr->CreateMap(mapid, t, 0)); + t->SetMap(sMapMgr->CreateBaseMap(mapid)); t->AddToWorld(); ++count; @@ -494,7 +494,7 @@ void Transport::TeleportTransport(uint32 newMapid, float x, float y, float z) RemoveFromWorld(); ResetMap(); - Map* newMap = sMapMgr->CreateMap(newMapid, this, 0); + Map* newMap = sMapMgr->CreateBaseMap(newMapid); SetMap(newMap); ASSERT (GetMap()); AddToWorld(); diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index 2533096cc22..bb62912d204 100755 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -95,9 +95,9 @@ void MapManager::checkAndCorrectGridStatesArray() ++i_GridStateErrorCount; } -Map* MapManager::_createBaseMap(uint32 id) +Map* MapManager::CreateBaseMap(uint32 id) { - Map* m = _findMap(id); + Map* m = FindBaseMap(id); if (m == NULL) { @@ -119,21 +119,19 @@ Map* MapManager::_createBaseMap(uint32 id) return m; } -Map* MapManager::CreateMap(uint32 id, const WorldObject* obj, uint32 /*instanceId*/) +Map* MapManager::CreateMap(uint32 id, Player* player) { - ASSERT(obj); - //if (!obj->IsInWorld()) sLog->outError("GetMap: called for map %d with object (typeid %d, guid %d, mapid %d, instanceid %d) who is not in world!", id, obj->GetTypeId(), obj->GetGUIDLow(), obj->GetMapId(), obj->GetInstanceId()); - Map* m = _createBaseMap(id); + Map* m = CreateBaseMap(id); - if (m && obj->GetTypeId() == TYPEID_PLAYER && m->Instanceable()) - m = ((MapInstanced*)m)->CreateInstanceForPlayer(id, (Player*)obj); + if (m && m->Instanceable()) + m = ((MapInstanced*)m)->CreateInstanceForPlayer(id, player); return m; } Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const { - Map* map = _findMap(mapid); + Map* map = FindBaseMap(mapid); if (!map) return NULL; diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h index 926ff2c8051..6ce641f81bd 100755 --- a/src/server/game/Maps/MapManager.h +++ b/src/server/game/Maps/MapManager.h @@ -35,14 +35,18 @@ class MapManager friend class ACE_Singleton; public: - - Map* CreateMap(uint32, const WorldObject* obj, uint32 instanceId); - Map const* CreateBaseMap(uint32 id) const { return const_cast(this)->_createBaseMap(id); } - Map* FindMap(uint32 mapid, uint32 instanceId = 0) const; + Map* CreateBaseMap(uint32 mapId); + Map* FindBaseMap(uint32 mapId) const + { + MapMapType::const_iterator iter = i_maps.find(mapId); + return (iter == i_maps.end() ? NULL : iter->second); + } + Map* CreateMap(uint32 mapId, Player* player); + Map* FindMap(uint32 mapId, uint32 instanceId) const; uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const { - Map const* m = CreateBaseMap(mapid); + Map const* m = const_cast(this)->CreateBaseMap(mapid); return m->GetAreaFlag(x, y, z); } uint32 GetAreaId(uint32 mapid, float x, float y, float z) const @@ -163,13 +167,6 @@ class MapManager MapManager(const MapManager &); MapManager& operator=(const MapManager &); - Map* _createBaseMap(uint32 id); - Map* _findMap(uint32 id) const - { - MapMapType::const_iterator iter = i_maps.find(id); - return (iter == i_maps.end() ? NULL : iter->second); - } - ACE_Thread_Mutex Lock; uint32 i_gridCleanUpDelay; MapMapType i_maps; diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index 808d8318ea9..48e662d08bf 100755 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -351,7 +351,7 @@ void FlightPathMovementGenerator::InitEndGridInfo() void FlightPathMovementGenerator::PreloadEndGrid() { // used to preload the final grid where the flightmaster is - Map* endMap = sMapMgr->FindMap(m_endMapId); + Map* endMap = sMapMgr->FindBaseMap(m_endMapId); // Load the grid if (endMap) diff --git a/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp b/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp index 90368ae3011..4e45eb2d6c6 100755 --- a/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp @@ -72,7 +72,7 @@ void WorldSession::HandleMoveWorldportAckOpcode() } // relocate the player to the teleport destination - Map* newMap = sMapMgr->CreateMap(loc.GetMapId(), GetPlayer(), 0); + Map* newMap = sMapMgr->CreateMap(loc.GetMapId(), GetPlayer()); // 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 || !newMap->CanEnter(GetPlayer())) -- cgit v1.2.3