Commit a4e5f734 authored by Razer's avatar Razer
Browse files

Added ServerRequest function + WIP extensioncallback

parent fdeaf29c
addMissionEventHandler ["ExtensionCallback", {
params ["_name", "_function", "_data"];
if (_name == "libredex_callback") then {
_this spawn {
params ["_name", "_function", "_data"];
private _handleResponse = {
(missionNamespace getVariable _function) params ["_callFunction","_params"];
if (isNil _callFunction) exitWith {diag_log format ["<ApmsDB>: ERROR: Unable to find function: %1",_callFunction];};
if (_data != "") then {_params append (parseSimpleArray _data)};
_params call _callFunction;
};
if !(isNil {missionNamespace getVariable _callFunction}) then {
call _handleResponse
} else {
// Spawn waituntil thread to wait for SQF to catch up (THIS SHOULD NEVER HAPPEN)
diag_log "<ApmsDB>: WARNING: ";
_timeout = diag_tickTime + 3;
waitUntil {!isNil {missionNamespace getVariable _function} || diag_tickTime > _timeout};
if (diag_tickTime > _timeout) exitWith {diag_log "timeout"};
call _handleResponse
};
};
};
if (_name == "libredex_callin") then {
};
}];
// example usage for load character
_playerUUID = _playerObj getVariable ["pUUID"];
_request = [PROTOCOL_DBCALL_FUNCTION_LOAD_CHAR_CALLBACK,[PROTOCOL_DBCALL_ARGUMENT_PLAYER_UUID,_playerUUID]];
_functionUUID = [_request] call DB_fnc_sendRequest;
_callFunction = "DB_fnc_unserializeCharacter";
_params = [_playerObj];
missionNamespace setVariable [_functionUUID, [_callFunction, _params]];
_request = [PROTOCOL_DBCALL_FUNCTION_LOAD_CHAR_CALLBACK,[PROTOCOL_DBCALL_ARGUMENT_PLAYER_UUID,_playerUUID]];
_data = [_request] call DB_fnc_callExtension;
\ No newline at end of file
/*
* Desolation Redux
* http://desolationredux.com/
* © 2016 - 2020 Desolation Dev Team
*
* This work is licensed under the Arma Public License Share Alike (APL-SA) + Bohemia monetization rights.
* To view a copy of this license, visit:
* https://www.bistudio.com/community/licenses/arma-public-license-share-alike/
* https://www.bistudio.com/monetization/
*/
if(isNil _fnc_scriptNameParent || {_fnc_scriptNameParent == _fnc_scriptName}) exitWith {};
if(isServer) exitWith {_this call (missionNamespace getVariable [_fnc_scriptNameParent,{diag_log format ["<ApmsDB>: ERROR: Function: %1, not found!",_fnc_scriptNameParent]}])};
// Server request
_this remoteExec [_fnc_scriptNameParent,2];
private _timeout = 3; // 3 = default
_timeout = diag_tickTime + _timeout;
// Wait for server response
waitUntil {!(isNil {missionNamespace getVariable ("DB_var_response_" + _fnc_scriptNameParent)}) || diag_tickTime > _timeout};
if (diag_tickTime > _timeout) exitWith {};
private _return = missionNamespace getVariable ("DB_var_response_" + _fnc_scriptNameParent);
missionNamespace setVariable [("DB_var_response_" + _fnc_scriptNameParent),nil];
_return
\ No newline at end of file
......@@ -87,10 +87,14 @@ while{_doswitchloop} do {
// log error
private _error = (_compiledResponse select 1);
if(_error isEqualType []) then {
diag_log format ["<ApmsDB>: ERROR: %1",_error select 1];
for "_i" from 1 to 5 do {
diag_log format ["<ApmsDB>: ERROR: %1",_error select 1];
};
_return = ["error",_error select 0]; // wanted error "code"
} else {
diag_log format ["<ApmsDB>: ERROR: %1",_error];
for "_i" from 1 to 5 do {
diag_log format ["<ApmsDB>: ERROR: %1",_error];
};
_return = ["error",""]; // Return general error message
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment