Not exactly a GM command, unless someone can help me understand Torque 3D enough to make this a client-initiated option, but here's a serverside script to restart the server.
Executed by calling
RestartServer(15); (for example) in the server console, can be canceled by calling
CancelRestart();The following code can be inserted into whatever serverside scripts you have loading, i.e. any script with an exec() line in main.cs, or a new script added as an exec() line there.
- Code: Select all
function RestartServer(%minutes)
{
CancelRestart();
%shutdown = %minutes * 60000;
%one = %shutdown - 60000;
%two = %shutdown - 120000;
%five = %shutdown - 300000;
%ten = %shutdown - 600000;
hack("Initiating server restart in " @ %minutes @ " minutes.");
centerPrintAll("Server going down for restart in " @ %minutes @ " minutes.\n\nPlease ensure you are in a safe area.",15,2);
if (%minutes > 12)
{
$TIMER_TEN = schedule(%ten, 0, "onTimerAnnounce","Server going down for restart in 10 minutes.\n\nPlease ensure you are in a safe area.");
}
if (%minutes > 7)
{
$TIMER_FIVE = schedule(%five, 0, "onTimerAnnounce","Server going down for restart in 5 minutes.\n\nLog out at your earliest convenience.");
}
if (%minutes > 3)
{
$TIMER_TWO = schedule(%two, 0, "onTimerAnnounce","Server going down for restart in 2 minutes.\n\nLog out now!");
}
if (%minutes > 1)
{
$TIMER_ONE = schedule(%one, 0, "onTimerAnnounce","Server going down for restart in 1 minute.\n\nLog out now!");
}
$TIMER_Shutdown = schedule(%shutdown, 0, "onTimerShutdown");
}
function CancelRestart()
{
cancel($TIMER_TEN);
cancel($TIMER_FIVE);
cancel($TIMER_TWO);
cancel($TIMER_ONE);
cancel($TIMER_SHUTDOWN);
}
CancelRestart();
function OnTimerAnnounce(%str)
{
hack("Sending server restart message:" SPC %str);
centerPrintAll(%str,10,2);
}
function onTimerShutdown()
{
hack("Server restart initiated.");
shellExecute("check_server.cmd",$cm_config::worldID);
Quit();
}
and the check_server.cmd batch file:
- Code: Select all
@echo off
REM Delay until server process is closed...
<nul (set/p _any_variable=Waiting for server to exit.)
:WAITCLOSE
<nul (set/p _any_variable=.)
ping ::1 -n 3 >NUL 2>NUL
tasklist /FI "imagename eq ddctd_cm_yo_server.exe" /V | find "world ID %1" >NUL && goto :WAITCLOSE
echo done.
ping ::1 -n 5 >NUL 2>NUL
:LOOP
REM If server is started, exit batch file.
tasklist /FI "imagename eq ddctd_cm_yo_server.exe" /V | find "world ID %1" >NUL && goto :END
REM If not, try to start it.
echo Launching WorldID %1.
start ddctd_cm_yo_server.exe -WorldID %1
REM Wait 30 seconds before next check to give server time to initialize titlebar with world ID.
echo Waiting 30 seconds to ensure server has started.
PING ::1 -n 30 >NUL 2>NUL
REM Loop to check if server is initialized.
GOTO :LOOP
:END
<EDIT> Tweaked code for functionality with multiple worlds.
<EDIT2> Much improved code. Batch file launch now shows window with status output, and relaunches the server without excessive wait times.