mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Instance: stop updating the instance resettimes based on creature respawns
- Rather update normal instance reset time to 2 hours after last creature kill - This fixes yet another integer overflow due to the possibility of having time_t max showing up - Also change respawntime and resettime fields to bigint on respawn/instance related tables - Start using prepared statements on the InstanceSaveMgr
This commit is contained in:
@@ -155,7 +155,7 @@ void InstanceSaveManager::RemoveInstanceSave(uint32 InstanceId)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_INSTANCE_RESETTIME);
|
||||
|
||||
stmt->setUInt32(0, uint32(resettime));
|
||||
stmt->setUInt64(0, uint64(resettime));
|
||||
stmt->setUInt32(1, InstanceId);
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
@@ -209,7 +209,7 @@ void InstanceSave::SaveToDB()
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_INSTANCE_SAVE);
|
||||
stmt->setUInt32(0, m_instanceid);
|
||||
stmt->setUInt16(1, GetMapId());
|
||||
stmt->setUInt32(2, uint32(GetResetTimeForDB()));
|
||||
stmt->setUInt64(2, uint64(GetResetTimeForDB()));
|
||||
stmt->setUInt8(3, uint8(GetDifficulty()));
|
||||
stmt->setUInt32(4, completedEncounters);
|
||||
stmt->setString(5, data);
|
||||
@@ -315,8 +315,7 @@ void InstanceSaveManager::LoadResetTimes()
|
||||
typedef std::pair<ResetTimeMapDiffInstances::const_iterator, ResetTimeMapDiffInstances::const_iterator> ResetTimeMapDiffInstancesBounds;
|
||||
ResetTimeMapDiffInstances mapDiffResetInstances;
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT id, map, difficulty, resettime FROM instance ORDER BY id ASC");
|
||||
if (result)
|
||||
if (QueryResult result = CharacterDatabase.Query("SELECT id, map, difficulty, resettime FROM instance ORDER BY id ASC"))
|
||||
{
|
||||
do
|
||||
{
|
||||
@@ -332,7 +331,7 @@ void InstanceSaveManager::LoadResetTimes()
|
||||
// Mark instance id as being used
|
||||
sMapMgr->RegisterInstanceId(instanceId);
|
||||
|
||||
if (time_t resettime = time_t(fields[3].GetUInt32()))
|
||||
if (time_t resettime = time_t(fields[3].GetUInt64()))
|
||||
{
|
||||
uint32 mapid = fields[1].GetUInt16();
|
||||
uint32 difficulty = fields[2].GetUInt8();
|
||||
@@ -343,24 +342,6 @@ void InstanceSaveManager::LoadResetTimes()
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
// update reset time for normal instances with the max creature respawn time + X hours
|
||||
if (PreparedQueryResult result2 = CharacterDatabase.Query(CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAX_CREATURE_RESPAWNS)))
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result2->Fetch();
|
||||
uint32 instance = fields[1].GetUInt32();
|
||||
time_t resettime = time_t(fields[0].GetUInt32() + 2 * HOUR);
|
||||
InstResetTimeMapDiffType::iterator itr = instResetTime.find(instance);
|
||||
if (itr != instResetTime.end() && itr->second.second != resettime)
|
||||
{
|
||||
CharacterDatabase.DirectPExecute("UPDATE instance SET resettime = '" UI64FMTD "' WHERE id = '%u'", uint64(resettime), instance);
|
||||
itr->second.second = resettime;
|
||||
}
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
|
||||
// schedule the reset times
|
||||
for (InstResetTimeMapDiffType::iterator itr = instResetTime.begin(); itr != instResetTime.end(); ++itr)
|
||||
if (itr->second.second > now)
|
||||
@@ -369,28 +350,37 @@ void InstanceSaveManager::LoadResetTimes()
|
||||
|
||||
// load the global respawn times for raid/heroic instances
|
||||
uint32 diff = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR) * HOUR;
|
||||
result = CharacterDatabase.Query("SELECT mapid, difficulty, resettime FROM instance_reset");
|
||||
if (result)
|
||||
if (QueryResult result = CharacterDatabase.Query("SELECT mapid, difficulty, resettime FROM instance_reset"))
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 mapid = fields[0].GetUInt16();
|
||||
Difficulty difficulty = Difficulty(fields[1].GetUInt8());
|
||||
uint64 oldresettime = fields[2].GetUInt32();
|
||||
uint64 oldresettime = fields[2].GetUInt64();
|
||||
|
||||
MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
|
||||
if (!mapDiff)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "InstanceSaveManager::LoadResetTimes: invalid mapid(%u)/difficulty(%u) pair in instance_reset!", mapid, difficulty);
|
||||
CharacterDatabase.DirectPExecute("DELETE FROM instance_reset WHERE mapid = '%u' AND difficulty = '%u'", mapid, difficulty);
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GLOBAL_INSTANCE_RESETTIME);
|
||||
stmt->setUInt16(0, uint16(mapid));
|
||||
stmt->setUInt8(1, uint8(difficulty));
|
||||
CharacterDatabase.DirectExecute(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
// update the reset time if the hour in the configs changes
|
||||
uint64 newresettime = (oldresettime / DAY) * DAY + diff;
|
||||
if (oldresettime != newresettime)
|
||||
CharacterDatabase.DirectPExecute("UPDATE instance_reset SET resettime = '%u' WHERE mapid = '%u' AND difficulty = '%u'", uint32(newresettime), mapid, difficulty);
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
|
||||
stmt->setUInt64(0, uint64(newresettime));
|
||||
stmt->setUInt16(1, uint16(mapid));
|
||||
stmt->setUInt8(2, uint8(difficulty));
|
||||
CharacterDatabase.DirectExecute(stmt);
|
||||
}
|
||||
|
||||
InitializeResetTimeFor(mapid, difficulty, newresettime);
|
||||
} while (result->NextRow());
|
||||
@@ -417,7 +407,12 @@ void InstanceSaveManager::LoadResetTimes()
|
||||
{
|
||||
// initialize the reset time
|
||||
t = today + period + diff;
|
||||
CharacterDatabase.DirectPExecute("INSERT INTO instance_reset VALUES ('%u', '%u', '%u')", mapid, difficulty, (uint32)t);
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GLOBAL_INSTANCE_RESETTIME);
|
||||
stmt->setUInt16(0, uint16(mapid));
|
||||
stmt->setUInt8(1, uint8(difficulty));
|
||||
stmt->setUInt64(2, uint64(t));
|
||||
CharacterDatabase.DirectExecute(stmt);
|
||||
}
|
||||
|
||||
if (t < now)
|
||||
@@ -426,7 +421,12 @@ void InstanceSaveManager::LoadResetTimes()
|
||||
// calculate the next reset time
|
||||
t = (t / DAY) * DAY;
|
||||
t += ((today - t) / period + 1) * period + diff;
|
||||
CharacterDatabase.DirectPExecute("UPDATE instance_reset SET resettime = '" UI64FMTD "' WHERE mapid = '%u' AND difficulty= '%u'", (uint64)t, mapid, difficulty);
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
|
||||
stmt->setUInt64(0, uint64(t));
|
||||
stmt->setUInt16(1, uint16(mapid));
|
||||
stmt->setUInt8(2, uint8(difficulty));
|
||||
CharacterDatabase.DirectExecute(stmt);
|
||||
}
|
||||
|
||||
InitializeResetTimeFor(mapid, difficulty, t);
|
||||
@@ -678,7 +678,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b
|
||||
// Update it in the DB
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
|
||||
|
||||
stmt->setUInt32(0, next_reset);
|
||||
stmt->setUInt64(0, uint64(next_reset));
|
||||
stmt->setUInt16(1, uint16(mapid));
|
||||
stmt->setUInt8(2, uint8(difficulty));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user