Michael Cullen

Realtime Restarts

32 posts in this topic

Want to restart your server at specific times of the day? Sick of manual restarts buggering up your restart cycle?

Then "Realtime Restarts" has got you covered!

 

Changelog

1.0.2
Added the ability to broadcast the time remaining (in minutes) to the next restart to all clients on the server. In client-side scripts (statusbars, alerts, etc) use the following code to retrieve this value.

missionNameSpace getVariable "TimeTilRestart"

1.0.1
Fixed bug causing endless restart cycle after the last entry in the realtimeRestartHours array.

1.0
Initial release!

 

Installation

Replace your ExileServer_system_rcon_thread_check.sqf - found in \exile_server\code\ - with this:

/**
 * ExileServer_system_rcon_thread_check
 *
 * Exile Mod
 * exile.majormittens.co.uk
 * © 2015 Exile Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 *
 * "Realtime Restarts" 1.0.2 by Michael Cullen. No rights reserved.
 */
 
private["_restartTime","_useAutoKick","_kickTime","_lockTime","_uptime","_timeTilRestart","_time","_i","_realtime","_realtimeHours","_realtimeMinutes","_realtimeSinceMidnight","_realtimeRestartHours","_hourCount","_firstRestartHour","_restartHour"];
_restartTime = _this select 0;
_useAutoKick = _this select 1;
_kickTime = _this select 2;
_lockTime = _this select 3;

if(getNumber(configFile >> "CfgSettings" >> "RCON" >> "realtimeRestarts") isEqualTo 1) then {
	_realtime = (call compile ("extDB2" callExtension format["9:TIME:%1", getNumber(configFile >> "CfgSettings" >> "RCON" >> "realtimeOffset")])) select 1;
	_realtimeHours = _realtime select 3;
	_realtimeMinutes = _realtime select 4;
	_realtimeSinceMidnight = (_realtimeHours * 60) + _realtimeMinutes;
	_realtimeRestartHours = getArray (configFile >> "CfgSettings" >> "RCON" >> "realtimeRestartHours");
	_hourCount = (count _realtimeRestartHours) - 1;
	_firstRestartHour = (_realtimeRestartHours select 0) * 60;
	
	for "_i" from 0 to _hourCount do
	{
		_restartHour = (_realtimeRestartHours select _i) * 60;
		if (_restartHour > _realtimeSinceMidnight) exitWith {_restartTime = _restartHour};
		if ((_i == _hourCount) && (((24 * 60) + _firstRestartHour) > _realtimeSinceMidnight)) exitWith { _restartTime = (24 * 60) + _firstRestartHour};
	};

	_timeTilRestart = _restartTime - _realtimeSinceMidnight;
} else {
	_uptime = call ExileServer_util_time_uptime;
	_timeTilRestart = _restartTime - _uptime;
};

if(getNumber(configFile >> "CfgSettings" >> "RCON" >> "broadcastTimeTilRestart") isEqualTo 1) then {
	missionNamespace setVariable ["TimeTilRestart", _timeTilRestart, true];
};

if (typeName ExileServerRestartMessages isEqualTo "ARRAY") then
{
	if !(ExileServerRestartMessages isEqualTo []) then
	{
		{
			_time = _x;
			if (_timeTilRestart < _time) then
			{
				if (count ExileSessionIDs > 0) then
				{
					["toastRequest", ["InfoTitleAndText", ["Restart incoming!", format["Server is going to restart in %1 min! Log out before the restart to prevent gear loss.", _time] ]]] call ExileServer_system_network_send_broadcast;
				};
				ExileServerRestartMessages deleteAt _forEachIndex;
				format ["Restart Warnings for %1min sent",_time] call ExileServer_util_log;
			};
		} 
		forEach ExileServerRestartMessages;
	};
};
if (_timeTilRestart < _lockTime) then
{
	if !(ExileServerIsLocked) then
	{
		"#lock" call ExileServer_system_rcon_event_sendCommand;
		"Server locked for restart" call ExileServer_util_log;
		["toastRequest", ["ErrorTitleAndText", ["Server will restart now!", "You will be kicked off the server due to a restart."]]] call ExileServer_system_network_send_broadcast;
		ExileServerIsLocked = true;
	};
	if (_timeTilRestart < _kickTime) then
	{
		if !(ExileServerRestartMode) then
		{
			call ExileServer_system_rcon_event_kickAllrestart;
			"Everyone kicked for restart" call ExileServer_util_log;
			ExileSystemSpawnThread = [];
			call ExileServer_system_rcon_event_clearBuffers;
			"Buffers cleared!" call ExileServer_util_log;
			for "_i" from 0 to 49 do
			{
				"SERVER READY FOR RESTART!!" call ExileServer_util_log;
			};
			ExileServerRestartMode = true;
			if(getNumber(configFile >> "CfgSettings" >> "RCON" >> "useShutdown") isEqualTo 1)then
			{
				'#shutdown' call ExileServer_system_rcon_event_sendCommand;
			};
		};
	};
};
true

NOTE: You can also use @BetterDeadThanZed's method below to keep the changes in your Mission PBO (may be useful for upgrades, etc).

And add this into the RCON section of your server's config.cpp.

/*
	Restart on a realtime cycle
*/
realtimeRestarts = 1;
realtimeOffset = 1; //Offset from UTC
realtimeRestartHours[] = {0, 4, 8, 12, 16, 20};
broadcastTimeTilRestart = 1;

Adjust your offset and restart times to your liking, repack your PBOs, and you're good to go!

Edited by Michael Cullen
Update to 1.0.2
  • Like 9

Share this post


Link to post
Share on other sites

Hi,

Could you help me by pinpointing were i can find the   ExileServer_system_rcon_thread_check.sqf file at? I have looked in Altis.Exile.pbo and also in Exiler_server_config.pbo and both do not contain that file.

Thanks alot for this tutorial!! Can't wait to set it up!

Share this post


Link to post
Share on other sites
Advertisement
1 hour ago, BiNoX said:

Hi,

Could you help me by pinpointing were i can find the   ExileServer_system_rcon_thread_check.sqf file at? I have looked in Altis.Exile.pbo and also in Exiler_server_config.pbo and both do not contain that file.

Thanks alot for this tutorial!! Can't wait to set it up!

A file with "server" in it is located in @ExileServer\addons\exile_server.pbo. Open that up and go to the "code" folder. The directions are actually kind of poor. You should never edit the files in your exile_server.pbo. That's why the Exile dev team created the "customcode" in the client config.cpp. 

1. In your server's mission pbo file (Where you find the description.ext file), create a folder called custom\restart
2. Create a file in there called ExileServer_system_rcon_thread_check.sqf with the code from the OP.
3. Open your client side config.cpp and find the "class CfgExileCustomCode" section. 
4. In that section, add the following line:

ExileServer_system_rcon_thread_check = "custom\restart\ExileServer_system_rcon_thread_check.sqf";

It should look something like this:

class CfgExileCustomCode 
{
          ExileServer_system_rcon_thread_check = "custom\restart\ExileServer_system_rcon_thread_check.sqf";
};

Depending on what other mods you have, you may have multiple lines in there. Make the other changes explained in the rcon section, above and re-pbo your mission pbo and you're good.

Share this post


Link to post
Share on other sites
7 minutes ago, BetterDeadThanZed said:


2. Create a file in there called ExileServer_system_rcon_thread_check.sqf with the code from the OP.

What's "the code from the OP"? i don't understand that abbreviation? I too need to do this

Share this post


Link to post
Share on other sites
13 minutes ago, BetterDeadThanZed said:

A file with "server" in it is located in @ExileServer\addons\exile_server.pbo. Open that up and go to the "code" folder. The directions are actually kind of poor. You should never edit the files in your exile_server.pbo. That's why the Exile dev team created the "customcode" in the client config.cpp. 

Cheers BDTZ; I haven't done any work with Exile so didn't even know they'd implemented overrides like that. Your method of applying it would definitely be preferable.

  • Like 1

Share this post


Link to post
Share on other sites
36 minutes ago, BetterDeadThanZed said:

You should never edit the files in your exile_server.pbo. That's why the Exile dev team created the "customcode" in the client config.cpp. 

This advice is very "poor."

Why inflate your mission file size when you have zero reason to do that?

If you can't keep track of server files you've modified that's your own fault, doesn't mean you shouldn't do it that way.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, BetterDeadThanZed said:

A file with "server" in it is located in @ExileServer\addons\exile_server.pbo. Open that up and go to the "code" folder. The directions are actually kind of poor. You should never edit the files in your exile_server.pbo. That's why the Exile dev team created the "customcode" in the client config.cpp. 

1. In your server's mission pbo file (Where you find the description.ext file), create a folder called custom\restart
2. Create a file in there called ExileServer_system_rcon_thread_check.sqf with the code from the OP.
3. Open your client side config.cpp and find the "class CfgExileCustomCode" section. 
4. In that section, add the following line:


ExileServer_system_rcon_thread_check = "custom\restart\ExileServer_system_rcon_thread_check.sqf";

It should look something like this:


class CfgExileCustomCode 
{
          ExileServer_system_rcon_thread_check = "custom\restart\ExileServer_system_rcon_thread_check.sqf";
};

Depending on what other mods you have, you may have multiple lines in there. Make the other changes explained in the rcon section, above and re-pbo your mission pbo and you're good.

Followed your instructions server won't load now. getting this log error in my rpt files (a3ds/profiles)

 4:47:36 Error context ExileServer_system_rcon_thread_check = "customrestart\ExileServer_system_rcon_thread_check.sqf";
 4:47:36 Warning Message: File mpmissions\__cur_mp.Tanoa\config.cpp, line 2707: '/CfgExileCustomCode.': '{' encountered instead of '='
 4:47:36 Warning Message: Config : some input after EndOfFile.

Share this post


Link to post
Share on other sites

this override function was built in mainly for overriding some files in the exileclientstuff

if you would change it directly in these files every client on your server would have to download these files from you to have the changes...

if the change is to be done in a serverside file you can change it directly there...

 

imho it would be nice (to keep better track of all your changes etc) if we would have a serverside override option too... without the need to touch the server pbo at all

Edited by AFC~Gagi2~

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.