Core/InstanceSaveMgr: Prevent timer underflow by passing resetTime instead of timeLeft

--HG--
branch : trunk
This commit is contained in:
linencloth
2010-12-19 00:59:04 +01:00
parent 837e50ea23
commit 4193806dba
2 changed files with 21 additions and 8 deletions
+20 -7
View File
@@ -470,7 +470,7 @@ void InstanceSaveManager::Update()
{
// global reset/warning for a certain map
time_t resetTime = GetResetTimeFor(event.mapid,event.difficulty);
_ResetOrWarnAll(event.mapid, event.difficulty, event.type != 4, uint32(resetTime - now));
_ResetOrWarnAll(event.mapid, event.difficulty, event.type != 4, resetTime);
if (event.type != 4)
{
// schedule the next warning/reset
@@ -520,14 +520,14 @@ void InstanceSaveManager::_ResetInstance(uint32 mapid, uint32 instanceId)
else sObjectMgr.DeleteRespawnTimeForInstance(instanceId); // even if map is not loaded
}
void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, uint32 timeLeft)
void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, time_t resetTime)
{
// global reset for all instances of the given map
MapEntry const *mapEntry = sMapStore.LookupEntry(mapid);
if (!mapEntry->Instanceable())
return;
uint64 now = (uint64)time(NULL);
time_t now = time(NULL);
if (!warn)
{
@@ -561,7 +561,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b
if (period < DAY)
period = DAY;
uint64 next_reset = ((now + timeLeft + MINUTE) / DAY * DAY) + period + diff;
uint64 next_reset = ((resetTime + MINUTE) / DAY * DAY) + period + diff;
SetResetTimeFor(mapid, difficulty, next_reset);
ScheduleReset(true, time_t(next_reset-3600), InstResetEvent(1, mapid, difficulty, 0));
@@ -574,12 +574,25 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b
Map const *map = sMapMgr.CreateBaseMap(mapid); // _not_ include difficulty
MapInstanced::InstancedMaps &instMaps = ((MapInstanced*)map)->GetInstancedMaps();
MapInstanced::InstancedMaps::iterator mitr;
uint32 timeLeft;
for (mitr = instMaps.begin(); mitr != instMaps.end(); ++mitr)
{
Map *map2 = mitr->second;
if (!map2->IsDungeon()) continue;
if (warn) ((InstanceMap*)map2)->SendResetWarnings(timeLeft);
else ((InstanceMap*)map2)->Reset(INSTANCE_RESET_GLOBAL);
if (!map2->IsDungeon())
continue;
if (warn)
{
if (now <= resetTime)
timeLeft = 0;
else
timeLeft = uint32(now - resetTime);
((InstanceMap*)map2)->SendResetWarnings(timeLeft);
}
else
((InstanceMap*)map2)->Reset(INSTANCE_RESET_GLOBAL);
}
// TODO: delete creature/gameobject respawn times even if the maps are not loaded
+1 -1
View File
@@ -177,7 +177,7 @@ class InstanceSaveManager
private:
void _ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, uint32 timeleft);
void _ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, time_t resetTime);
void _ResetInstance(uint32 mapid, uint32 instanceId);
void _ResetSave(InstanceSaveHashMap::iterator &itr);
void _DelHelper(const char *fields, const char *table, const char *queryTail,...);