#include "..\script_component.hpp"

if (!isServer) exitWith {};

missionNamespace setVariable[QGVAR(raw_cps), 0];
missionNamespace setVariable[QGVAR(cps), 0];

publicVariable QGVAR(raw_cps);
publicVariable QGVAR(cps);

[
	LEVEL_INFO,
	QUOTE(COMPONENT),
	"Initializing server stats PFH",
	[]
] call EFUNC(common,log);

_serverCpsPFH = [
	{ 
		[] call FUNC(calculateServerStats);
	},
	QGVAR(server_cps_interval) call CBA_settings_fnc_get,
	[],
	{ 
		[
			LEVEL_INFO,
			QUOTE(COMPONENT),
			"Server PFH loaded",
			[["pfhInterval", QGVAR(server_cps_interval) call CBA_settings_fnc_get]]
		] call EFUNC(common,log);
	},
	{ 	[
			LEVEL_INFO,
			QUOTE(COMPONENT),
			"Server PFH unloaded",
			[]
		] call EFUNC(common,log);
	},
	{ QGVAR(server_cps_enable) call CBA_settings_fnc_get },
	{ false },
	[]
] call CBA_fnc_createPerFrameHandlerObject;


missionNamespace setVariable [QGVAR(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;
