From 528b74109e8af101ad3a9f76e2dc118c48901820 Mon Sep 17 00:00:00 2001 From: hg <4683435+hgtw@users.noreply.github.com> Date: Tue, 19 May 2020 23:03:36 -0400 Subject: [PATCH] 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 --- zone/dynamiczone.cpp | 10 ++++------ zone/dynamiczone.h | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/zone/dynamiczone.cpp b/zone/dynamiczone.cpp index 5e87e229c..38377fefe 100644 --- a/zone/dynamiczone.cpp +++ b/zone/dynamiczone.cpp @@ -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()) diff --git a/zone/dynamiczone.h b/zone/dynamiczone.h index b2bf22b41..bb2bee16b 100644 --- a/zone/dynamiczone.h +++ b/zone/dynamiczone.h @@ -89,7 +89,7 @@ public: void SetCompass(const DynamicZoneLocation& location, bool update_db = false); void SetSafeReturn(const DynamicZoneLocation& location, bool update_db = false); void SetZoneInLocation(const DynamicZoneLocation& location, bool update_db = false); - void UpdateExpireTime(uint32_t seconds); + void UpdateExpireTime(uint32_t seconds, bool reduce_only = true); void LoadFromDatabase(uint32_t instance_id); uint32_t SaveToDatabase();