36 for (InstanceSave::PlayerListType::iterator itr2 = save->
m_playerList.begin(), next = itr2; itr2 != save->
m_playerList.end(); itr2 = next)
42 for (InstanceSave::GroupListType::iterator itr2 = save->
m_groupList.begin(), next = itr2; itr2 != save->
m_groupList.end(); itr2 = next)
64 SF_LOG_ERROR(
"misc",
"InstanceSaveManager::AddInstanceSave: wrong mapid = %d, instanceid = %d!", mapId, instanceId);
70 SF_LOG_ERROR(
"misc",
"InstanceSaveManager::AddInstanceSave: mapid = %d, wrong instanceid = %d!", mapId, instanceId);
76 SF_LOG_ERROR(
"misc",
"InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d, wrong dificalty %u!", mapId, instanceId, difficulty);
88 resetTime = time(NULL) + 2 *
HOUR;
94 SF_LOG_DEBUG(
"maps",
"InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d", mapId, instanceId);
136 if (time_t resettime = itr->second->GetResetTimeForDB())
146 itr->second->SetToDelete(
true);
168 uint32 completedEncounters = 0;
176 data = instanceScript->GetSaveData();
177 completedEncounters = instanceScript->GetCompletedEncounterMask();
236 CharacterDatabase.DirectExecute(
"DELETE i FROM instance i LEFT JOIN instance_reset ir ON mapid = map AND i.difficulty = ir.difficulty "
237 "WHERE (i.resettime > 0 AND i.resettime < UNIX_TIMESTAMP()) OR (ir.resettime IS NOT NULL AND ir.resettime < UNIX_TIMESTAMP())");
240 CharacterDatabase.DirectExecute(
"DELETE ci.* FROM character_instance AS ci LEFT JOIN characters AS c ON ci.guid = c.guid WHERE c.guid IS NULL");
241 CharacterDatabase.DirectExecute(
"DELETE gi.* FROM party_instance AS gi LEFT JOIN parties AS g ON gi.guid = g.guid WHERE g.guid IS NULL");
244 CharacterDatabase.DirectExecute(
"DELETE i.* FROM instance AS i LEFT JOIN character_instance AS ci ON i.id = ci.instance LEFT JOIN party_instance AS gi ON i.id = gi.instance WHERE ci.guid IS NULL AND gi.guid IS NULL");
247 CharacterDatabase.DirectExecute(
"DELETE FROM creature_respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
248 CharacterDatabase.DirectExecute(
"DELETE FROM gameobject_respawn WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
249 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");
250 CharacterDatabase.DirectExecute(
"DELETE tmp.* FROM party_instance AS tmp LEFT JOIN instance ON tmp.instance = instance.id WHERE tmp.instance > 0 AND instance.id IS NULL");
253 CharacterDatabase.DirectExecute(
"UPDATE corpse SET instanceId = 0 WHERE instanceId > 0 AND instanceId NOT IN (SELECT id FROM instance)");
254 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");
267 time_t now = time(NULL);
268 time_t today = (now /
DAY) *
DAY;
275 typedef std::pair<
uint32 , time_t> ResetTimeMapDiffType;
276 typedef std::map<uint32, ResetTimeMapDiffType> InstResetTimeMapDiffType;
277 InstResetTimeMapDiffType instResetTime;
280 typedef std::multimap<
uint32 ,
uint32 > ResetTimeMapDiffInstances;
281 typedef std::pair<ResetTimeMapDiffInstances::const_iterator, ResetTimeMapDiffInstances::const_iterator> ResetTimeMapDiffInstancesBounds;
282 ResetTimeMapDiffInstances mapDiffResetInstances;
289 Field* fields = result->Fetch();
295 if (
sMapMgr->GetNextInstanceId() == instanceId)
296 sMapMgr->SetNextInstanceId(instanceId + 1);
299 sMapMgr->RegisterInstanceId(instanceId);
301 if (time_t resettime = time_t(fields[3].GetUInt32()))
306 instResetTime[instanceId] = ResetTimeMapDiffType(
MAKE_PAIR32(mapid, difficulty), resettime);
307 mapDiffResetInstances.insert(ResetTimeMapDiffInstances::value_type(
MAKE_PAIR32(mapid, difficulty), instanceId));
309 }
while (result->NextRow());
316 Field* fields = result2->Fetch();
318 time_t resettime = time_t(fields[0].GetUInt32() + 2 *
uint32(
HOUR));
319 InstResetTimeMapDiffType::iterator itr = instResetTime.find(instance);
320 if (itr != instResetTime.end() && itr->second.second != resettime)
323 itr->second.second = resettime;
325 }
while (result->NextRow());
329 for (InstResetTimeMapDiffType::iterator itr = instResetTime.begin(); itr != instResetTime.end(); ++itr)
330 if (itr->second.second > now)
336 result =
CharacterDatabase.Query(
"SELECT mapid, difficulty, resettime FROM instance_reset");
341 Field* fields = result->Fetch();
349 SF_LOG_ERROR(
"misc",
"InstanceSaveManager::LoadResetTimes: invalid mapid(%u)/difficulty(%u) pair in instance_reset!", mapid, difficulty);
350 CharacterDatabase.DirectPExecute(
"DELETE FROM instance_reset WHERE mapid = '%u' AND difficulty = '%u'", mapid, difficulty);
355 uint64 newresettime = (oldresettime /
DAY) *
DAY + diff;
356 if (oldresettime != newresettime)
357 CharacterDatabase.DirectPExecute(
"UPDATE instance_reset SET resettime = '%u' WHERE mapid = '%u' AND difficulty = '%u'",
uint32(newresettime), mapid, difficulty);
360 }
while (result->NextRow());
367 uint32 mapid = mapDifficultyPair.first;
369 for (
auto& difficultyPair : mapDifficultyPair.second)
385 t = today + period + diff;
386 CharacterDatabase.DirectPExecute(
"INSERT INTO instance_reset VALUES ('%u', '%u', '%u')", mapid, difficulty, (
uint32)t);
394 t += ((today - t) / period + 1) * period + diff;
395 CharacterDatabase.DirectPExecute(
"UPDATE instance_reset SET resettime = '" UI64FMTD "' WHERE mapid = '%u' AND difficulty= '%u'", (
uint64)t, mapid, difficulty);
402 for (type = 1; type < 4; ++type)
408 ResetTimeMapDiffInstancesBounds range = mapDiffResetInstances.equal_range(
MAKE_PAIR32(mapid, difficulty));
409 for (; range.first != range.second; ++range.first)
420 ResetTimeQueue::iterator itr;
421 std::pair<ResetTimeQueue::iterator, ResetTimeQueue::iterator> range;
423 for (itr = range.first; itr != range.second; ++itr)
425 if (itr->second == event)
433 if (itr == range.second)
437 if (itr->second == event)
445 SF_LOG_ERROR(
"misc",
"InstanceSaveManager::ScheduleReset: cannot cancel the reset, the event(%d, %d, %d) was not found!", event.
type, event.
mapid, event.
instanceId);
454 time_t now = time(NULL);
474 _ResetOrWarnAll(event.mapid, event.difficulty, event.type != 4, resetTime);
493 while (!pList.empty())
495 Player* player = *(pList.begin());
496 player->
UnbindInstance(itr->second->GetMapId(), itr->second->GetDifficulty(),
true);
500 while (!gList.empty())
502 Group* group = *(gList.begin());
503 group->
UnbindInstance(itr->second->GetMapId(), itr->second->GetDifficulty(),
true);
514 SF_LOG_DEBUG(
"maps",
"InstanceSaveMgr::_ResetInstance %u, %u", mapid, instanceId);
515 Map const* map =
sMapMgr->CreateBaseMap(mapid);
536 sMapMgr->FreeInstanceId(instanceId);
546 time_t now = time(NULL);
553 SF_LOG_ERROR(
"misc",
"InstanceSaveManager::ResetOrWarnAll: not valid difficulty or no reset delay for map %d", mapid);
560 if (itr->second->GetMapId() == mapid && itr->second->GetDifficulty() == difficulty)
609 Map const* map =
sMapMgr->CreateBaseMap(mapid);
611 MapInstanced::InstancedMaps::iterator mitr;
614 for (mitr = instMaps.begin(); mitr != instMaps.end(); ++mitr)
616 Map* map2 = mitr->second;
622 if (now <= resetTime)
625 timeLeft =
uint32(now - resetTime);
640 ret += itr->second->GetPlayerCount();
649 ret += itr->second->GetGroupCount();
@ CHAR_UPD_GLOBAL_INSTANCE_RESETTIME
@ CHAR_SEL_MAX_CREATURE_RESPAWNS
@ CHAR_DEL_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_INSTANCE_BY_MAP_DIFF
@ CHAR_UPD_INSTANCE_RESETTIME
MapDifficulty const * GetMapDifficultyData(uint32 mapId, DifficultyID difficulty)
MapDifficultyMap sMapDifficultyMap
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
#define SF_LOG_DEBUG(filterType__,...)
#define SF_LOG_ERROR(filterType__,...)
#define SF_LOG_INFO(filterType__,...)
@ INSTANCE_RESET_RESPAWN_DELAY
uint32 MAKE_PAIR32(uint16 l, uint16 h)
uint16 PAIR32_HIPART(uint32 x)
uint16 PAIR32_LOPART(uint32 x)
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload=false)
DifficultyID GetDifficulty() const
DifficultyID m_difficulty
InstanceTemplate const * GetTemplate()
MapEntry const * GetMapEntry()
time_t GetResetTimeForDB()
uint32 GetInstanceId() const
std::list< Group * > GroupListType
PlayerListType m_playerList
std::list< Player * > PlayerListType
InstanceSave(uint16 MapId, uint32 InstanceId, DifficultyID difficulty, time_t resetTime, bool canReset)
GroupListType m_groupList
time_t GetResetTime() const
InstanceSave * GetInstanceSave(uint32 InstanceId)
static void DeleteInstanceFromDB(uint32 instanceid)
void SetResetTimeFor(uint32 mapid, DifficultyID d, time_t t)
void _ResetInstance(uint32 mapid, uint32 instanceId)
InstanceSaveHashMap m_instanceSaveById
static uint16 ResetTimeDelay[]
uint32 GetNumBoundGroupsTotal()
uint32 GetNumBoundPlayersTotal()
friend class InstanceSave
void RemoveInstanceSave(uint32 InstanceId)
void ScheduleReset(bool add, time_t time, InstResetEvent event)
void _ResetOrWarnAll(uint32 mapid, DifficultyID difficulty, bool warn, time_t resetTime)
InstanceSave * AddInstanceSave(uint32 mapId, uint32 instanceId, DifficultyID difficulty, time_t resetTime, bool canReset, bool load=false)
ResetTimeQueue m_resetTimeQueue
void _ResetSave(InstanceSaveHashMap::iterator &itr)
time_t GetResetTimeFor(uint32 mapid, DifficultyID d) const
static void DeleteRespawnTimesInDB(uint16 mapId, uint32 instanceId)
void DeleteRespawnTimes()
bool Instanceable() const
UNORDERED_MAP< uint32, Map * > InstancedMaps
void UnbindInstance(uint32 mapid, DifficultyID difficulty, bool unload=false)
void setString(const uint8 index, const std::string &value)
void setUInt16(const uint8 index, const uint16 value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
@ CONFIG_INSTANCE_RESET_TIME_HOUR
@ RATE_INSTANCE_RESET_TIME
bool Instanceable() const