From cc1d20f0490277a006f0cc63ba92ce1fc2e42127 Mon Sep 17 00:00:00 2001 From: Rob Nelson Date: Tue, 17 Sep 2013 04:50:35 -0700 Subject: [PATCH] Add system to let the restart script know when a round ends so it doesn't kill the round. --- baystation12.dme | 1 + code/game/gamemodes/gameticker.dm | 18 +++++++++++++----- code/game/gamemodes/malfunction/malfunction.dm | 4 ++++ code/game/gamemodes/nuclear/nuclearbomb.dm | 5 +++++ code/modules/admin/admin.dm | 10 ++++++++++ code/modules/ext_scripts/python.dm | 2 +- code/modules/ext_scripts/watchdog.dm | 17 +++++++++++++++++ 7 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 code/modules/ext_scripts/watchdog.dm diff --git a/baystation12.dme b/baystation12.dme index c562d1b3e2c..0e24bb68709 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -842,6 +842,7 @@ #include "code\modules\events\wallrot.dm" #include "code\modules\ext_scripts\irc.dm" #include "code\modules\ext_scripts\python.dm" +#include "code\modules\ext_scripts\watchdog.dm" #include "code\modules\flufftext\Dreaming.dm" #include "code\modules\flufftext\Hallucination.dm" #include "code\modules\flufftext\TextFilters.dm" diff --git a/code/game/gamemodes/gameticker.dm b/code/game/gamemodes/gameticker.dm index c09a33a620d..401f12bbb32 100644 --- a/code/game/gamemodes/gameticker.dm +++ b/code/game/gamemodes/gameticker.dm @@ -302,7 +302,13 @@ var/global/datum/controller/gameticker/ticker emergency_shuttle.process() - var/mode_finished = mode.check_finished() || (emergency_shuttle.location == 2 && emergency_shuttle.alert == 1) + var/force_round_end=0 + + // If server's empty, force round end. + if(watchdog.waiting && player_list.len == 0) + force_round_end=1 + + var/mode_finished = mode.check_finished() || (emergency_shuttle.location == 2 && emergency_shuttle.alert == 1) || force_round_end if(!mode.explosion_in_progress && mode_finished) current_state = GAME_STATE_FINISHED @@ -312,18 +318,20 @@ var/global/datum/controller/gameticker/ticker spawn(50) if (mode.station_was_nuked) feedback_set_details("end_proper","nuke") - if(!delay_end) + if(!delay_end && !watchdog.waiting) world << "\blue Rebooting due to destruction of station in [restart_timeout/10] seconds" else feedback_set_details("end_proper","proper completion") - if(!delay_end) + if(!delay_end && !watchdog.waiting) world << "\blue Restarting in [restart_timeout/10] seconds" - if(blackbox) blackbox.save_all_data_to_sql() - if(!delay_end) + if (watchdog.waiting) + world << "\blue Server will shut down for an automatic update in a few seconds." + watchdog.signal_ready() + else if(!delay_end) sleep(restart_timeout) if(!delay_end) world.Reboot() diff --git a/code/game/gamemodes/malfunction/malfunction.dm b/code/game/gamemodes/malfunction/malfunction.dm index 69eda2a405b..a8c2d4ac0a8 100644 --- a/code/game/gamemodes/malfunction/malfunction.dm +++ b/code/game/gamemodes/malfunction/malfunction.dm @@ -47,6 +47,10 @@ if(blackbox) blackbox.save_all_data_to_sql() + if (watchdog.waiting) + world << "\blue Server will shut down for an automatic update in a few seconds." + watchdog.signal_ready() + return sleep(50) world.Reboot() return diff --git a/code/game/gamemodes/nuclear/nuclearbomb.dm b/code/game/gamemodes/nuclear/nuclearbomb.dm index 7480555d694..a1d117d1d92 100644 --- a/code/game/gamemodes/nuclear/nuclearbomb.dm +++ b/code/game/gamemodes/nuclear/nuclearbomb.dm @@ -306,6 +306,11 @@ var/bomb_set if(blackbox) blackbox.save_all_data_to_sql() + + if (watchdog.waiting) + world << "\blue Server will shut down for an automatic update in a few seconds." + watchdog.signal_ready() + return sleep(300) log_game("Rebooting due to nuclear detonation") world.Reboot() diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index c0c5537bb50..04f25e4ada8 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -685,6 +685,11 @@ var/global/floorIsLava = 0 if(blackbox) blackbox.save_all_data_to_sql() + if (watchdog.waiting) + world << "\blue Server will shut down for an automatic update in a few seconds." + watchdog.signal_ready() + return + sleep(50) world.Reboot() @@ -871,6 +876,11 @@ var/global/floorIsLava = 0 if(blackbox) blackbox.save_all_data_to_sql() + if (watchdog.waiting) + world << "\blue Server will shut down for an automatic update in a few seconds." + watchdog.signal_ready() + return + world.Reboot() /datum/admins/proc/unprison(var/mob/M in mob_list) diff --git a/code/modules/ext_scripts/python.dm b/code/modules/ext_scripts/python.dm index 9b798d80cae..a6e578635d3 100644 --- a/code/modules/ext_scripts/python.dm +++ b/code/modules/ext_scripts/python.dm @@ -6,4 +6,4 @@ var/command = config.python_path + " " + script + " " + args - return shell(command) + return shell(command) \ No newline at end of file diff --git a/code/modules/ext_scripts/watchdog.dm b/code/modules/ext_scripts/watchdog.dm new file mode 100644 index 00000000000..5fa7b0b683f --- /dev/null +++ b/code/modules/ext_scripts/watchdog.dm @@ -0,0 +1,17 @@ +var/global/datum/watchdog/watchdog = new + +/datum/watchdog + var/waiting=0 // Waiting for the server to end round or empty. + var/const/update_signal_file="data/UPDATE_READY.txt" + var/const/server_signal_file="data/SERVER_READY.txt" + +/datum/watchdog/proc/check_for_update() + if(waiting) + return + if(fexists(update_signal_file) == 1) + waiting=1 + +/datum/watchdog/proc/signal_ready() + var/signal = file(server_signal_file) + fdel(signal) + signal << "READY" \ No newline at end of file