Expanding Server's Rebooting Period

Development assistance and tutorials here.
Post Reply
Nelsona
Posts: 1728
Joined: Sat Sep 30, 2017 5:03 am

Expanding Server's Rebooting Period

Post by Nelsona »

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:

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
}
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.
UncodeX Stuff
Not often maintained
My UT Mapping works...
Learn the rules like a pro, so you can break them like an artist.
- Pablo Picasso -
Nelsona
Posts: 1728
Joined: Sat Sep 30, 2017 5:03 am

Re: Expanding Server's Rebooting Period

Post by Nelsona »

On request, I will modify the ServerReset actor to make it a little more flexible. The INI file will have the same format, only it will recognize the word "Daily". If this word is used instead of the name of the day of the week you want to restart, then the server will be restarted every day.
If it is found to work without errors it will be updated in the Sniper Server.

Code: Select all

//---------------------------------------------------
//ServerReset
//---------------------------------------------------
class ServerReset expands Actor config(ServerReset);

//**** Configuration
var() config int ResetHour, ResetMinute, ResetSecond;
var() config string ResetDay;
/*
	ResetDay values: Sunday Monday Tuesday Wednesday Thursday Friday Saturday Daily
	Daily - this string means everyday, at the same time, server will exit leaving batch launcher to restart it.
*/
//**** Internal control usage
var() bool bLogTimes, bDoItNow, bDaily;

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;
		case 7: ReadableDay = "Daily";		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;
	if ( !bDaily )
		Day = Level.DayOfWeek;
	else
		Day = 7;

	if ( bLogTimes )
	{
		bLogTimes = False;
		log ("Daily Restart ="@bDaily,'ServerReset');
		Log("Reset Time:   "$ResetDay$":"$ResetHour$":"$ResetMinute$":"$ResetSecond,'ServerReset');
		Log("Current Time: "$GetDayName(Level.DayOfWeek)$":"$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:
	if ( ResetDay ~= "" )
		ResetDay = "Daily";
	bDaily = ( ResetDay ~= "Daily" );
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
}
And then we have two options for restart times: weekly at a scheduled time and daily at that scheduled time.
UncodeX Stuff
Not often maintained
My UT Mapping works...
Learn the rules like a pro, so you can break them like an artist.
- Pablo Picasso -
User avatar
SC]-[WARTZ_{HoF}
Site Admin
Posts: 425
Joined: Wed May 10, 2017 7:08 am

Re: Expanding Server's Rebooting Period

Post by SC]-[WARTZ_{HoF} »

I think daily reset option for sniper is a good thing. Then we can un-suppress script warnings to find bugs. I would say pick between 3-5AM Eastern Time (UTC-05:00).
Nelsona
Posts: 1728
Joined: Sat Sep 30, 2017 5:03 am

Re: Expanding Server's Rebooting Period

Post by Nelsona »

Then I have to look at server-box, I wanna see what format has the date and what time is matching or I have to setup a period when server is mainly empty... except some eternal camper... bugging votes...
UncodeX Stuff
Not often maintained
My UT Mapping works...
Learn the rules like a pro, so you can break them like an artist.
- Pablo Picasso -
Post Reply