Only update dz expire time if reducing

Add optional UpdateExpireTime parameter

This is currently only used when an expedition becomes empty to make
dynamic zone instances shutdown earlier. For that it should only update
if new time is less than remaining time
This commit is contained in:
hg
2020-05-19 23:03:36 -04:00
parent e79d03261a
commit e822fdb9cf
2 changed files with 5 additions and 7 deletions
+4 -6
View File
@@ -437,21 +437,19 @@ void DynamicZone::SendInstanceCharacterChange(uint32_t character_id, bool remove
}
}
void DynamicZone::UpdateExpireTime(uint32_t seconds)
void DynamicZone::UpdateExpireTime(uint32_t seconds, bool reduce_only)
{
if (GetInstanceID() == 0)
if (GetInstanceID() == 0 || (reduce_only && GetSecondsRemaining() < seconds))
{
return;
}
m_duration = seconds;
m_expire_time = std::chrono::system_clock::now() + std::chrono::seconds(seconds);
auto new_duration = std::chrono::system_clock::to_time_t(m_expire_time) - m_start_time;
m_duration = std::chrono::system_clock::to_time_t(m_expire_time) - m_start_time;
std::string query = fmt::format(SQL(
UPDATE instance_list SET duration = {} WHERE id = {};
), new_duration, GetInstanceID());
), m_duration, GetInstanceID());
auto results = database.QueryDatabase(query);
if (results.Success())