Expanding Server's Rebooting Period
Posted: Mon Oct 07, 2019 5:37 pm
The older version of this tool used in the Sniper Server was basically for daily restart. A weekly restart was requested at a certain time. Here is what we have below:
The question is asked if you want something more extended, for example for certain days of the week, even twice a week or something like that. If not, we'll leave it that simple for a certain day of the week. For installation on the server we will need a break, probably the operation is recommended at a time when there are not many players connected.
No package is required to be sent to the player, it is all based on the native replication used by the PlayerPawn class.
Code: Select all
//---------------------------------------------------
//ServerReset
//---------------------------------------------------
class ServerReset expands Actor config(ServerReset);
var() config int ResetHour;
var() config int ResetMinute;
var() config int ResetSecond;
var() config string ResetDay;
var() bool bLogTimes, bDoItNow;
event PreBeginPlay()
{
}
function PostBeginPlay()
{
bLogTimes = True;
bDoItNow = False;
InitialState = 'Monitoring';
}
final function String GetDayName(int Day)
{
local String ReadableDay;
switch(Day)
{
case 0: ReadableDay = "Sunday"; break;
case 1: ReadableDay = "Monday"; break;
case 2: ReadableDay = "Tuesday"; break;
case 3: ReadableDay = "Wednesday"; break;
case 4: ReadableDay = "Thursday"; break;
case 5: ReadableDay = "Friday"; break;
case 6: ReadableDay = "Saturday"; break;
}
if ( ReadableDay != "" )
return ReadableDay;
else
return "Bork";
}
function ShowColorizedMessage(PlayerPawn T)
{
local bool bInvalid;
local color clMsg, WhiteColor;
local int i;
bInvalid = ( T == None || T.bDeleteMe );
if ( !bInvalid )
{
T.ClearProgressMessages();
WhiteColor.R=255;
WhiteColor.G=255;
WhiteColor.B=255;
clMsg.R=255;
clMsg.G=128;
clMsg.B=0;
T.SetProgressColor(clMsg,i);
T.SetProgressMessage("The server will execute the scheduled restart !",i++);
T.SetProgressColor(WhiteColor,i);
T.SetProgressMessage("Will be active again shortly. It takes less than a minute.",i++);
T.SetProgressTime(4);
}
}
function AnnounceReset()
{
local PlayerPawn T;
foreach AllActors(class 'PlayerPawn',T)
{
if ( !T.bDeleteMe )
ShowColorizedMessage(T);
}
}
final function TimeCheck()
{
local int Hr, Min, Sec, Day;
if ( bDoItNow )
{
log ("Executing Exit command for scheduled restart...",'ServerReset');
ConsoleCommand("EXIT");
return;
}
Hr = Level.Hour;
Min = Level.Minute;
Sec = Level.Second;
Day = Level.DayOfWeek;
if ( bLogTimes )
{
if ( ResetDay ~= "" )
ResetDay = "Sunday";
bLogTimes = False;
Log("Reset Time: "$ResetDay$":"$ResetHour$":"$ResetMinute$":"$ResetSecond,'ServerReset');
Log("Current Time: "$GetDayName(Day)$":"$Hr$":"$Min$":"$Sec,'ServerReset');
Log("");
}
if ( (Hr == ResetHour) && (Min == ResetMinute) && ( (Sec == ResetSecond) || (Sec == ResetSecond+1) ) && GetDayName(Day) ~= ResetDay )
{
BroadCastMessage("SERVER IS BEING RESET...",True);
bDoItNow = True; //Preserve 1 second for figuring this
}
}
state Monitoring
{
Begin:
Loop:
Sleep(1.00);
if ( bDoItNow )
{
AnnounceReset();
Sleep(4.1);
}
TimeCheck();
GoTo('Loop');
End:
}
defaultproperties
{
ResetHour=2
ResetMinute=0
ResetSecond=0
ResetDay=Sunday
RemoteRole=ROLE_None
NetPriority=2.000000
}
No package is required to be sent to the player, it is all based on the native replication used by the PlayerPawn class.