From fa8311ed9789cc5491e7e2e9b8e8c35b86397ecf Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Mon, 16 Aug 2021 16:26:25 -0400 Subject: [PATCH] Add rollover safety check --- code/_helpers/time.dm | 14 ++++++++++++-- code/game/world.dm | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/code/_helpers/time.dm b/code/_helpers/time.dm index 987eed64541..1930f13b29c 100644 --- a/code/_helpers/time.dm +++ b/code/_helpers/time.dm @@ -124,9 +124,19 @@ GLOBAL_VAR_INIT(round_start_time, 0) /var/midnight_rollovers = 0 /var/rollovercheck_last_timeofday = 0 +/var/rollover_safety_date = 0 // set in world/New to the server startup day-of-month /proc/update_midnight_rollover() - if (world.timeofday < rollovercheck_last_timeofday) //TIME IS GOING BACKWARDS! - midnight_rollovers += 1 + // Day has wrapped (world.timeofday drops to 0 at the start of each real day) + if (world.timeofday < rollovercheck_last_timeofday) + // Compare the last wrap date (or server startup date) to our current date + var/curday = text2num(time2text(world.timeofday, "DD")) + // If the date is the same as the startup or last wrap, we should avoid wrapping, may be clock adjustment + // note that this won't protect against going from 00:01 to 23:59 and crossing the boundary again + if(rollover_safety_date != curday) + midnight_rollovers++ + rollover_safety_date = curday + else + warning("Time rollover error: world.timeofday decreased from previous check, but date remained the same. System clock?") rollovercheck_last_timeofday = world.timeofday return midnight_rollovers diff --git a/code/game/world.dm b/code/game/world.dm index bad01f2a082..c62f2e35b09 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -1,6 +1,7 @@ #define RECOMMENDED_VERSION 501 /world/New() world_startup_time = world.timeofday + rollover_safety_date = text2num(time2text(world_startup_time, "DD")) to_world_log("Map Loading Complete") //logs //VOREStation Edit Start