Files
RangerMetrics/@RangerMetrics/addons/RangerMetrics/functions/callbackHandlers/fn_callbackHandler.sqf

84 lines
2.2 KiB
Plaintext

params ["_name", "_function", "_data"];
if !(_name == "RangerMetrics") exitWith {};
// Validate data param
if (isNil "_data") then {_data = ""};
if (_data isEqualTo "") exitWith {
[
format ["Callback empty data: %1", _function],
"WARN"
] call RangerMetrics_fnc_log;
false;
};
// Parse response from string array
private "_response";
try {
// diag_log format ["Raw callback: %1: %2", _function, _data];
_response = parseSimpleArray _data;
} catch {
[
format ["Callback invalid data: %1: %2", _function, _data],
"WARN"
] call RangerMetrics_fnc_log;
};
switch (_function) do {
case "loadSettingsJSON": {
[_function, _response] call RangerMetrics_callback_fnc_loadSettings;
};
case "loadSettings": {
// Load settings
[_function, _response] call RangerMetrics_callback_fnc_loadSettings;
};
case "extensionReady": {
// deinitialize existing captures
if (!isNil "RangerMetrics_allMEH") then {
{
private _handle = missionNamespace getVariable _x;
if (isNil "_handle") then {continue};
private _EHName = (_x splitString "_") select 2;
removeMissionEventHandler [_EHName, _handle];
missionNamespace setVariable [_x, nil];
} forEach RangerMetrics_allMEH;
};
if (!isNil "RangerMetrics_allCBA") then {
{
private _handle = missionNamespace getVariable _x;
if (isNil "_handle") then {continue};
private _EHName = (_x splitString "_") select 2;
[_EHName, _handle] call CBA_fnc_removeEventHandler;
missionNamespace setVariable [_x, nil];
} forEach RangerMetrics_allCBA;
};
if (!isNil "RangerMetrics_allServerPoll") then {
{
private _handle = missionNamespace getVariable _x;
if (isNil "_handle") then {continue};
terminate _handle;
missionNamespace setVariable [_x, nil];
} forEach RangerMetrics_allServerPoll;
};
if (!isNil "RangerMetrics_sendHandler") then {
[RangerMetrics_sendHandler] call CBA_fnc_removePerFrameHandler;
missionNamespace setVariable ["RangerMetrics_sendHandler", nil];
};
if (
missionNamespace getVariable [
"RangerMetrics_run",
false
]
) then {
call RangerMetrics_fnc_initCapture;
};
};
default {
_response call RangerMetrics_fnc_log;
};
};