AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
InstanceSaveMgr Class Reference

#include "InstanceSaveMgr.h"

Classes

struct  InstResetEvent
 

Public Types

typedef std::unordered_map< uint32, InstanceSave * > InstanceSaveHashMap
 
typedef std::multimap< time_t, InstResetEventResetTimeQueue
 

Public Member Functions

void LoadInstances ()
 
void LoadResetTimes ()
 
void LoadInstanceSaves ()
 
void LoadCharacterBinds ()
 
time_t GetResetTimeFor (uint32 mapid, Difficulty d) const
 
time_t GetExtendedResetTimeFor (uint32 mapid, Difficulty d) const
 
void SetResetTimeFor (uint32 mapid, Difficulty d, time_t t)
 
void SetExtendedResetTimeFor (uint32 mapid, Difficulty d, time_t t)
 
ResetTimeByMapDifficultyMap const & GetResetTimeMap () const
 
void ScheduleReset (time_t time, InstResetEvent event)
 
void Update ()
 
InstanceSaveAddInstanceSave (uint32 mapId, uint32 instanceId, Difficulty difficulty, bool startup=false)
 
bool DeleteInstanceSaveIfNeeded (uint32 InstanceId, bool skipMapCheck)
 
bool DeleteInstanceSaveIfNeeded (InstanceSave *save, bool skipMapCheck, bool deleteSave=true)
 
InstanceSaveGetInstanceSave (uint32 InstanceId)
 
InstancePlayerBindPlayerBindToInstance (ObjectGuid guid, InstanceSave *save, bool permanent, Player *player=nullptr)
 
void PlayerUnbindInstance (ObjectGuid guid, uint32 mapid, Difficulty difficulty, bool deleteFromDB, Player *player=nullptr)
 
void PlayerUnbindInstanceNotExtended (ObjectGuid guid, uint32 mapid, Difficulty difficulty, Player *player=nullptr)
 
InstancePlayerBindPlayerGetBoundInstance (ObjectGuid guid, uint32 mapid, Difficulty difficulty)
 
bool PlayerIsPermBoundToInstance (ObjectGuid guid, uint32 mapid, Difficulty difficulty)
 
BoundInstancesMap const & PlayerGetBoundInstances (ObjectGuid guid, Difficulty difficulty)
 
void PlayerCreateBoundInstancesMaps (ObjectGuid guid)
 
InstanceSavePlayerGetInstanceSave (ObjectGuid guid, uint32 mapid, Difficulty difficulty)
 
uint32 PlayerGetDestinationInstanceId (Player *player, uint32 mapid, Difficulty difficulty)
 
void CopyBinds (ObjectGuid from, ObjectGuid to, Player *toPlr=nullptr)
 
void UnbindAllFor (InstanceSave *save)
 
void SanitizeInstanceSavedData ()
 
void DeleteInstanceSavedData (uint32 instanceId)
 

Static Public Member Functions

static InstanceSaveMgrinstance ()
 

Static Protected Attributes

static uint16 ResetTimeDelay [] = {3600, 900, 300, 60, 0}
 
static PlayerBindStorage playerBindStorage
 
static BoundInstancesMap emptyBoundInstancesMap
 

Private Member Functions

 InstanceSaveMgr ()=default
 
 ~InstanceSaveMgr ()
 
void _ResetOrWarnAll (uint32 mapid, Difficulty difficulty, bool warn, time_t resetTime)
 
void _ResetSave (InstanceSaveHashMap::iterator &itr)
 

Private Attributes

bool lock_instLists {false}
 
InstanceSaveHashMap m_instanceSaveById
 
ResetTimeByMapDifficultyMap m_resetTimeByMapDifficulty
 
ResetTimeByMapDifficultyMap m_resetExtendedTimeByMapDifficulty
 
ResetTimeQueue m_resetTimeQueue
 

Friends

class InstanceSave
 

Detailed Description

Member Typedef Documentation

◆ InstanceSaveHashMap

◆ ResetTimeQueue

typedef std::multimap<time_t , InstResetEvent> InstanceSaveMgr::ResetTimeQueue

Constructor & Destructor Documentation

◆ InstanceSaveMgr()

InstanceSaveMgr::InstanceSaveMgr ( )
privatedefault

◆ ~InstanceSaveMgr()

InstanceSaveMgr::~InstanceSaveMgr ( )
private
42{
43 lock_instLists = true;
44 // pussywizard: crashes on calling function in destructor (PlayerUnbindInstance), completely not needed anyway
45 /*for (InstanceSaveHashMap::iterator itr = m_instanceSaveById.begin(); itr != m_instanceSaveById.end(); ++itr)
46 {
47 InstanceSave* save = itr->second;
48
49 InstanceSave::PlayerListType &pList = save->m_playerList;
50 while (!pList.empty())
51 PlayerUnbindInstance(*(pList.begin()), save->GetMapId(), save->GetDifficulty(), false);
52
53 delete save;
54 }*/
55}
bool lock_instLists
Definition InstanceSaveMgr.h:195

References lock_instLists.

Member Function Documentation

◆ _ResetOrWarnAll()

void InstanceSaveMgr::_ResetOrWarnAll ( uint32  mapid,
Difficulty  difficulty,
bool  warn,
time_t  resetTime 
)
private
562{
563 // global reset for all instances of the given map
564 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
565 if (!mapEntry->Instanceable())
566 return;
567
568 time_t now = GameTime::GetGameTime().count();
569
570 if (!warn)
571 {
572 MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
573 if (!mapDiff || !mapDiff->resetTime)
574 {
575 LOG_ERROR("instance.save", "InstanceSaveMgr::ResetOrWarnAll: not valid difficulty or no reset delay for map {}", mapid);
576 return;
577 }
578
579 // calculate the next reset time
580 uint32 diff = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR) * HOUR;
581
582 uint32 period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / DAY) * DAY);
583 if (period < DAY)
584 period = DAY;
585
586 uint32 next_reset = uint32(((resetTime + MINUTE) / DAY * DAY) + period + diff);
587 SetResetTimeFor(mapid, difficulty, next_reset);
588 SetExtendedResetTimeFor(mapid, difficulty, next_reset + period);
589 ScheduleReset(time_t(next_reset - 3600), InstResetEvent(1, mapid, difficulty));
590
591 // update it in the DB
593 stmt->SetData(0, next_reset);
594 stmt->SetData(1, uint16(mapid));
595 stmt->SetData(2, uint8(difficulty));
596 CharacterDatabase.Execute(stmt);
597
598 // remove all binds to instances of the given map and delete from db (delete per instance id, no mass deletion!)
599 // do this after new reset time is calculated
600 for (InstanceSaveHashMap::iterator itr = m_instanceSaveById.begin(), itr2; itr != m_instanceSaveById.end(); )
601 {
602 itr2 = itr++;
603 if (itr2->second->GetMapId() == mapid && itr2->second->GetDifficulty() == difficulty)
604 _ResetSave(itr2);
605 }
606 }
607
608 // now loop all existing maps to warn / reset
609 Map const* map = sMapMgr->CreateBaseMap(mapid);
610 MapInstanced::InstancedMaps& instMaps = ((MapInstanced*)map)->GetInstancedMaps();
611 MapInstanced::InstancedMaps::iterator mitr;
612 uint32 timeLeft;
613
614 for (mitr = instMaps.begin(); mitr != instMaps.end(); ++mitr)
615 {
616 Map* map2 = mitr->second;
617 if (!map2->IsDungeon() || map2->GetDifficulty() != difficulty)
618 continue;
619
620 if (warn)
621 {
622 if (now >= resetTime)
623 timeLeft = 0;
624 else
625 timeLeft = uint32(resetTime - now);
626
627 map2->ToInstanceMap()->SendResetWarnings(timeLeft);
628 }
629 else
630 {
632 map2->ToInstanceMap()->Reset(INSTANCE_RESET_GLOBAL, (save ? & (save->m_playerList) : nullptr));
633 }
634 }
635}
@ CHAR_UPD_GLOBAL_INSTANCE_RESETTIME
Definition CharacterDatabase.h:303
constexpr auto DAY
Definition Common.h:49
constexpr auto HOUR
Definition Common.h:48
constexpr auto MINUTE
Definition Common.h:47
MapDifficulty const * GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
Definition DBCStores.cpp:761
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
std::uint16_t uint16
Definition Define.h:108
@ CONFIG_INSTANCE_RESET_TIME_HOUR
Definition IWorld.h:248
@ RATE_INSTANCE_RESET_TIME
Definition IWorld.h:519
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
#define sMapMgr
Definition MapMgr.h:220
@ INSTANCE_RESET_GLOBAL
Definition Map.h:646
void SendResetWarnings(uint32 timeLeft) const
Definition Map.cpp:2387
bool Reset(uint8 method, GuidList *globalSkipList=nullptr)
Definition Map.cpp:2289
InstanceSave * GetInstanceSave(uint32 InstanceId)
Definition InstanceSaveMgr.cpp:108
void ScheduleReset(time_t time, InstResetEvent event)
Definition InstanceSaveMgr.cpp:457
void _ResetSave(InstanceSaveHashMap::iterator &itr)
Definition InstanceSaveMgr.cpp:509
void SetResetTimeFor(uint32 mapid, Difficulty d, time_t t)
Definition InstanceSaveMgr.h:148
InstanceSaveHashMap m_instanceSaveById
Definition InstanceSaveMgr.h:196
void SetExtendedResetTimeFor(uint32 mapid, Difficulty d, time_t t)
Definition InstanceSaveMgr.h:153
Definition InstanceSaveMgr.h:56
GuidList m_playerList
Definition InstanceSaveMgr.h:91
Definition MapInstanced.h:26
std::unordered_map< uint32, Map * > InstancedMaps
Definition MapInstanced.h:29
Definition Map.h:156
bool IsDungeon() const
Definition Map.h:295
InstanceMap * ToInstanceMap()
Definition Map.h:393
Difficulty GetDifficulty() const
Definition Map.h:290
uint32 GetInstanceId() const
Definition Map.h:266
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
#define sWorld
Definition World.h:363
Seconds GetGameTime()
Definition GameTime.cpp:38
Definition DBCStructure.h:2221
uint32 resetTime
Definition DBCStructure.h:2225
Definition DBCStructure.h:1324
bool Instanceable() const
Definition DBCStructure.h:1352

References _ResetSave(), CHAR_UPD_GLOBAL_INSTANCE_RESETTIME, CharacterDatabase, CONFIG_INSTANCE_RESET_TIME_HOUR, DAY, Map::GetDifficulty(), GameTime::GetGameTime(), Map::GetInstanceId(), GetInstanceSave(), GetMapDifficultyData(), HOUR, INSTANCE_RESET_GLOBAL, MapEntry::Instanceable(), Map::IsDungeon(), LOG_ERROR, m_instanceSaveById, InstanceSave::m_playerList, MINUTE, RATE_INSTANCE_RESET_TIME, InstanceMap::Reset(), MapDifficulty::resetTime, ScheduleReset(), InstanceMap::SendResetWarnings(), PreparedStatementBase::SetData(), SetExtendedResetTimeFor(), SetResetTimeFor(), sMapMgr, sMapStore, sWorld, and Map::ToInstanceMap().

Referenced by Update().

◆ _ResetSave()

void InstanceSaveMgr::_ResetSave ( InstanceSaveHashMap::iterator &  itr)
private
510{
511 lock_instLists = true;
512
513 GuidList& pList = itr->second->m_playerList;
514 for (GuidList::iterator iter = pList.begin(), iter2; iter != pList.end(); )
515 {
516 iter2 = iter++;
517 PlayerUnbindInstanceNotExtended(*iter2, itr->second->GetMapId(), itr->second->GetDifficulty(), ObjectAccessor::FindConnectedPlayer(*iter2));
518 }
519
520 // delete stuff if no players left (noone extended id)
521 if (pList.empty())
522 {
523 // delete character_instance per id, delete instance per id
525 stmt->SetData(0, itr->second->GetInstanceId());
526 CharacterDatabase.Execute(stmt);
527 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INSTANCE_BY_INSTANCE);
528 stmt->SetData(0, itr->second->GetInstanceId());
529 CharacterDatabase.Execute(stmt);
530 DeleteInstanceSavedData(itr->second->GetInstanceId());
531
532 // clear respawn times if the map is already unloaded and won't do it by itself
533 if (!sMapMgr->FindMap(itr->second->GetMapId(), itr->second->GetInstanceId()))
534 Map::DeleteRespawnTimesInDB(itr->second->GetMapId(), itr->second->GetInstanceId());
535
536 sScriptMgr->OnInstanceIdRemoved(itr->second->GetInstanceId());
537
538 delete itr->second;
539 m_instanceSaveById.erase(itr);
540 }
541 else
542 {
543 // delete character_instance per id where extended = 0, transtaction with set extended = 0, transaction is used to avoid mysql thread races
544 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
546 stmt->SetData(0, itr->second->GetInstanceId());
547 trans->Append(stmt);
549 stmt->SetData(0, itr->second->GetInstanceId());
550 trans->Append(stmt);
551 CharacterDatabase.CommitTransaction(trans);
552
553 // update reset time and extended reset time for instance save
554 itr->second->SetResetTime(GetResetTimeFor(itr->second->GetMapId(), itr->second->GetDifficulty()));
555 itr->second->SetExtendedResetTime(GetExtendedResetTimeFor(itr->second->GetMapId(), itr->second->GetDifficulty()));
556 }
557
558 lock_instLists = false;
559}
@ CHAR_UPD_CHAR_INSTANCE_SET_NOT_EXTENDED
Definition CharacterDatabase.h:310
@ CHAR_DEL_INSTANCE_BY_INSTANCE
Definition CharacterDatabase.h:381
@ CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_NOT_EXTENDED
Definition CharacterDatabase.h:309
@ CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE
Definition CharacterDatabase.h:308
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition DatabaseEnvFwd.h:69
std::list< ObjectGuid > GuidList
Definition ObjectGuid.h:254
#define sScriptMgr
Definition ScriptMgr.h:727
void DeleteInstanceSavedData(uint32 instanceId)
Definition InstanceSaveMgr.cpp:250
time_t GetResetTimeFor(uint32 mapid, Difficulty d) const
Definition InstanceSaveMgr.h:136
time_t GetExtendedResetTimeFor(uint32 mapid, Difficulty d) const
Definition InstanceSaveMgr.h:142
void PlayerUnbindInstanceNotExtended(ObjectGuid guid, uint32 mapid, Difficulty difficulty, Player *player=nullptr)
Definition InstanceSaveMgr.cpp:732
static void DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId)
Definition Map.cpp:2642
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:257

References CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE, CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_NOT_EXTENDED, CHAR_DEL_INSTANCE_BY_INSTANCE, CHAR_UPD_CHAR_INSTANCE_SET_NOT_EXTENDED, CharacterDatabase, DeleteInstanceSavedData(), Map::DeleteRespawnTimesInDB(), ObjectAccessor::FindConnectedPlayer(), GetExtendedResetTimeFor(), GetResetTimeFor(), lock_instLists, m_instanceSaveById, PlayerUnbindInstanceNotExtended(), PreparedStatementBase::SetData(), sMapMgr, and sScriptMgr.

Referenced by _ResetOrWarnAll().

◆ AddInstanceSave()

InstanceSave * InstanceSaveMgr::AddInstanceSave ( uint32  mapId,
uint32  instanceId,
Difficulty  difficulty,
bool  startup = false 
)
67{
68 ASSERT(!GetInstanceSave(instanceId));
69
70 MapEntry const* entry = sMapStore.LookupEntry(mapId);
71 if (!entry)
72 {
73 LOG_ERROR("instance.save", "InstanceSaveMgr::AddInstanceSave: wrong mapid = {}, instanceid = {}!", mapId, instanceId);
74 return nullptr;
75 }
76
77 if (instanceId == 0)
78 {
79 LOG_ERROR("instance.save", "InstanceSaveMgr::AddInstanceSave: mapid = {}, wrong instanceid = {}!", mapId, instanceId);
80 return nullptr;
81 }
82
83 if (difficulty >= (entry->IsRaid() ? MAX_RAID_DIFFICULTY : MAX_DUNGEON_DIFFICULTY))
84 {
85 LOG_ERROR("instance.save", "InstanceSaveMgr::AddInstanceSave: mapid = {}, instanceid = {}, wrong difficulty {}!", mapId, instanceId, difficulty);
86 return nullptr;
87 }
88
89 time_t resetTime, extendedResetTime;
90 if (entry->map_type == MAP_RAID || difficulty > DUNGEON_DIFFICULTY_NORMAL)
91 {
92 resetTime = GetResetTimeFor(mapId, difficulty);
93 extendedResetTime = GetExtendedResetTimeFor(mapId, difficulty);
94 }
95 else
96 {
97 resetTime = GameTime::GetGameTime().count() + static_cast<long long>(3) * DAY; // normals expire after 3 days even if someone is still bound to them, cleared on startup
98 extendedResetTime = 0;
99 }
100 InstanceSave* save = new InstanceSave(mapId, instanceId, difficulty, resetTime, extendedResetTime);
101 if (!startup)
102 save->InsertToDB();
103
104 m_instanceSaveById[instanceId] = save;
105 return save;
106}
#define MAX_RAID_DIFFICULTY
Definition DBCEnums.h:282
@ MAP_RAID
Definition DBCEnums.h:348
@ DUNGEON_DIFFICULTY_NORMAL
Definition DBCEnums.h:269
#define MAX_DUNGEON_DIFFICULTY
Definition DBCEnums.h:281
#define ASSERT
Definition Errors.h:68
friend class InstanceSave
Definition InstanceSaveMgr.h:108
void InsertToDB()
Definition InstanceSaveMgr.cpp:165
bool IsRaid() const
Definition DBCStructure.h:1353
uint32 map_type
Definition DBCStructure.h:1327

References ASSERT, DAY, DUNGEON_DIFFICULTY_NORMAL, GetExtendedResetTimeFor(), GameTime::GetGameTime(), GetInstanceSave(), GetResetTimeFor(), InstanceSave::InsertToDB(), InstanceSave, MapEntry::IsRaid(), LOG_ERROR, m_instanceSaveById, MAP_RAID, MapEntry::map_type, MAX_DUNGEON_DIFFICULTY, MAX_RAID_DIFFICULTY, and sMapStore.

Referenced by LoadInstanceSaves().

◆ CopyBinds()

void InstanceSaveMgr::CopyBinds ( ObjectGuid  from,
ObjectGuid  to,
Player toPlr = nullptr 
)
820{
821 if (from == to)
822 return;
823
824 for (uint8 d = 0; d < MAX_DIFFICULTY; ++d)
825 {
827 for (BoundInstancesMap::const_iterator itr = bi.begin(); itr != bi.end(); ++itr)
828 if (!PlayerGetBoundInstance(to, itr->first, Difficulty(d)))
829 PlayerBindToInstance(to, itr->second.save, false, toPlr);
830 }
831}
Difficulty
Definition DBCEnums.h:266
#define MAX_DIFFICULTY
Definition DBCEnums.h:283
std::unordered_map< uint32, InstancePlayerBind > BoundInstancesMap
Definition InstanceSaveMgr.h:46
InstancePlayerBind * PlayerBindToInstance(ObjectGuid guid, InstanceSave *save, bool permanent, Player *player=nullptr)
Definition InstanceSaveMgr.cpp:637
BoundInstancesMap const & PlayerGetBoundInstances(ObjectGuid guid, Difficulty difficulty)
Definition InstanceSaveMgr.cpp:782
InstancePlayerBind * PlayerGetBoundInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty)
Definition InstanceSaveMgr.cpp:752

References MAX_DIFFICULTY, PlayerBindToInstance(), PlayerGetBoundInstance(), and PlayerGetBoundInstances().

◆ DeleteInstanceSavedData()

void InstanceSaveMgr::DeleteInstanceSavedData ( uint32  instanceId)
251{
252 if (instanceId)
253 {
255 stmt->SetData(0, instanceId);
256 CharacterDatabase.Execute(stmt);
257 }
258}
@ CHAR_DELETE_INSTANCE_SAVED_DATA
Definition CharacterDatabase.h:528

References CHAR_DELETE_INSTANCE_SAVED_DATA, CharacterDatabase, and PreparedStatementBase::SetData().

Referenced by _ResetSave(), and DeleteInstanceSaveIfNeeded().

◆ DeleteInstanceSaveIfNeeded() [1/2]

bool InstanceSaveMgr::DeleteInstanceSaveIfNeeded ( InstanceSave save,
bool  skipMapCheck,
bool  deleteSave = true 
)
120{
121 // pussywizard: save is removed only when there are no more players bound AND the map doesn't exist
122 // pussywizard: this function is called when unbinding a player and when unloading a map
123 if (!lock_instLists && save && save->m_playerList.empty() && (skipMapCheck || !sMapMgr->FindMap(save->GetMapId(), save->GetInstanceId())))
124 {
125 // delete save from storage:
126 InstanceSaveHashMap::iterator itr = m_instanceSaveById.find(save->GetInstanceId());
127 ASSERT(itr != m_instanceSaveById.end() && itr->second == save);
128 m_instanceSaveById.erase(itr);
129
130 // delete save from db:
131 // character_instance is deleted when unbinding a certain player
133 stmt->SetData(0, save->GetInstanceId());
134 CharacterDatabase.Execute(stmt);
136
137 // clear respawn times (if map is loaded do it just to be sure, if already unloaded it won't do it by itself)
139
140 sScriptMgr->OnInstanceIdRemoved(save->GetInstanceId());
141
142 if (deleteSave)
143 {
144 delete save;
145 }
146
147 return true;
148 }
149 return false;
150}
uint32 GetInstanceId() const
Definition InstanceSaveMgr.h:61
uint32 GetMapId() const
Definition InstanceSaveMgr.h:62

References ASSERT, CHAR_DEL_INSTANCE_BY_INSTANCE, CharacterDatabase, DeleteInstanceSavedData(), Map::DeleteRespawnTimesInDB(), InstanceSave::GetInstanceId(), InstanceSave::GetMapId(), lock_instLists, m_instanceSaveById, InstanceSave::m_playerList, PreparedStatementBase::SetData(), sMapMgr, and sScriptMgr.

◆ DeleteInstanceSaveIfNeeded() [2/2]

bool InstanceSaveMgr::DeleteInstanceSaveIfNeeded ( uint32  InstanceId,
bool  skipMapCheck 
)
115{
116 return DeleteInstanceSaveIfNeeded(GetInstanceSave(InstanceId), skipMapCheck);
117}
bool DeleteInstanceSaveIfNeeded(uint32 InstanceId, bool skipMapCheck)
Definition InstanceSaveMgr.cpp:114

References DeleteInstanceSaveIfNeeded(), and GetInstanceSave().

Referenced by DeleteInstanceSaveIfNeeded(), and InstanceSave::RemovePlayer().

◆ GetExtendedResetTimeFor()

time_t InstanceSaveMgr::GetExtendedResetTimeFor ( uint32  mapid,
Difficulty  d 
) const
inline
143 {
144 ResetTimeByMapDifficultyMap::const_iterator itr = m_resetExtendedTimeByMapDifficulty.find(MAKE_PAIR32(mapid, d));
145 return itr != m_resetExtendedTimeByMapDifficulty.end() ? itr->second : 0;
146 }
uint32 MAKE_PAIR32(uint16 l, uint16 h)
Definition ObjectDefines.h:87
ResetTimeByMapDifficultyMap m_resetExtendedTimeByMapDifficulty
Definition InstanceSaveMgr.h:198

References m_resetExtendedTimeByMapDifficulty, and MAKE_PAIR32().

Referenced by _ResetSave(), and AddInstanceSave().

◆ GetInstanceSave()

InstanceSave * InstanceSaveMgr::GetInstanceSave ( uint32  InstanceId)
109{
110 InstanceSaveHashMap::iterator itr = m_instanceSaveById.find(InstanceId);
111 return itr != m_instanceSaveById.end() ? itr->second : nullptr;
112}

References m_instanceSaveById.

Referenced by _ResetOrWarnAll(), AddInstanceSave(), DeleteInstanceSaveIfNeeded(), and LoadCharacterBinds().

◆ GetResetTimeFor()

time_t InstanceSaveMgr::GetResetTimeFor ( uint32  mapid,
Difficulty  d 
) const
inline
137 {
138 ResetTimeByMapDifficultyMap::const_iterator itr = m_resetTimeByMapDifficulty.find(MAKE_PAIR32(mapid, d));
139 return itr != m_resetTimeByMapDifficulty.end() ? itr->second : 0;
140 }
ResetTimeByMapDifficultyMap m_resetTimeByMapDifficulty
Definition InstanceSaveMgr.h:197

References m_resetTimeByMapDifficulty, and MAKE_PAIR32().

Referenced by _ResetSave(), AddInstanceSave(), LoadResetTimes(), and Update().

◆ GetResetTimeMap()

ResetTimeByMapDifficultyMap const & InstanceSaveMgr::GetResetTimeMap ( ) const
inline
159 {
161 }

References m_resetTimeByMapDifficulty.

◆ instance()

InstanceSaveMgr * InstanceSaveMgr::instance ( )
static
58{
60 return &instance;
61}
Definition InstanceSaveMgr.h:107
static InstanceSaveMgr * instance()
Definition InstanceSaveMgr.cpp:57

References instance().

Referenced by instance().

◆ LoadCharacterBinds()

void InstanceSaveMgr::LoadCharacterBinds ( )
406{
407 lock_instLists = true;
408
409 QueryResult result = CharacterDatabase.Query("SELECT guid, instance, permanent, extended FROM character_instance");
410 if (result)
411 {
412 do
413 {
414 Field* fields = result->Fetch();
415
416 ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>(fields[0].Get<uint32>());
417 uint32 instanceId = fields[1].Get<uint32>();
418 bool perm = fields[2].Get<bool>();
419 bool extended = fields[3].Get<bool>();
420
421 if (InstanceSave* save = GetInstanceSave(instanceId))
422 {
424 InstancePlayerBind& bind = playerBindStorage[guid]->m[save->GetDifficulty()][save->GetMapId()];
425 if (bind.save) // pussywizard: another bind for the same map and difficulty! may happen because of mysql thread races
426 {
427 if (bind.perm) // already loaded perm -> delete currently checked one from db
428 {
430 stmt->SetData(0, guid.GetCounter());
431 stmt->SetData(1, instanceId);
432 CharacterDatabase.Execute(stmt);
433 continue;
434 }
435 else // override temp bind by newest one
436 {
438 stmt->SetData(0, guid.GetCounter());
439 stmt->SetData(1, bind.save->GetInstanceId());
440 CharacterDatabase.Execute(stmt);
441 bind.save->RemovePlayer(guid, this);
442 }
443 }
444 bind.save = save;
445 bind.perm = perm;
446 bind.extended = extended;
447 save->AddPlayer(guid);
448 if (perm)
449 save->SetCanReset(false);
450 }
451 } while (result->NextRow());
452 }
453
454 lock_instLists = false;
455}
@ CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_GUID
Definition CharacterDatabase.h:311
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
void PlayerCreateBoundInstancesMaps(ObjectGuid guid)
Definition InstanceSaveMgr.cpp:790
static PlayerBindStorage playerBindStorage
Definition InstanceSaveMgr.h:189
bool RemovePlayer(ObjectGuid guid, InstanceSaveMgr *ism)
Definition InstanceSaveMgr.cpp:224
Definition ObjectGuid.h:118
LowType GetCounter() const
Definition ObjectGuid.h:145
Definition InstanceSaveMgr.h:39
InstanceSave * save
Definition InstanceSaveMgr.h:40
bool extended
Definition InstanceSaveMgr.h:42
bool perm
Definition InstanceSaveMgr.h:41

References CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_GUID, CharacterDatabase, InstancePlayerBind::extended, Field::Get(), ObjectGuid::GetCounter(), InstanceSave::GetInstanceId(), GetInstanceSave(), lock_instLists, InstancePlayerBind::perm, playerBindStorage, PlayerCreateBoundInstancesMaps(), InstanceSave::RemovePlayer(), InstancePlayerBind::save, and PreparedStatementBase::SetData().

Referenced by LoadInstances().

◆ LoadInstances()

void InstanceSaveMgr::LoadInstances ( )
261{
262 uint32 oldMSTime = getMSTime();
263
264 // Delete character_instance for non-existent character
265 CharacterDatabase.DirectExecute("DELETE ci.* FROM character_instance AS ci LEFT JOIN characters AS c ON ci.guid = c.guid WHERE c.guid IS NULL");
266
267 // Delete expired normal instances (normals expire after 3 days even if someone is still bound to them, cleared on startup)
268 CharacterDatabase.DirectExecute("DELETE FROM instance WHERE resettime > 0 AND resettime < UNIX_TIMESTAMP()");
269
270 // Delete instance with no binds
271 CharacterDatabase.DirectExecute("DELETE i.* FROM instance AS i LEFT JOIN character_instance AS ci ON i.id = ci.instance WHERE ci.guid IS NULL");
272
273 // Delete creature_respawn, gameobject_respawn and creature_instance for non-existent instance
274 CharacterDatabase.DirectExecute("DELETE FROM creature_respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
275 CharacterDatabase.DirectExecute("DELETE FROM gameobject_respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
276 CharacterDatabase.DirectExecute("DELETE tmp.* FROM character_instance AS tmp LEFT JOIN instance ON tmp.instance = instance.id WHERE tmp.instance > 0 AND instance.id IS NULL");
277
278 // Clean invalid references to instance
279 CharacterDatabase.DirectExecute("UPDATE corpse SET instanceId = 0 WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
280 CharacterDatabase.DirectExecute("UPDATE characters AS tmp LEFT JOIN instance ON tmp.instance_id = instance.id SET tmp.instance_id = 0 WHERE tmp.instance_id > 0 AND instance.id IS NULL");
281
282 // Initialize instance id storage (Needs to be done after the trash has been clean out)
283 sMapMgr->InitInstanceIds();
284
285 // Load reset times and clean expired instances
287
288 // pussywizard
291
292 // Sanitize pending rows on Instance_saved_data for data that wasn't deleted properly
294
295 LOG_INFO("server.loading", ">> Loaded Instances And Binds in {} ms", GetMSTimeDiffToNow(oldMSTime));
296 LOG_INFO("server.loading", " ");
297}
#define LOG_INFO(filterType__,...)
Definition Log.h:165
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
void LoadCharacterBinds()
Definition InstanceSaveMgr.cpp:405
void LoadInstanceSaves()
Definition InstanceSaveMgr.cpp:374
void LoadResetTimes()
Definition InstanceSaveMgr.cpp:299
void SanitizeInstanceSavedData()
Definition InstanceSaveMgr.cpp:244

References CharacterDatabase, getMSTime(), GetMSTimeDiffToNow(), LoadCharacterBinds(), LoadInstanceSaves(), LoadResetTimes(), LOG_INFO, SanitizeInstanceSavedData(), and sMapMgr.

◆ LoadInstanceSaves()

void InstanceSaveMgr::LoadInstanceSaves ( )
375{
376 QueryResult result = CharacterDatabase.Query("SELECT id, map, resettime, difficulty, completedEncounters, data FROM instance ORDER BY id ASC");
377 if (result)
378 {
379 do
380 {
381 Field* fields = result->Fetch();
382
383 uint32 instanceId = fields[0].Get<uint32>();
384 uint32 mapId = fields[1].Get<uint16>();
385 time_t resettime = time_t(fields[2].Get<uint32>());
386 uint8 difficulty = fields[3].Get<uint8>();
387 uint32 completedEncounters = fields[4].Get<uint32>();
388 std::string instanceData = fields[5].Get<std::string>();
389
390 // Mark instance id as being used
391 sMapMgr->RegisterInstanceId(instanceId);
392
393 InstanceSave* save = AddInstanceSave(mapId, instanceId, Difficulty(difficulty), true);
394 if (save)
395 {
396 save->SetCompletedEncounterMask(completedEncounters);
397 save->SetInstanceData(instanceData);
398 if (resettime > 0)
399 save->SetResetTime(resettime);
400 }
401 } while (result->NextRow());
402 }
403}
InstanceSave * AddInstanceSave(uint32 mapId, uint32 instanceId, Difficulty difficulty, bool startup=false)
Definition InstanceSaveMgr.cpp:66
void SetResetTime(time_t resetTime)
Definition InstanceSaveMgr.h:78
void SetInstanceData(std::string str)
Definition InstanceSaveMgr.h:70
void SetCompletedEncounterMask(uint32 mask)
Definition InstanceSaveMgr.h:72

References AddInstanceSave(), CharacterDatabase, Field::Get(), InstanceSave::SetCompletedEncounterMask(), InstanceSave::SetInstanceData(), InstanceSave::SetResetTime(), and sMapMgr.

Referenced by LoadInstances().

◆ LoadResetTimes()

void InstanceSaveMgr::LoadResetTimes ( )
300{
301 time_t now = GameTime::GetGameTime().count();
302 time_t today = (now / DAY) * DAY;
303
304 // load the global respawn times for raid/heroic instances
305 uint32 diff = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR) * HOUR;
306 QueryResult result = CharacterDatabase.Query("SELECT mapid, difficulty, resettime FROM instance_reset");
307 if (result)
308 {
309 do
310 {
311 Field* fields = result->Fetch();
312 uint32 mapid = fields[0].Get<uint16>();
313 Difficulty difficulty = Difficulty(fields[1].Get<uint8>());
314 uint64 resettime = fields[2].Get<uint32>();
315
316 MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
317 if (!mapDiff)
318 {
319 LOG_ERROR("instance.save", "InstanceSaveMgr::LoadResetTimes: invalid mapid({})/difficulty({}) pair in instance_reset!", mapid, difficulty);
320 CharacterDatabase.DirectExecute("DELETE FROM instance_reset WHERE mapid = '{}' AND difficulty = '{}'", mapid, difficulty);
321 continue;
322 }
323
324 SetResetTimeFor(mapid, difficulty, resettime);
325 } while (result->NextRow());
326 }
327
328 // calculate new global reset times for expired instances and those that have never been reset yet
329 // add the global reset times to the priority queue
330 for (MapDifficultyMap::const_iterator itr = sMapDifficultyMap.begin(); itr != sMapDifficultyMap.end(); ++itr)
331 {
332 uint32 map_diff_pair = itr->first;
333 uint32 mapid = PAIR32_LOPART(map_diff_pair);
334 Difficulty difficulty = Difficulty(PAIR32_HIPART(map_diff_pair));
335 MapDifficulty const* mapDiff = &itr->second;
336 if (!mapDiff->resetTime)
337 continue;
338
339 // the reset_delay must be at least one day
340 uint32 period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / DAY) * DAY);
341 if (period < DAY)
342 period = DAY;
343
344 time_t t = GetResetTimeFor(mapid, difficulty);
345 if (!t)
346 {
347 // initialize the reset time
348 t = today + period + diff;
349 SetResetTimeFor(mapid, difficulty, t);
350 CharacterDatabase.DirectExecute("INSERT INTO instance_reset VALUES ('{}', '{}', '{}')", mapid, difficulty, (uint32)t);
351 }
352
353 if (t < now)
354 {
355 // assume that expired instances have already been cleaned
356 // calculate the next reset time
357 t = (t * DAY) / DAY;
358 t += ((today - t) / period + 1) * period + diff;
359 CharacterDatabase.DirectExecute("UPDATE instance_reset SET resettime = '{}' WHERE mapid = '{}' AND difficulty = '{}'", (uint32)t, mapid, difficulty);
360 }
361
362 SetExtendedResetTimeFor(mapid, difficulty, t);
363
364 // schedule the global reset/warning
365 uint8 type;
366 for (type = 1; type < 5; ++type)
367 if (now + ResetTimeDelay[type - 1] < t)
368 break;
369
370 ScheduleReset(t - ResetTimeDelay[type - 1], InstResetEvent(type, mapid, difficulty));
371 }
372}
MapDifficultyMap sMapDifficultyMap
Definition DBCStores.cpp:121
std::uint64_t uint64
Definition Define.h:106
uint16 PAIR32_HIPART(uint32 x)
Definition ObjectDefines.h:92
uint16 PAIR32_LOPART(uint32 x)
Definition ObjectDefines.h:97
static uint16 ResetTimeDelay[]
Definition InstanceSaveMgr.h:37

References CharacterDatabase, CONFIG_INSTANCE_RESET_TIME_HOUR, DAY, Field::Get(), GameTime::GetGameTime(), GetMapDifficultyData(), GetResetTimeFor(), HOUR, LOG_ERROR, PAIR32_HIPART(), PAIR32_LOPART(), RATE_INSTANCE_RESET_TIME, MapDifficulty::resetTime, ResetTimeDelay, ScheduleReset(), SetExtendedResetTimeFor(), SetResetTimeFor(), sMapDifficultyMap, and sWorld.

Referenced by LoadInstances().

◆ PlayerBindToInstance()

InstancePlayerBind * InstanceSaveMgr::PlayerBindToInstance ( ObjectGuid  guid,
InstanceSave save,
bool  permanent,
Player player = nullptr 
)
638{
639 InstancePlayerBind& bind = playerBindStorage[guid]->m[save->GetDifficulty()][save->GetMapId()];
640 ASSERT(!bind.perm || permanent); // ensure there's no changing permanent to temporary, this can be done only by unbinding
641
642 if (bind.save)
643 {
644 if (save != bind.save || permanent != bind.perm)
645 {
646 bind.extended = false;
647
649 stmt->SetData(0, save->GetInstanceId());
650 stmt->SetData(1, permanent);
651 stmt->SetData(2, guid.GetCounter());
652 stmt->SetData(3, bind.save->GetInstanceId());
653 CharacterDatabase.Execute(stmt);
654 }
655 }
656 else
657 {
658 // pussywizard: protect against mysql thread races!
659 // pussywizard: CHANGED MY MIND! DON'T SLOW DOWN THIS QUERY! HANDLE ONLY DURING LOADING FROM DB!
660 // example: enter instance -> bind -> update old id to new id -> exit -> delete new id
661 // if delete by new id is executed before update, then we end up with in db
662 /*CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
663 // ensure any for that map+difficulty is deleted!
664 CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE_BY_GUID_MAP_DIFF); // DELETE ci FROM character_instance ci JOIN instance i ON ci.instance = i.id WHERE ci.guid = ? AND i.map = ? AND i.difficulty = ?
665 stmt->SetData(0, guidLow);
666 stmt->SetData(1, uint16(save->GetMapId()));
667 stmt->SetData(2, uint8(save->GetDifficulty()));
668 trans->Append(stmt);
669 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_INSTANCE);
670 stmt->SetData(0, guidLow);
671 stmt->SetData(1, save->GetInstanceId());
672 stmt->SetData(2, permanent);
673 trans->Append(stmt);
674 CharacterDatabase.CommitTransaction(trans);*/
675
677 stmt->SetData(0, guid.GetCounter());
678 stmt->SetData(1, save->GetInstanceId());
679 stmt->SetData(2, permanent);
680 CharacterDatabase.Execute(stmt);
681
682 if (player)
684 }
685
686 if (bind.save != save)
687 {
688 if (bind.save)
689 bind.save->RemovePlayer(guid, this);
690 save->AddPlayer(guid);
691 }
692
693 if (permanent)
694 {
695 save->SetCanReset(false);
696 if (!bind.perm && player) // temporary changing to permanent
697 player->GetSession()->SendCalendarRaidLockout(save, true);
698 }
699
700 bind.save = save;
701 bind.perm = permanent;
702
703 if (player)
704 sScriptMgr->OnPlayerBindToInstance(player, save->GetDifficulty(), save->GetMapId(), permanent);
705
706 return &bind;
707}
@ CHAR_INS_CHAR_INSTANCE
Definition CharacterDatabase.h:314
@ CHAR_UPD_CHAR_INSTANCE
Definition CharacterDatabase.h:312
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_RAID
Definition DBCEnums.h:136
void AddPlayer(ObjectGuid guid)
Definition InstanceSaveMgr.cpp:218
void SetCanReset(bool canReset)
Definition InstanceSaveMgr.h:82
Difficulty GetDifficulty() const
Definition InstanceSaveMgr.h:63
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, Unit *unit=nullptr)
Definition PlayerUpdates.cpp:2177
WorldSession * GetSession() const
Definition Player.h:2005
void SendCalendarRaidLockout(InstanceSave const *save, bool add)
Definition CalendarHandler.cpp:818

References ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_RAID, InstanceSave::AddPlayer(), ASSERT, CHAR_INS_CHAR_INSTANCE, CHAR_UPD_CHAR_INSTANCE, CharacterDatabase, InstancePlayerBind::extended, ObjectGuid::GetCounter(), InstanceSave::GetDifficulty(), InstanceSave::GetInstanceId(), InstanceSave::GetMapId(), Player::GetSession(), InstancePlayerBind::perm, playerBindStorage, InstanceSave::RemovePlayer(), InstancePlayerBind::save, WorldSession::SendCalendarRaidLockout(), InstanceSave::SetCanReset(), PreparedStatementBase::SetData(), sScriptMgr, and Player::UpdateAchievementCriteria().

Referenced by CopyBinds().

◆ PlayerCreateBoundInstancesMaps()

void InstanceSaveMgr::PlayerCreateBoundInstancesMaps ( ObjectGuid  guid)
791{
792 if (playerBindStorage.find(guid) == playerBindStorage.end())
794}
Definition InstanceSaveMgr.h:49

References playerBindStorage.

Referenced by LoadCharacterBinds().

◆ PlayerGetBoundInstance()

InstancePlayerBind * InstanceSaveMgr::PlayerGetBoundInstance ( ObjectGuid  guid,
uint32  mapid,
Difficulty  difficulty 
)
753{
754 Difficulty difficulty_fixed = ( IsSharedDifficultyMap(mapid) ? Difficulty(difficulty % 2) : difficulty);
755
756 MapDifficulty const* mapDiff = GetDownscaledMapDifficultyData(mapid, difficulty_fixed);
757 if (!mapDiff)
758 return nullptr;
759
760 BoundInstancesMapWrapper* w = nullptr;
761 PlayerBindStorage::const_iterator itr = playerBindStorage.find(guid);
762 if (itr != playerBindStorage.end())
763 w = itr->second;
764 else
765 return nullptr;
766
767 BoundInstancesMap::iterator itr2 = w->m[difficulty_fixed].find(mapid);
768 if (itr2 != w->m[difficulty_fixed].end())
769 return &itr2->second;
770 else
771 return nullptr;
772}
MapDifficulty const * GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
Definition DBCStores.cpp:767
bool IsSharedDifficultyMap(uint32 mapid)
Definition DBCStores.cpp:829
BoundInstancesMap m[MAX_DIFFICULTY]
Definition InstanceSaveMgr.h:50

References GetDownscaledMapDifficultyData(), IsSharedDifficultyMap(), BoundInstancesMapWrapper::m, and playerBindStorage.

Referenced by CopyBinds(), PlayerGetDestinationInstanceId(), PlayerGetInstanceSave(), and PlayerIsPermBoundToInstance().

◆ PlayerGetBoundInstances()

BoundInstancesMap const & InstanceSaveMgr::PlayerGetBoundInstances ( ObjectGuid  guid,
Difficulty  difficulty 
)
783{
784 PlayerBindStorage::iterator itr = playerBindStorage.find(guid);
785 if (itr != playerBindStorage.end())
786 return itr->second->m[difficulty];
788}
static BoundInstancesMap emptyBoundInstancesMap
Definition InstanceSaveMgr.h:190

References emptyBoundInstancesMap, and playerBindStorage.

Referenced by CopyBinds().

◆ PlayerGetDestinationInstanceId()

uint32 InstanceSaveMgr::PlayerGetDestinationInstanceId ( Player player,
uint32  mapid,
Difficulty  difficulty 
)
803{
804 // returning 0 means a new instance will be created
805 // non-zero implicates that InstanceSave exists
806
807 InstancePlayerBind* ipb = PlayerGetBoundInstance(player->GetGUID(), mapid, difficulty);
808 if (ipb && ipb->perm) // 1. self perm
809 return ipb->save->GetInstanceId();
810 if (Group* g = player->GetGroup())
811 {
812 if (InstancePlayerBind* ilb = PlayerGetBoundInstance(g->GetLeaderGUID(), mapid, difficulty)) // 2. leader temp/perm
813 return ilb->save->GetInstanceId();
814 return 0; // 3. in group, no leader bind
815 }
816 return ipb ? ipb->save->GetInstanceId() : 0; // 4. self temp
817}
Definition Group.h:169
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:112
Group * GetGroup()
Definition Player.h:2476

References Player::GetGroup(), Object::GetGUID(), InstanceSave::GetInstanceId(), InstancePlayerBind::perm, PlayerGetBoundInstance(), and InstancePlayerBind::save.

◆ PlayerGetInstanceSave()

InstanceSave * InstanceSaveMgr::PlayerGetInstanceSave ( ObjectGuid  guid,
uint32  mapid,
Difficulty  difficulty 
)
797{
798 InstancePlayerBind* pBind = PlayerGetBoundInstance(guid, mapid, difficulty);
799 return (pBind ? pBind->save : nullptr);
800}

References PlayerGetBoundInstance(), and InstancePlayerBind::save.

◆ PlayerIsPermBoundToInstance()

bool InstanceSaveMgr::PlayerIsPermBoundToInstance ( ObjectGuid  guid,
uint32  mapid,
Difficulty  difficulty 
)
775{
776 if (InstancePlayerBind* bind = PlayerGetBoundInstance(guid, mapid, difficulty))
777 if (bind->perm)
778 return true;
779 return false;
780}

References PlayerGetBoundInstance().

◆ PlayerUnbindInstance()

void InstanceSaveMgr::PlayerUnbindInstance ( ObjectGuid  guid,
uint32  mapid,
Difficulty  difficulty,
bool  deleteFromDB,
Player player = nullptr 
)
710{
712 BoundInstancesMap::iterator itr = w->m[difficulty].find(mapid);
713 if (itr != w->m[difficulty].end())
714 {
715 if (deleteFromDB)
716 {
718 stmt->SetData(0, guid.GetCounter());
719 stmt->SetData(1, itr->second.save->GetInstanceId());
720 CharacterDatabase.Execute(stmt);
721 }
722
723 if (itr->second.perm && player)
724 player->GetSession()->SendCalendarRaidLockout(itr->second.save, false);
725
726 InstanceSave* tmp = itr->second.save;
727 w->m[difficulty].erase(itr);
728 tmp->RemovePlayer(guid, this);
729 }
730}

References CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_GUID, CharacterDatabase, ObjectGuid::GetCounter(), Player::GetSession(), BoundInstancesMapWrapper::m, playerBindStorage, InstanceSave::RemovePlayer(), WorldSession::SendCalendarRaidLockout(), and PreparedStatementBase::SetData().

Referenced by UnbindAllFor().

◆ PlayerUnbindInstanceNotExtended()

void InstanceSaveMgr::PlayerUnbindInstanceNotExtended ( ObjectGuid  guid,
uint32  mapid,
Difficulty  difficulty,
Player player = nullptr 
)
733{
735 BoundInstancesMap::iterator itr = w->m[difficulty].find(mapid);
736 if (itr != w->m[difficulty].end())
737 {
738 if (itr->second.extended)
739 itr->second.extended = false;
740 else
741 {
742 if (itr->second.perm && player)
743 player->GetSession()->SendCalendarRaidLockout(itr->second.save, false);
744
745 InstanceSave* tmp = itr->second.save;
746 w->m[difficulty].erase(itr);
747 tmp->RemovePlayer(guid, this);
748 }
749 }
750}

References Player::GetSession(), BoundInstancesMapWrapper::m, playerBindStorage, InstanceSave::RemovePlayer(), and WorldSession::SendCalendarRaidLockout().

Referenced by _ResetSave().

◆ SanitizeInstanceSavedData()

void InstanceSaveMgr::SanitizeInstanceSavedData ( )
245{
247 CharacterDatabase.Execute(stmt);
248}
@ CHAR_SANITIZE_INSTANCE_SAVED_DATA
Definition CharacterDatabase.h:529

References CHAR_SANITIZE_INSTANCE_SAVED_DATA, and CharacterDatabase.

Referenced by LoadInstances().

◆ ScheduleReset()

void InstanceSaveMgr::ScheduleReset ( time_t  time,
InstResetEvent  event 
)
458{
459 m_resetTimeQueue.insert(std::pair<time_t, InstResetEvent>(time, event));
460}
ResetTimeQueue m_resetTimeQueue
Definition InstanceSaveMgr.h:199

References m_resetTimeQueue.

Referenced by _ResetOrWarnAll(), LoadResetTimes(), and Update().

◆ SetExtendedResetTimeFor()

void InstanceSaveMgr::SetExtendedResetTimeFor ( uint32  mapid,
Difficulty  d,
time_t  t 
)
inline

◆ SetResetTimeFor()

void InstanceSaveMgr::SetResetTimeFor ( uint32  mapid,
Difficulty  d,
time_t  t 
)
inline
149 {
151 }

References m_resetTimeByMapDifficulty, and MAKE_PAIR32().

Referenced by _ResetOrWarnAll(), and LoadResetTimes().

◆ UnbindAllFor()

void InstanceSaveMgr::UnbindAllFor ( InstanceSave save)
834{
835 uint32 mapId = save->GetMapId();
836 Difficulty difficulty = save->GetDifficulty();
837 GuidList players = save->m_playerList;
838
839 for (ObjectGuid const& guid : players)
840 {
841 PlayerUnbindInstance(guid, mapId, difficulty, true, ObjectAccessor::FindConnectedPlayer(guid));
842 }
843}
void PlayerUnbindInstance(ObjectGuid guid, uint32 mapid, Difficulty difficulty, bool deleteFromDB, Player *player=nullptr)
Definition InstanceSaveMgr.cpp:709

References ObjectAccessor::FindConnectedPlayer(), InstanceSave::GetDifficulty(), InstanceSave::GetMapId(), InstanceSave::m_playerList, and PlayerUnbindInstance().

◆ Update()

void InstanceSaveMgr::Update ( )
463{
464 time_t now = GameTime::GetGameTime().count();
465 time_t t;
466 bool resetOccurred = false;
467
468 while (!m_resetTimeQueue.empty())
469 {
470 t = m_resetTimeQueue.begin()->first;
471 if (t >= now)
472 break;
473
474 InstResetEvent& event = m_resetTimeQueue.begin()->second;
475 if (event.type)
476 {
477 // global reset/warning for a certain map
478 time_t resetTime = GetResetTimeFor(event.mapid, event.difficulty);
479 bool warn = event.type < 5;
480 _ResetOrWarnAll(event.mapid, event.difficulty, warn, resetTime);
481 if (warn)
482 {
483 // schedule the next warning/reset
484 ++event.type;
485 ScheduleReset(resetTime - ResetTimeDelay[event.type - 1], event);
486 }
487 else
488 resetOccurred = true;
489 }
490 m_resetTimeQueue.erase(m_resetTimeQueue.begin());
491 }
492
493 // pussywizard: send updated calendar and raid info
494 if (resetOccurred)
495 {
496 LOG_INFO("instance.save", "Instance ID reset occurred, sending updated calendar and raid info to all players!");
497 WorldPacket dummy;
498
499 WorldSessionMgr::SessionMap const& sessionMap = sWorldSessionMgr->GetAllSessions();
500 for (WorldSessionMgr::SessionMap::const_iterator itr = sessionMap.begin(); itr != sessionMap.end(); ++itr)
501 if (Player* plr = itr->second->GetPlayer())
502 {
503 itr->second->HandleCalendarGetCalendar(dummy);
504 plr->SendRaidInfo();
505 }
506 }
507}
#define sWorldSessionMgr
Definition WorldSessionMgr.h:110
void _ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, time_t resetTime)
Definition InstanceSaveMgr.cpp:561
Definition Player.h:1081
Definition WorldPacket.h:26
std::unordered_map< uint32, WorldSession * > SessionMap
Definition WorldSessionMgr.h:56

References _ResetOrWarnAll(), GameTime::GetGameTime(), GetResetTimeFor(), LOG_INFO, m_resetTimeQueue, ResetTimeDelay, ScheduleReset(), and sWorldSessionMgr.

Friends And Related Symbol Documentation

◆ InstanceSave

friend class InstanceSave
friend

Referenced by AddInstanceSave().

Member Data Documentation

◆ emptyBoundInstancesMap

BoundInstancesMap InstanceSaveMgr::emptyBoundInstancesMap
staticprotected

Referenced by PlayerGetBoundInstances().

◆ lock_instLists

bool InstanceSaveMgr::lock_instLists {false}
private

◆ m_instanceSaveById

InstanceSaveHashMap InstanceSaveMgr::m_instanceSaveById
private

◆ m_resetExtendedTimeByMapDifficulty

ResetTimeByMapDifficultyMap InstanceSaveMgr::m_resetExtendedTimeByMapDifficulty
private

◆ m_resetTimeByMapDifficulty

ResetTimeByMapDifficultyMap InstanceSaveMgr::m_resetTimeByMapDifficulty
private

◆ m_resetTimeQueue

ResetTimeQueue InstanceSaveMgr::m_resetTimeQueue
private

Referenced by ScheduleReset(), and Update().

◆ playerBindStorage

◆ ResetTimeDelay

uint16 InstanceSaveMgr::ResetTimeDelay = {3600, 900, 300, 60, 0}
staticprotected

Referenced by LoadResetTimes(), and Update().


The documentation for this class was generated from the following files: