76 lines
2.7 KiB
Plaintext

#include "..\script_component.hpp"
/*
* File: fnc_extCall.sqf
* Author: IDSolutions
* Date: 2026-01-03
* Last Update: 2026-01-03
* Public: No
*
* Description:
* Call Forge Server extension.
*
* Parameter(s):
* 0: Function name to call <STRING>
* 1: Arguments to pass to function <ARRAY>
*
* Returns:
* Extension result <ARRAY>
* Success <BOOL>
*
* Example(s):
* ["icom:connect", ["127.0.0.1:9090", "server_1"]] call forge_x_component_fnc_extCall params ["_result", "_isSuccess"];
*/
params [["_function", "", [""]], ["_arguments", [], [[]]]];
["INFO", format ["Calling function: %1", _function], nil, nil] call EFUNC(common,log);
private _functionLower = toLower _function;
private _requiresRedis = !(_functionLower in ["status", "version"])
&& (_functionLower find "icom:" == 0)
&& (_functionLower find "terrain:" == 0);
if (_requiresRedis) then {
("forge_server" callExtension ["status", []]) params ["_redisStatus", "_statusExtCode", "_statusArmaCode"];
private _statusSuccess = (_statusExtCode == 0) && (_statusArmaCode == 0 || _statusArmaCode == 301);
if (!_statusSuccess) exitWith {
["WARNING", "Unable to determine Redis status before extension call", nil, nil] call EFUNC(common,log);
["Error: Redis status check failed", false]
};
if (_redisStatus != "connected") exitWith {
["WARNING", format ["Blocked extension call '%1' because Redis status is '%2'", _function, _redisStatus], nil, nil] call EFUNC(common,log);
[format ["Error: Redis is %1", _redisStatus], false]
};
};
("forge_server" callExtension [_function, _arguments]) params ["_result", "_extCode", "_armaCode"];
private _success = true;
if (_armaCode != 0 && _armaCode != 301) then {
_success = false;
private _armaCodeMessage = createHashMapFromArray [
[101, "SYNTAX_ERROR_WRONG_PARAMS_SIZE"],
[102, "SYNTAX_ERROR_WRONG_PARAMS_TYPE"],
[201, "PARAMS_ERROR_TOO_MANY_ARGS"],
// [301, "EXECUTION_WARNING_TAKES_TOO_LONG"],
[400, "EXTENSION_LOAD_FAILED"],
[403, "EXTENSION_BLOCKED_BY_BATTLEYE"],
[404, "EXTENSION_NOT_FOUND"]
] getOrDefault [_armaCode, format ["UNKNOWN_%1", _armaCode]];
["WARNING", format ["Arma error: %1", _armaCodeMessage], nil, nil] call EFUNC(common,log);
};
if (_extCode != 0) then {
_success = false;
if (_extCode == -1) exitWith { ["WARNING", "Extension not available", nil, nil] call EFUNC(common,log); };
if (_extCode == 9) exitWith { ["WARNING", format ["Extension error: %1", _result], nil, nil] call EFUNC(common,log); };
["WARNING", format ["Extension error: %1", _extCode], nil, nil] call EFUNC(common,log);
};
[_result, _success]