56 for (InstanceSave::PlayerListType::iterator itr2 = save->
m_playerList.begin(), next = itr2; itr2 != save->
m_playerList.end(); itr2 = next)
62 for (InstanceSave::GroupListType::iterator itr2 = save->
m_groupList.begin(), next = itr2; itr2 != save->
m_groupList.end(); itr2 = next)
84 TC_LOG_ERROR(
"misc",
"InstanceSaveManager::AddInstanceSave: wrong mapid = {}, instanceid = {}!", mapId, instanceId);
90 TC_LOG_ERROR(
"misc",
"InstanceSaveManager::AddInstanceSave: mapid = {}, wrong instanceid = {}!", mapId, instanceId);
96 TC_LOG_ERROR(
"misc",
"InstanceSaveManager::AddInstanceSave: mapid = {}, instanceid = {}, wrong dificalty {}!", mapId, instanceId,
static_cast<uint32>(difficulty));
114 TC_LOG_DEBUG(
"maps",
"InstanceSaveManager::AddInstanceSave: mapid = {}, instanceid = {}", mapId, instanceId);
156 if (time_t resettime = itr->second->GetResetTimeForDB())
166 itr->second->SetToDelete(
true);
175 save->UnloadIfEmpty();
176 if (save->m_toDelete)
182: m_resetTime(resetTime), m_instanceid(InstanceId), m_mapid(MapId),
183 m_difficulty(difficulty), m_canReset(canReset), m_toDelete(false) { }
198 uint32 completedEncounters = 0;
206 data = instanceScript->GetSaveData();
207 completedEncounters = instanceScript->GetCompletedEncounterMask();
254 if (map->HavePlayers())
271 CharacterDatabase.DirectExecute(
"DELETE i FROM instance i LEFT JOIN instance_reset ir ON mapid = map AND i.difficulty = ir.difficulty "
272 "WHERE (i.resettime > 0 AND i.resettime < UNIX_TIMESTAMP()) OR (ir.resettime IS NOT NULL AND ir.resettime < UNIX_TIMESTAMP())");
275 CharacterDatabase.DirectExecute(
"DELETE ci.* FROM character_instance AS ci LEFT JOIN characters AS c ON ci.guid = c.guid WHERE c.guid IS NULL");
276 CharacterDatabase.DirectExecute(
"DELETE gi.* FROM group_instance AS gi LEFT JOIN `groups` AS g ON gi.guid = g.guid WHERE g.guid IS NULL");
279 CharacterDatabase.DirectExecute(
"DELETE i.* FROM instance AS i LEFT JOIN character_instance AS ci ON i.id = ci.instance LEFT JOIN group_instance AS gi ON i.id = gi.instance WHERE ci.guid IS NULL AND gi.guid IS NULL");
282 CharacterDatabase.DirectExecute(
"DELETE FROM respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
283 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");
284 CharacterDatabase.DirectExecute(
"DELETE tmp.* FROM group_instance AS tmp LEFT JOIN instance ON tmp.instance = instance.id WHERE tmp.instance > 0 AND instance.id IS NULL");
287 CharacterDatabase.DirectExecute(
"UPDATE corpse SET instanceId = 0 WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
288 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");
303 time_t today = (now /
DAY) *
DAY;
310 typedef std::pair<
uint32 , time_t> ResetTimeMapDiffType;
311 typedef std::map<uint32, ResetTimeMapDiffType> InstResetTimeMapDiffType;
312 InstResetTimeMapDiffType instResetTime;
315 typedef std::multimap<
uint32 ,
uint32 > ResetTimeMapDiffInstances;
316 typedef std::pair<ResetTimeMapDiffInstances::const_iterator, ResetTimeMapDiffInstances::const_iterator> ResetTimeMapDiffInstancesBounds;
317 ResetTimeMapDiffInstances mapDiffResetInstances;
323 Field* fields = result->Fetch();
328 sMapMgr->RegisterInstanceId(instanceId);
330 if (time_t resettime = time_t(fields[3].GetUInt64()))
335 instResetTime[instanceId] = ResetTimeMapDiffType(
MAKE_PAIR32(mapid, difficulty), resettime);
336 mapDiffResetInstances.insert(ResetTimeMapDiffInstances::value_type(
MAKE_PAIR32(mapid, difficulty), instanceId));
339 while (result->NextRow());
342 for (InstResetTimeMapDiffType::iterator itr = instResetTime.begin(); itr != instResetTime.end(); ++itr)
343 if (itr->second.second > now)
353 Field* fields = result->Fetch();
361 TC_LOG_ERROR(
"misc",
"InstanceSaveManager::LoadResetTimes: invalid mapid({})/difficulty({}) pair in instance_reset!", mapid,
static_cast<uint32>(difficulty));
372 if (oldresettime != newresettime)
382 }
while (result->NextRow());
389 uint32 map_diff_pair = itr->first;
418 time_t day = (t /
DAY) *
DAY;
432 for (type = 1; type < 4; ++type)
438 ResetTimeMapDiffInstancesBounds range = mapDiffResetInstances.equal_range(map_diff_pair);
439 for (; range.first != range.second; ++range.first)
449 TC_LOG_ERROR(
"misc",
"InstanceSaveManager::GetSubsequentResetTime: not valid difficulty or no reset delay for map {}", mapid);
473 ResetTimeQueue::iterator itr;
474 std::pair<ResetTimeQueue::iterator, ResetTimeQueue::iterator> range;
476 for (itr = range.first; itr != range.second; ++itr)
478 if (itr->second == event)
486 if (itr == range.second)
490 if (itr->second == event)
498 TC_LOG_ERROR(
"misc",
"InstanceSaveManager::ScheduleReset: cannot cancel the reset, the event({}, {}, {}) was not found!", event.
type, event.
mapid, event.
instanceId);
538 _ResetOrWarnAll(event.mapid, event.difficulty, event.type != 4, resetTime);
556 bool shouldDelete =
true;
558 std::vector<Player*> temp;
559 for (
Player* player : pList)
561 if (
InstancePlayerBind* bind = player->GetBoundInstance(itr->second->GetMapId(), itr->second->GetDifficulty()))
563 ASSERT(bind->save == itr->second);
564 if (bind->perm && bind->extendState)
568 shouldDelete =
false;
572 temp.push_back(player);
574 for (
Player* player : temp)
576 player->UnbindInstance(itr->second->GetMapId(), itr->second->GetDifficulty(),
true);
580 while (!gList.empty())
582 Group* group = *(gList.begin());
583 group->
UnbindInstance(itr->second->GetMapId(), itr->second->GetDifficulty(),
true);
599 TC_LOG_DEBUG(
"maps",
"InstanceSaveMgr::_ResetInstance {}, {}", mapid, instanceId);
600 Map const* map =
sMapMgr->CreateBaseMap(mapid);
624 sMapMgr->FreeInstanceId(instanceId);
633 TC_LOG_DEBUG(
"misc",
"InstanceSaveManager::ResetOrWarnAll: Processing map {} ({}) on difficulty {} (warn? {})", mapEntry->
MapName[0], mapid,
static_cast<uint32>(difficulty), warn);
672 if (itr->second->GetMapId() == mapid && itr->second->GetDifficulty() == difficulty)
700 if (now >= resetTime)
703 timeLeft =
uint32(resetTime - now);
718 ret += itr->second->GetPlayerCount();
727 ret += itr->second->GetGroupCount();
@ CHAR_UPD_GLOBAL_INSTANCE_RESETTIME
@ CHAR_DEL_EXPIRED_INSTANCE_BY_MAP_DIFF
@ CHAR_UPD_EXPIRE_CHAR_INSTANCE_BY_MAP_DIFF
@ CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE
@ CHAR_DEL_GROUP_INSTANCE_BY_MAP_DIFF
@ CHAR_DEL_INSTANCE_BY_INSTANCE
@ CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE
@ CHAR_DEL_GLOBAL_INSTANCE_RESETTIME
@ CHAR_DEL_EXPIRED_CHAR_INSTANCE_BY_MAP_DIFF
@ CHAR_UPD_INSTANCE_RESETTIME
@ CHAR_INS_GLOBAL_INSTANCE_RESETTIME
#define MAX_RAID_DIFFICULTY
@ DUNGEON_DIFFICULTY_NORMAL
@ DUNGEON_DIFFICULTY_HEROIC
#define MAX_DUNGEON_DIFFICULTY
MapDifficulty const * GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
MapDifficultyMap sMapDifficultyMap
MapDifficulty const * GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
#define TC_LOG_DEBUG(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_INFO(filterType__,...)
@ INSTANCE_RESET_RESPAWN_DELAY
uint32 MAKE_PAIR32(uint16 l, uint16 h)
uint16 PAIR32_HIPART(uint32 x)
uint16 PAIR32_LOPART(uint32 x)
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
Class used to access individual fields of database query result.
void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload=false)
void SendResetWarnings(uint32 timeLeft) const
InstanceSave * GetInstanceSave(uint32 InstanceId)
static void DeleteInstanceFromDB(uint32 instanceid)
uint32 GetNumBoundGroupsTotal() const
void _ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, time_t resetTime)
void _ResetInstance(uint32 mapid, uint32 instanceId)
InstanceSaveHashMap m_instanceSaveById
void ForceGlobalReset(uint32 mapId, Difficulty difficulty)
static uint16 ResetTimeDelay[]
void UnloadInstanceSave(uint32 InstanceId)
uint32 GetNumBoundPlayersTotal() const
time_t GetSubsequentResetTime(uint32 mapid, Difficulty difficulty, time_t resetTime) const
ResetTimeByMapDifficultyMap m_resetTimeByMapDifficulty
friend class InstanceSave
void RemoveInstanceSave(uint32 InstanceId)
static InstanceSaveManager * instance()
void ScheduleReset(bool add, time_t time, InstResetEvent event)
InstanceSave * AddInstanceSave(uint32 mapId, uint32 instanceId, Difficulty difficulty, time_t resetTime, bool canReset, bool load=false)
time_t GetResetTimeFor(uint32 mapid, Difficulty d) const
void SetResetTimeFor(uint32 mapid, Difficulty d, time_t t)
void InitializeResetTimeFor(uint32 mapid, Difficulty d, time_t t)
ResetTimeQueue m_resetTimeQueue
void _ResetSave(InstanceSaveHashMap::iterator &itr)
InstanceTemplate const * GetTemplate()
MapEntry const * GetMapEntry()
time_t GetResetTimeForDB()
uint32 GetInstanceId() const
std::list< Group * > GroupListType
Difficulty GetDifficulty() const
PlayerListType m_playerList
InstanceSave(uint16 MapId, uint32 InstanceId, Difficulty difficulty, time_t resetTime, bool canReset)
std::list< Player * > PlayerListType
GroupListType m_groupList
time_t GetResetTime() const
InstancedMaps & GetInstancedMaps()
static void DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId)
void DeleteRespawnTimes()
bool Instanceable() const
InstanceMap * ToInstanceMap()
MapInstanced * ToMapInstanced()
void setUInt16(uint8 index, uint16 value)
void setUInt32(uint8 index, uint32 value)
void setUInt64(uint8 index, uint64 value)
void setUInt8(uint8 index, uint8 value)
void setString(uint8 index, std::string const &value)
@ CONFIG_INSTANCE_RESET_TIME_HOUR
@ RATE_INSTANCE_RESET_TIME
bool Instanceable() const