From 594d5a2a86647ec04067179d9c0edc798628abd8 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sun, 21 Jan 2018 10:42:15 -0500 Subject: [PATCH] Allows silent reboots from in game --- DMAPI/server_tools.dm | 5 +++-- DMAPI/st_interface.dm | 4 ++-- TGS.Server/Instance/DreamDaemon.cs | 17 ++++++++++++++--- TGS.Server/Instance/Interop.cs | 9 +++++++-- Tools/Test.dm | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/DMAPI/server_tools.dm b/DMAPI/server_tools.dm index 8d48cc081b..2540dac4ba 100644 --- a/DMAPI/server_tools.dm +++ b/DMAPI/server_tools.dm @@ -1,5 +1,5 @@ // /tg/station 13 server tools API -#define SERVICE_API_VERSION_STRING "3.2.0.2" +#define SERVICE_API_VERSION_STRING "3.2.0.3" //CONFIGURATION //use this define if you want to do configuration outside of this file @@ -47,7 +47,7 @@ //Forces a hard reboot of BYOND by ending the process //unlike del(world) clients will try to reconnect //If the service has not requested a shutdown, the world will reboot shortly after -#define SERVER_TOOLS_REBOOT_BYOND world.ServiceEndProcess() +#define SERVER_TOOLS_REBOOT_BYOND(silent) world.ServiceEndProcess(silent) /* Gets the list of any testmerged github pull requests @@ -93,6 +93,7 @@ #define SERVICE_JSON_PARAM_REQUIREDPARAMETERS "required_parameters" #define SERVICE_REQUEST_KILL_PROCESS "killme" +#define SERVICE_REQUEST_KILL_PROCESS_SILENT "killmesilent" #define SERVICE_REQUEST_IRC_BROADCAST "irc" #define SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE "send2irc" #define SERVICE_REQUEST_WORLD_REBOOT "worldreboot" diff --git a/DMAPI/st_interface.dm b/DMAPI/st_interface.dm index 25a829da14..931ab10ff3 100644 --- a/DMAPI/st_interface.dm +++ b/DMAPI/st_interface.dm @@ -47,10 +47,10 @@ SERVER_TOOLS_DEFINE_AND_SET_GLOBAL(server_tools_api_compatible, FALSE) /world/proc/AdminBroadcast(message) ExportService("[SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE] [message]") -/world/proc/ServiceEndProcess() +/world/proc/ServiceEndProcess(silent = FALSE) SERVER_TOOLS_LOG("Sending shutdown request!"); sleep(world.tick_lag) //flush the buffers - ExportService(SERVICE_REQUEST_KILL_PROCESS) + ExportService(silent ? SERVICE_REQUEST_KILL_PROCESS_SILENT : SERVICE_REQUEST_KILL_PROCESS) //called at the exact moment the world is supposed to reboot /world/proc/ServiceReboot() diff --git a/TGS.Server/Instance/DreamDaemon.cs b/TGS.Server/Instance/DreamDaemon.cs index 8dc4ffe85b..347514d1c7 100644 --- a/TGS.Server/Instance/DreamDaemon.cs +++ b/TGS.Server/Instance/DreamDaemon.cs @@ -246,7 +246,7 @@ namespace TGS.Server } //handle a kill request from the server - public void KillMe() + public void KillMe(bool silent) { bool DoRestart; lock (watchdogLock) @@ -257,7 +257,7 @@ namespace TGS.Server } //Do this is a seperate thread or we'll kill this thread in the middle of rebooting if (DoRestart) - ThreadPool.QueueUserWorkItem(_ => { Restart(); }); + ThreadPool.QueueUserWorkItem(_ => { RestartImpl(silent); }); else ThreadPool.QueueUserWorkItem(_ => { Stop(); }); } @@ -267,13 +267,24 @@ namespace TGS.Server { if (DaemonStatus() == DreamDaemonStatus.Offline) return Start(); + return RestartImpl(false); + } + + /// + /// Restarts DD + /// + /// If no chat message will be sent + /// on success, error message on failure + string RestartImpl(bool silent) + { lock (restartLock) { if (RestartInProgress) return "Restart already in progress"; RestartInProgress = true; } - SendMessage("DD: Hard restart triggered", MessageType.WatchdogInfo); + if (!silent) + SendMessage("DD: Hard restart triggered", MessageType.WatchdogInfo); Stop(); var res = Start(); if (res != null) diff --git a/TGS.Server/Instance/Interop.cs b/TGS.Server/Instance/Interop.cs index 6935a842bb..4e4aa22cd7 100644 --- a/TGS.Server/Instance/Interop.cs +++ b/TGS.Server/Instance/Interop.cs @@ -41,6 +41,7 @@ namespace TGS.Server const string SRetSuccess = "SUCCESS"; const string SRKillProcess = "killme"; + const string SRKillProcessSilent = "killmesilent"; const string SRIRCBroadcast = "irc"; const string SRIRCAdminChannelMessage = "send2irc"; const string SRWorldReboot = "worldreboot"; @@ -102,15 +103,19 @@ namespace TGS.Server } if (!APIValid && cmd != SRAPIVersion) - return; //SPEAK THE LANGUAGE!!! + return; //SPEAK THE LANGUAGE!!! + var showKillMessage = true; switch (cmd) { case SRIRCBroadcast: SendMessage("GAME: " + String.Join(" ", splits), MessageType.GameInfo); break; + case SRKillProcessSilent: + showKillMessage = false; + goto case SRKillProcess; case SRKillProcess: - KillMe(); + KillMe(!showKillMessage); break; case SRIRCAdminChannelMessage: SendMessage("RELAY: " + String.Join(" ", splits), MessageType.AdminInfo); diff --git a/Tools/Test.dm b/Tools/Test.dm index 81b545df84..91c97a26d6 100644 --- a/Tools/Test.dm +++ b/Tools/Test.dm @@ -8,7 +8,7 @@ /world/Reboot(reason) SERVER_TOOLS_ON_REBOOT - SERVER_TOOLS_REBOOT_BYOND + SERVER_TOOLS_REBOOT_BYOND(FALSE) /proc/message_admins(event) world << event