if (!isServer) exitWith {};

missionNamespace setVariable["milsim_raw_cps", 0];
missionNamespace setVariable["milsim_cps", 0];

publicVariable "milsim_raw_cps";
publicVariable "milsim_cps";

diag_log text format ["[MILSIM] (server) initializing Server Stats PFH"];

_serverCpsPFH = [
	{ 
		[] call milsim_fnc_calculateServerStats;
	},
	"milsim_server_cps_interval" call CBA_settings_fnc_get,
	[],
	{ diag_log text format ["[MILSIM] (server) Server PFH loaded with interval %1 seconds", "milsim_server_cps_interval" call CBA_settings_fnc_get ] },
	{ diag_log text format ["[MILSIM] (server) Server PFH unloaded"] },
	{ "milsim_server_cps_enable" call CBA_settings_fnc_get },
	{ false },
	[]
] call CBA_fnc_createPerFrameHandlerObject;


missionNamespace setVariable ["milsim_server_cps_handler", _serverCpsPFH];

_playerCpsPFH = [
	{ 

		diag_log text "[MILSIM] (server) ** Player Executions **";

		{
			diag_log ( format ["%1: ( %2, %3 )", name _x, _x getVariable ["milsim_player_raw_cps",-1], _x getVariable ["milsim_player_cps",-1] ] )
		} forEach allPlayers;

		diag_log text "[MILSIM] (server) ***********************";

	},
	"milsim_server_cps_interval" call CBA_settings_fnc_get,
	[],
	{ diag_log text format ["[MILSIM] (server) Player PFH loaded"] },
	{ diag_log text format ["[MILSIM] (server) Player PFH unloaded"] },
	{ "milsim_server_cps_enable" call CBA_settings_fnc_get },
	{ false },
	[]
] call CBA_fnc_createPerFrameHandlerObject;

missionNamespace setVariable ["milsim_player_cps_handler", _playerCpsPFH];

nil;
