aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Groups
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-01-02 14:19:35 +0100
committerShauren <shauren.trinity@gmail.com>2022-10-04 00:19:38 +0200
commit9b924522d0549dd67b10e2cbdfc20297dd21e182 (patch)
treef0fcdf96902b7c497c1bc65db83621a8dfadf43a /src/server/game/Groups
parenta131542855d23022714a97640be1c8d68a741c31 (diff)
Core/Instances: Delete InstanceSaveMgr and replace most of its uses with new InstanceLockMgr
Diffstat (limited to 'src/server/game/Groups')
-rw-r--r--src/server/game/Groups/Group.cpp230
-rw-r--r--src/server/game/Groups/Group.h24
-rw-r--r--src/server/game/Groups/GroupMgr.cpp47
3 files changed, 2 insertions, 299 deletions
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp
index f8929654908..c799212b059 100644
--- a/src/server/game/Groups/Group.cpp
+++ b/src/server/game/Groups/Group.cpp
@@ -24,7 +24,6 @@
#include "Formulas.h"
#include "GameObject.h"
#include "GroupMgr.h"
-#include "InstanceSaveMgr.h"
#include "Item.h"
#include "LFGMgr.h"
#include "Log.h"
@@ -67,11 +66,6 @@ Group::~Group()
TC_LOG_ERROR("misc", "Group::~Group: battleground group is not linked to the correct battleground.");
}
- // this may unload some instance saves
- for (auto difficultyItr = m_boundInstances.begin(); difficultyItr != m_boundInstances.end(); ++difficultyItr)
- for (auto itr2 = difficultyItr->second.begin(); itr2 != difficultyItr->second.end(); ++itr2)
- itr2->second.save->RemoveGroup(this);
-
// Sub group counters clean up
delete[] m_subGroupsCounts;
}
@@ -694,28 +688,6 @@ void Group::ChangeLeader(ObjectGuid newLeaderGuid, int8 partyIndex)
{
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
- // Remove the groups permanent instance bindings
- for (auto difficultyItr = m_boundInstances.begin(); difficultyItr != m_boundInstances.end(); ++difficultyItr)
- {
- for (auto itr = difficultyItr->second.begin(); itr != difficultyItr->second.end();)
- {
- // Do not unbind saves of instances that already had map created (a newLeader entered)
- // forcing a new instance with another leader requires group disbanding (confirmed on retail)
- if (itr->second.perm && !sMapMgr->FindMap(itr->first, itr->second.save->GetInstanceId()))
- {
- CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_PERM_BINDING);
- stmt->setUInt32(0, m_dbStoreId);
- stmt->setUInt32(1, itr->second.save->GetInstanceId());
- trans->Append(stmt);
-
- itr->second.save->RemoveGroup(this);
- difficultyItr->second.erase(itr++);
- }
- else
- ++itr;
- }
- }
-
// Update the group leader
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GROUP_LEADER);
@@ -1387,174 +1359,8 @@ Difficulty Group::GetDifficultyID(MapEntry const* mapEntry) const
return m_raidDifficulty;
}
-void Group::ResetInstances(uint8 method, bool isRaid, bool isLegacy, Player* SendMsgTo)
-{
- if (isBGGroup() || isBFGroup())
- return;
-
- // method can be INSTANCE_RESET_ALL, INSTANCE_RESET_CHANGE_DIFFICULTY, INSTANCE_RESET_GROUP_DISBAND
-
- // we assume that when the difficulty changes, all instances that can be reset will be
- Difficulty diff = GetDungeonDifficultyID();
- if (isRaid)
- {
- if (!isLegacy)
- diff = GetRaidDifficultyID();
- else
- diff = GetLegacyRaidDifficultyID();
- }
-
- auto difficultyItr = m_boundInstances.find(diff);
- if (difficultyItr == m_boundInstances.end())
- return;
-
- for (auto itr = difficultyItr->second.begin(); itr != difficultyItr->second.end();)
- {
- InstanceSave* instanceSave = itr->second.save;
- MapEntry const* entry = sMapStore.LookupEntry(itr->first);
- if (!entry || entry->IsRaid() != isRaid || (!instanceSave->CanReset() && method != INSTANCE_RESET_GROUP_DISBAND))
- {
- ++itr;
- continue;
- }
-
- if (method == INSTANCE_RESET_ALL)
- {
- // the "reset all instances" method can only reset normal maps
- if (entry->IsRaid() || diff == DIFFICULTY_HEROIC)
- {
- ++itr;
- continue;
- }
- }
-
- bool isEmpty = true;
- // if the map is loaded, reset it
- Map* map = sMapMgr->FindMap(instanceSave->GetMapId(), instanceSave->GetInstanceId());
- if (map && map->IsDungeon() && !(method == INSTANCE_RESET_GROUP_DISBAND && !instanceSave->CanReset()))
- {
- if (instanceSave->CanReset())
- isEmpty = ((InstanceMap*)map)->Reset(method);
- else
- isEmpty = !map->HavePlayers();
- }
-
- if (SendMsgTo)
- {
- if (!isEmpty)
- SendMsgTo->SendResetInstanceFailed(INSTANCE_RESET_FAILED, instanceSave->GetMapId());
- else if (sWorld->getBoolConfig(CONFIG_INSTANCES_RESET_ANNOUNCE))
- {
- if (Group* group = SendMsgTo->GetGroup())
- {
- for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
- if (Player* player = groupRef->GetSource())
- player->SendResetInstanceSuccess(instanceSave->GetMapId());
- }
-
- else
- SendMsgTo->SendResetInstanceSuccess(instanceSave->GetMapId());
- }
- else
- SendMsgTo->SendResetInstanceSuccess(instanceSave->GetMapId());
- }
-
- if (isEmpty || method == INSTANCE_RESET_GROUP_DISBAND || method == INSTANCE_RESET_CHANGE_DIFFICULTY)
- {
- // do not reset the instance, just unbind if others are permanently bound to it
- if (isEmpty && instanceSave->CanReset())
- {
- if (map && map->IsDungeon() && SendMsgTo)
- {
- AreaTriggerStruct const* instanceEntrance = sObjectMgr->GetGoBackTrigger(map->GetId());
-
- if (!instanceEntrance)
- TC_LOG_DEBUG("root", "Instance entrance not found for maps %u", map->GetId());
- else
- {
- WorldSafeLocsEntry const* graveyardLocation = sObjectMgr->GetClosestGraveyard(
- WorldLocation(instanceEntrance->target_mapId, instanceEntrance->target_X, instanceEntrance->target_Y, instanceEntrance->target_Z),
- SendMsgTo->GetTeam(), nullptr);
- uint32 const zoneId = sTerrainMgr.GetZoneId(PhasingHandler::GetEmptyPhaseShift(), graveyardLocation->Loc.GetMapId(),
- graveyardLocation->Loc.GetPositionX(), graveyardLocation->Loc.GetPositionY(), graveyardLocation->Loc.GetPositionZ());
-
- for (MemberSlot const& member : GetMemberSlots())
- {
- if (!ObjectAccessor::FindConnectedPlayer(member.guid))
- {
- CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHARACTER_POSITION_BY_MAPID);
-
- stmt->setFloat(0, graveyardLocation->Loc.GetPositionX());
- stmt->setFloat(1, graveyardLocation->Loc.GetPositionY());
- stmt->setFloat(2, graveyardLocation->Loc.GetPositionZ());
- stmt->setFloat(3, instanceEntrance->target_Orientation);
- stmt->setUInt32(4, graveyardLocation->Loc.GetMapId());
- stmt->setUInt32(5, zoneId);
- stmt->setUInt64(6, member.guid.GetCounter());
- stmt->setUInt32(7, map->GetId());
-
- CharacterDatabase.Execute(stmt);
- }
- }
- }
- }
-
- instanceSave->DeleteFromDB();
- }
- else
- {
- CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE);
-
- stmt->setUInt32(0, instanceSave->GetInstanceId());
-
- CharacterDatabase.Execute(stmt);
- }
-
- itr = difficultyItr->second.erase(itr);
- // this unloads the instance save unless online players are bound to it
- // (eg. permanent binds or GM solo binds)
- instanceSave->RemoveGroup(this);
- }
- else
- ++itr;
- }
-}
-
-InstanceGroupBind* Group::GetBoundInstance(Player* player)
-{
- uint32 mapid = player->GetMapId();
- MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
- return GetBoundInstance(mapEntry);
-}
-
-InstanceGroupBind* Group::GetBoundInstance(Map* aMap)
-{
- return GetBoundInstance(aMap->GetEntry());
-}
-
-InstanceGroupBind* Group::GetBoundInstance(MapEntry const* mapEntry)
+void Group::ResetInstances(InstanceResetMethod /*method*/, bool /*isRaid*/, bool /*isLegacy*/, Player* /*SendMsgTo*/)
{
- if (!mapEntry || !mapEntry->IsDungeon())
- return nullptr;
-
- Difficulty difficulty = GetDifficultyID(mapEntry);
- return GetBoundInstance(difficulty, mapEntry->ID);
-}
-
-InstanceGroupBind* Group::GetBoundInstance(Difficulty difficulty, uint32 mapId)
-{
- // some instances only have one difficulty
- sDB2Manager.GetDownscaledMapDifficultyData(mapId, difficulty);
-
- auto difficultyItr = m_boundInstances.find(difficulty);
- if (difficultyItr == m_boundInstances.end())
- return nullptr;
-
- auto itr = difficultyItr->second.find(mapId);
- if (itr != difficultyItr->second.end())
- return &itr->second;
- else
- return nullptr;
}
void Group::LinkOwnedInstance(GroupInstanceReference* ref)
@@ -1562,30 +1368,6 @@ void Group::LinkOwnedInstance(GroupInstanceReference* ref)
m_ownedInstancesMgr.insertLast(ref);
}
-void Group::UnbindInstance(uint32 mapid, uint8 difficulty, bool unload)
-{
- auto difficultyItr = m_boundInstances.find(Difficulty(difficulty));
- if (difficultyItr == m_boundInstances.end())
- return;
-
- auto itr = difficultyItr->second.find(mapid);
- if (itr != difficultyItr->second.end())
- {
- if (!unload)
- {
- CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_BY_GUID);
-
- stmt->setUInt32(0, m_dbStoreId);
- stmt->setUInt32(1, itr->second.save->GetInstanceId());
-
- CharacterDatabase.Execute(stmt);
- }
-
- itr->second.save->RemoveGroup(this); // save can become invalid
- difficultyItr->second.erase(itr);
- }
-}
-
void Group::_homebindIfInstance(Player* player)
{
if (player && !player->IsGameMaster() && sMapStore.LookupEntry(player->GetMapId())->IsDungeon())
@@ -1983,16 +1765,6 @@ void Group::DelinkMember(ObjectGuid guid)
}
}
-Group::BoundInstancesMap::iterator Group::GetBoundInstances(Difficulty difficulty)
-{
- return m_boundInstances.find(difficulty);
-}
-
-Group::BoundInstancesMap::iterator Group::GetBoundInstanceEnd()
-{
- return m_boundInstances.end();
-}
-
void Group::_initRaidSubGroupsCounter()
{
// Sub group counters initialization
diff --git a/src/server/game/Groups/Group.h b/src/server/game/Groups/Group.h
index 7860a81fd5c..58b27fb459b 100644
--- a/src/server/game/Groups/Group.h
+++ b/src/server/game/Groups/Group.h
@@ -31,7 +31,6 @@
class Battlefield;
class Battleground;
class Creature;
-class InstanceSave;
class Map;
class Player;
class Unit;
@@ -155,15 +154,6 @@ enum GroupUpdatePetFlags
GROUP_UPDATE_FLAG_PET_CUR_HP | GROUP_UPDATE_FLAG_PET_MAX_HP | GROUP_UPDATE_FLAG_PET_AURAS // all pet flags
};
-struct InstanceGroupBind
-{
- InstanceSave* save;
- bool perm;
- /* permanent InstanceGroupBinds exist if the leader has a permanent
- PlayerInstanceBind for the same instance. */
- InstanceGroupBind() : save(nullptr), perm(false) { }
-};
-
struct RaidMarker
{
WorldLocation Location;
@@ -195,7 +185,6 @@ class TC_GAME_API Group
typedef std::list<MemberSlot> MemberSlotList;
typedef MemberSlotList::const_iterator member_citerator;
- typedef std::unordered_map<Difficulty, std::unordered_map<uint32 /*mapId*/, InstanceGroupBind>> BoundInstancesMap;
protected:
typedef MemberSlotList::iterator member_witerator;
typedef std::set<Player*> InvitesList;
@@ -315,7 +304,7 @@ class TC_GAME_API Group
Difficulty GetDungeonDifficultyID() const { return m_dungeonDifficulty; }
Difficulty GetRaidDifficultyID() const { return m_raidDifficulty; }
Difficulty GetLegacyRaidDifficultyID() const { return m_legacyRaidDifficulty; }
- void ResetInstances(uint8 method, bool isRaid, bool isLegacy, Player* SendMsgTo);
+ void ResetInstances(InstanceResetMethod method, bool isRaid, bool isLegacy, Player* SendMsgTo);
// -no description-
//void SendInit(WorldSession* session);
@@ -345,8 +334,6 @@ class TC_GAME_API Group
void LinkMember(GroupReference* pRef);
void DelinkMember(ObjectGuid guid);
- uint32 GetInstanceId(MapEntry const* mapEntry) const { return 0; }
- InstanceGroupBind* BindToInstance(InstanceSave* save, bool permanent, bool load = false);
ObjectGuid GetRecentInstanceOwner(uint32 mapId) const
{
auto itr = m_recentInstances.find(mapId);
@@ -366,14 +353,6 @@ class TC_GAME_API Group
void LinkOwnedInstance(GroupInstanceReference* ref);
- void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload = false);
- InstanceGroupBind* GetBoundInstance(Player* player);
- InstanceGroupBind* GetBoundInstance(Map* aMap);
- InstanceGroupBind* GetBoundInstance(MapEntry const* mapEntry);
- InstanceGroupBind* GetBoundInstance(Difficulty difficulty, uint32 mapId);
- BoundInstancesMap::iterator GetBoundInstances(Difficulty difficulty);
- BoundInstancesMap::iterator GetBoundInstanceEnd();
-
void StartLeaderOfflineTimer();
void StopLeaderOfflineTimer();
void SelectNewPartyOrRaidLeader();
@@ -410,7 +389,6 @@ class TC_GAME_API Group
ItemQualities m_lootThreshold;
ObjectGuid m_looterGuid;
ObjectGuid m_masterLooterGuid;
- BoundInstancesMap m_boundInstances;
std::unordered_map<uint32 /*mapId*/, std::pair<ObjectGuid /*instanceOwner*/, uint32 /*instanceId*/>> m_recentInstances;
GroupInstanceRefManager m_ownedInstancesMgr;
uint8* m_subGroupsCounts;
diff --git a/src/server/game/Groups/GroupMgr.cpp b/src/server/game/Groups/GroupMgr.cpp
index c8ed49365ad..69fbe8e4d21 100644
--- a/src/server/game/Groups/GroupMgr.cpp
+++ b/src/server/game/Groups/GroupMgr.cpp
@@ -18,9 +18,7 @@
#include "GroupMgr.h"
#include "Common.h"
#include "DatabaseEnv.h"
-#include "DB2Stores.h"
#include "Group.h"
-#include "InstanceSaveMgr.h"
#include "Log.h"
#include "World.h"
@@ -205,49 +203,4 @@ void GroupMgr::LoadGroups()
TC_LOG_INFO("server.loading", ">> Loaded %u group members in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
-
- TC_LOG_INFO("server.loading", "Loading Group instance saves...");
- {
- uint32 oldMSTime = getMSTime();
-
- // 0 1 2 3 4 5 6
- QueryResult result = CharacterDatabase.Query("SELECT gi.guid, i.map, gi.instance, gi.permanent, i.difficulty, i.resettime, i.entranceId, "
- // 7
- "(SELECT COUNT(1) FROM character_instance ci LEFT JOIN `groups` g ON ci.guid = g.leaderGuid WHERE ci.instance = gi.instance AND ci.permanent = 1 LIMIT 1) "
- "FROM group_instance gi LEFT JOIN instance i ON gi.instance = i.id ORDER BY guid");
-
- if (!result)
- {
- TC_LOG_INFO("server.loading", ">> Loaded 0 group-instance saves. DB table `group_instance` is empty!");
- return;
- }
-
- uint32 count = 0;
- do
- {
- Field* fields = result->Fetch();
- Group* group = GetGroupByDbStoreId(fields[0].GetUInt32());
- // group will never be NULL (we have run consistency sql's before loading)
- ASSERT(group);
-
- MapEntry const* mapEntry = sMapStore.LookupEntry(fields[1].GetUInt16());
- if (!mapEntry || !mapEntry->IsDungeon())
- {
- TC_LOG_ERROR("sql.sql", "Incorrect entry in group_instance table : no dungeon map %d", fields[1].GetUInt16());
- continue;
- }
-
- uint32 diff = fields[4].GetUInt8();
- DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(diff);
- if (!difficultyEntry || difficultyEntry->InstanceType != mapEntry->InstanceType)
- continue;
-
- InstanceSave* save = sInstanceSaveMgr->AddInstanceSave(mapEntry->ID, fields[2].GetUInt32(), Difficulty(diff), fields[5].GetInt64(), fields[6].GetUInt32(), fields[7].GetUInt64() == 0, true);
- group->BindToInstance(save, fields[3].GetBool(), true);
- ++count;
- }
- while (result->NextRow());
-
- TC_LOG_INFO("server.loading", ">> Loaded %u group-instance saves in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
- }
}