mirror of
https://github.com/EQEmu/Server.git
synced 2026-02-19 03:22:29 +00:00
Store expedition duration and times as chrono
This simplifies comparisons and reduces conversions
This commit is contained in:
parent
006f7bf9e9
commit
ea0b37b7fc
@ -39,10 +39,10 @@ Expedition::Expedition(
|
||||
m_expedition_id(expedition_id),
|
||||
m_dz_instance_id(instance_id),
|
||||
m_dz_zone_id(dz_zone_id),
|
||||
m_start_time(start_time),
|
||||
m_start_time(std::chrono::system_clock::from_time_t(start_time)),
|
||||
m_duration(duration)
|
||||
{
|
||||
m_expire_time = std::chrono::system_clock::from_time_t(m_start_time + m_duration);
|
||||
m_expire_time = m_start_time + m_duration;
|
||||
}
|
||||
|
||||
void Expedition::SendZonesExpeditionDeleted()
|
||||
@ -60,7 +60,7 @@ void Expedition::SendZonesDurationUpdate()
|
||||
auto pack = std::unique_ptr<ServerPacket>(new ServerPacket(ServerOP_ExpeditionDzDuration, packsize));
|
||||
auto packbuf = reinterpret_cast<ServerExpeditionUpdateDuration_Struct*>(pack->pBuffer);
|
||||
packbuf->expedition_id = GetID();
|
||||
packbuf->new_duration_seconds = m_duration;
|
||||
packbuf->new_duration_seconds = static_cast<uint32_t>(m_duration.count());
|
||||
zoneserver_list.SendPacket(pack.get());
|
||||
}
|
||||
|
||||
@ -78,12 +78,10 @@ void Expedition::UpdateDzSecondsRemaining(uint32_t seconds_remaining)
|
||||
);
|
||||
|
||||
// preserve original start time and adjust duration instead
|
||||
auto new_expire_time = now + update_time;
|
||||
auto new_duration = std::chrono::system_clock::to_time_t(new_expire_time) - m_start_time;
|
||||
m_duration = static_cast<uint32_t>(new_duration);
|
||||
m_expire_time = std::chrono::system_clock::from_time_t(m_start_time + m_duration);
|
||||
m_expire_time = now + update_time;
|
||||
m_duration = std::chrono::duration_cast<std::chrono::seconds>(m_expire_time - m_start_time);
|
||||
|
||||
ExpeditionDatabase::UpdateDzDuration(GetInstanceID(), m_duration);
|
||||
ExpeditionDatabase::UpdateDzDuration(GetInstanceID(), static_cast<uint32_t>(m_duration.count()));
|
||||
|
||||
// update zone level caches and update the actual dz instance's timer
|
||||
SendZonesDurationUpdate();
|
||||
|
||||
@ -93,10 +93,10 @@ private:
|
||||
uint32_t m_expedition_id = 0;
|
||||
uint32_t m_dz_instance_id = 0;
|
||||
uint32_t m_dz_zone_id = 0;
|
||||
uint32_t m_start_time = 0;
|
||||
uint32_t m_duration = 0;
|
||||
bool m_pending_delete = false;
|
||||
std::unordered_set<uint32_t> m_member_ids;
|
||||
std::chrono::seconds m_duration;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_start_time;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_expire_time;
|
||||
};
|
||||
|
||||
|
||||
@ -119,14 +119,15 @@ uint32_t DynamicZone::CreateInstance()
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto start_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
m_start_time = std::chrono::system_clock::now();
|
||||
auto start_time = std::chrono::system_clock::to_time_t(m_start_time);
|
||||
|
||||
std::string query = fmt::format(SQL(
|
||||
INSERT INTO instance_list
|
||||
(id, zone, version, start_time, duration)
|
||||
VALUES
|
||||
({}, {}, {}, {}, {})
|
||||
), instance_id, m_zone_id, m_version, start_time, m_duration);
|
||||
), instance_id, m_zone_id, m_version, start_time, m_duration.count());
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success())
|
||||
@ -136,9 +137,8 @@ uint32_t DynamicZone::CreateInstance()
|
||||
}
|
||||
|
||||
m_instance_id = instance_id;
|
||||
m_start_time = static_cast<uint32_t>(start_time);
|
||||
m_never_expires = false;
|
||||
m_expire_time = std::chrono::system_clock::from_time_t(m_start_time + m_duration);
|
||||
m_expire_time = m_start_time + m_duration;
|
||||
|
||||
return m_instance_id;
|
||||
}
|
||||
@ -178,11 +178,11 @@ void DynamicZone::LoadDatabaseResult(MySQLRequestRow& row)
|
||||
m_instance_id = strtoul(row[0], nullptr, 10);
|
||||
m_zone_id = strtoul(row[1], nullptr, 10);
|
||||
m_version = strtoul(row[2], nullptr, 10);
|
||||
m_start_time = strtoul(row[3], nullptr, 10);
|
||||
m_duration = strtoul(row[4], nullptr, 10);
|
||||
m_start_time = std::chrono::system_clock::from_time_t(strtoul(row[3], nullptr, 10));
|
||||
m_duration = std::chrono::seconds(strtoul(row[4], nullptr, 10));
|
||||
m_expire_time = m_start_time + m_duration;
|
||||
m_never_expires = (strtoul(row[5], nullptr, 10) != 0);
|
||||
m_type = static_cast<DynamicZoneType>(strtoul(row[6], nullptr, 10));
|
||||
m_expire_time = std::chrono::system_clock::from_time_t(m_start_time + m_duration);
|
||||
m_compass.zone_id = strtoul(row[7], nullptr, 10);
|
||||
m_compass.x = strtof(row[8], nullptr);
|
||||
m_compass.y = strtof(row[9], nullptr);
|
||||
@ -530,8 +530,8 @@ uint32_t DynamicZone::GetSecondsRemaining() const
|
||||
void DynamicZone::SetUpdatedDuration(uint32_t new_duration)
|
||||
{
|
||||
// preserves original start time, just modifies duration and expire time
|
||||
m_duration = new_duration;
|
||||
m_expire_time = std::chrono::system_clock::from_time_t(m_start_time + m_duration);
|
||||
m_duration = std::chrono::seconds(new_duration);
|
||||
m_expire_time = m_start_time + m_duration;
|
||||
|
||||
if (zone && IsCurrentZoneDzInstance())
|
||||
{
|
||||
|
||||
@ -110,14 +110,14 @@ private:
|
||||
uint32_t m_zone_id = 0;
|
||||
uint32_t m_instance_id = 0;
|
||||
uint32_t m_version = 0;
|
||||
uint32_t m_start_time = 0;
|
||||
uint32_t m_duration = 0;
|
||||
bool m_never_expires = false;
|
||||
bool m_has_zonein = false;
|
||||
DynamicZoneType m_type = DynamicZoneType::None;
|
||||
DynamicZoneLocation m_compass;
|
||||
DynamicZoneLocation m_safereturn;
|
||||
DynamicZoneLocation m_zonein;
|
||||
std::chrono::seconds m_duration;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_start_time;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_expire_time;
|
||||
};
|
||||
|
||||
|
||||
@ -26,11 +26,12 @@
|
||||
const char* const DZ_REPLAY_TIMER_NAME = "Replay Timer"; // see December 14, 2016 patch notes
|
||||
|
||||
ExpeditionLockoutTimer::ExpeditionLockoutTimer(
|
||||
std::string expedition_name, std::string event_name, uint64_t expire_time, uint32_t duration, bool inherited
|
||||
std::string expedition_name, std::string event_name,
|
||||
uint64_t expire_time, uint32_t duration, bool inherited
|
||||
) :
|
||||
m_expedition_name(expedition_name),
|
||||
m_event_name(event_name),
|
||||
m_expire_time(expire_time),
|
||||
m_expire_time(std::chrono::system_clock::from_time_t(expire_time)),
|
||||
m_duration(duration),
|
||||
m_is_inherited(inherited)
|
||||
{
|
||||
@ -43,11 +44,10 @@ ExpeditionLockoutTimer::ExpeditionLockoutTimer(
|
||||
uint32_t ExpeditionLockoutTimer::GetSecondsRemaining() const
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto expire_time = std::chrono::system_clock::from_time_t(m_expire_time);
|
||||
if (expire_time > now)
|
||||
if (m_expire_time > now)
|
||||
{
|
||||
auto time_remaining = std::chrono::duration_cast<std::chrono::seconds>(expire_time - now).count();
|
||||
return static_cast<uint32_t>(time_remaining);
|
||||
auto remaining = m_expire_time - now;
|
||||
return static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(remaining).count());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#ifndef EXPEDITION_LOCKOUT_TIMER_H
|
||||
#define EXPEDITION_LOCKOUT_TIMER_H
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
extern const char* const DZ_REPLAY_TIMER_NAME;
|
||||
@ -29,7 +30,9 @@ class ExpeditionLockoutTimer
|
||||
{
|
||||
public:
|
||||
ExpeditionLockoutTimer() {}
|
||||
ExpeditionLockoutTimer(std::string expedition_name, std::string event_name, uint64_t expire_time, uint32_t duration, bool inherited = false);
|
||||
ExpeditionLockoutTimer(
|
||||
std::string expedition_name, std::string event_name,
|
||||
uint64_t expire_time, uint32_t duration, bool inherited = false);
|
||||
|
||||
struct DaysHoursMinutes
|
||||
{
|
||||
@ -38,13 +41,13 @@ public:
|
||||
std::string mins;
|
||||
};
|
||||
|
||||
uint32_t GetDuration() const { return m_duration; }
|
||||
uint64_t GetExpireTime() const { return m_expire_time; }
|
||||
uint32_t GetDuration() const { return static_cast<uint32_t>(m_duration.count()); }
|
||||
uint64_t GetExpireTime() const { return std::chrono::system_clock::to_time_t(m_expire_time); }
|
||||
uint32_t GetSecondsRemaining() const;
|
||||
DaysHoursMinutes GetDaysHoursMinutesRemaining() const;
|
||||
const std::string& GetExpeditionName() const { return m_expedition_name; }
|
||||
const std::string& GetEventName() const { return m_event_name; }
|
||||
void SetExpireTime(uint64_t expire_time) { m_expire_time = expire_time; }
|
||||
void SetExpireTime(uint64_t expire_time) { m_expire_time = std::chrono::system_clock::from_time_t(expire_time); }
|
||||
void SetInherited(bool is_inherited) { m_is_inherited = is_inherited; }
|
||||
bool IsExpired() const { return GetSecondsRemaining() == 0; }
|
||||
bool IsInherited() const { return m_is_inherited; }
|
||||
@ -55,10 +58,10 @@ public:
|
||||
private:
|
||||
std::string m_expedition_name;
|
||||
std::string m_event_name;
|
||||
uint64_t m_expire_time = 0;
|
||||
uint32_t m_duration = 0;
|
||||
bool m_is_inherited = false; // inherited from expedition leader
|
||||
bool m_is_replay_timer = false;
|
||||
std::chrono::seconds m_duration;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_expire_time;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user