mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 22:48:20 +01:00
Merge pull request #476 from Cyberboss/SilentRestart
Allows silent reboots from in game
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restarts DD
|
||||
/// </summary>
|
||||
/// <param name="silent">If <see langword="false"/> no chat message will be sent</param>
|
||||
/// <returns><see langword="null"/> on success, error message on failure</returns>
|
||||
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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user