diff --git a/code/controllers/configuration/entries/config.dm b/code/controllers/configuration/entries/config.dm index 39739593fc..d7dc0ff84d 100644 --- a/code/controllers/configuration/entries/config.dm +++ b/code/controllers/configuration/entries/config.dm @@ -381,3 +381,7 @@ CONFIG_TWEAK(flag/ValidateAndSet(str_val)) . = ..() if(. && Master.current_runlevel) world.sleep_offline = !value + +CONFIG_DEF(number/rounds_until_hard_restart) + value = -1 + min_val = 0 diff --git a/code/game/world.dm b/code/game/world.dm index 9a72794553..2853bb2ef6 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -1,4 +1,7 @@ +#define RESTART_COUNTER_PATH "data/round_counter.txt" + GLOBAL_VAR(security_mode) +GLOBAL_VAR(restart_counter) GLOBAL_PROTECT(security_mode) /world/New() @@ -31,6 +34,10 @@ GLOBAL_PROTECT(security_mode) GLOB.timezoneOffset = text2num(time2text(0,"hh")) * 36000 + if(fexists(RESTART_COUNTER_PATH)) + GLOB.restart_counter = text2num(trim(file2text(RESTART_COUNTER_PATH))) + fdel(RESTART_COUNTER_PATH) + Master.Initialize(10, FALSE) @@ -161,6 +168,27 @@ GLOBAL_PROTECT(security_mode) else to_chat(world, "Rebooting world...") Master.Shutdown() //run SS shutdowns + + if(SERVER_TOOLS_PRESENT) + var/do_hard_reboot + // check the hard reboot counter + var/ruhr = CONFIG_GET(number/rounds_until_hard_restart) + switch(ruhr) + if(-1) + do_hard_reboot = FALSE + if(0) + do_hard_reboot = TRUE + else + if(GLOB.restart_counter >= ruhr) + do_hard_reboot = TRUE + else + text2file("[++GLOB.restart_counter]", RESTART_COUNTER_PATH) + do_hard_reboot = FALSE + + if(do_hard_reboot) + log_world("World hard rebooted at [time_stamp()]") + SERVER_TOOLS_REBOOT_BYOND + log_world("World rebooted at [time_stamp()]") ..() diff --git a/config/config.txt b/config/config.txt index 34f11a8c7c..a05e463f45 100644 --- a/config/config.txt +++ b/config/config.txt @@ -383,3 +383,6 @@ DISABLE_HIGH_POP_MC_MODE_AMOUNT 60 ## Uncomment to prevent the world from sleeping while no players are connected after initializations #RESUME_AFTER_INITIALIZATIONS + +## Uncomment to set the number of /world/Reboot()s before the DreamDaemon restarts itself. 0 means restart every round. Requires tgstation server tools. +#ROUNDS_UNTIL_HARD_RESTART 10