Commit 087d6279 authored by Razer's avatar Razer
Browse files

Added REST Server Support (libredex_callin)

parent 6fa7e754
......@@ -32,12 +32,12 @@
// Client request
if(!isServer) exitWith {_this call DB_fnc_serverRequest};
params [["_target","",[objNull,""]],["_player","",[objNull,""]]];
params [["_targetParam","",[objNull,""]],["_playerParam","",[objNull,""]]];
private _playerClan = if (_player isEqualType "") then {_player} else {_player getVariable ["clanUUID",""]};
private _playerClan = if (_playerParam isEqualType "") then {_playerParam} else {_playerParam getVariable ["clanUUID",""]};
if (_playerClan == "") exitWith {false};
private _targetClan = if (_target isEqualType "") then {_target} else {_target getVariable ["clanUUID",""]};
private _targetClan = if (_targetParam isEqualType "") then {_targetParam} else {_targetParam getVariable ["clanUUID",""]};
if (_targetClan == "") exitWith {false};
// Return data to client
......
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 compile _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/
*/
/*
// 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]; // Additional params to be added in front of the libredex return array
missionNamespace setVariable [_functionUUID, [_callFunction, _params]];
*/
#include "\ApmsDB\constants.hpp"
private _eventString = "
params ['_name','_function','_params'];
if (_name == 'libredex_callback') then {";
if (DB_DEBUG) then {_eventString = _eventString + "
diag_log '===========================APMSDB EXTENSION CALLBACK==================================';
diag_log format ['<ApmsDB>: DEBUG: TYPE: %1',_name];
diag_log format ['<ApmsDB>: DEBUG: FUNCTION: %1',_function];
diag_log format ['<ApmsDB>: DEBUG: PARAMS: %1',_params];
diag_log '===========================APMSDB EXTENSION CALLBACK===================================';
";
};
_eventString = _eventString + "
_this spawn {
params ['_name','_function','_params'];
_timeout = diag_tickTime + 3;
waitUntil {!isNil {missionNamespace getVariable _function} || diag_tickTime > _timeout};
if (diag_tickTime > _timeout) exitWith {diag_log format ['<ApmsDB>: ERROR: Unable to find callback function UUID: %1',_function]};
(missionNamespace getVariable _function) params ['_callFunction','_params'];
if (_params != '') then {_params append (parseSimpleArray _params)};
_params call (missionNamespace getVariable [_callFunction,{diag_log format ['<ApmsDB>: ERROR: Unable to find function: %1',_callFunction]}]);
};
};
if (_name == 'libredex_callin') then {";
if (DB_DEBUG) then {_eventString = _eventString + "
diag_log '===========================APMSDB EXTENSION CALLBACK===================================';
diag_log format ['<ApmsDB>: DEBUG: TYPE: %1',_name];
diag_log format ['<ApmsDB>: DEBUG: FUNCTION: %1',_function];
diag_log format ['<ApmsDB>: DEBUG: PARAMS: %1',_params];
diag_log '===========================APMSDB EXTENSION CALLBACK===================================';
";
};
_eventString = _eventString + "
_params = parseSimpleArray _params;
_params spawn (missionNamespace getVariable [_function,{diag_log format ['<ApmsDB>: ERROR: Unable to find funtion: %1',_function]}]);
};";
addMissionEventHandler ['ExtensionCallback',(compile _eventString)];
\ No newline at end of file
......@@ -105,7 +105,7 @@ while{_doswitchloop} do {
if (DB_DEBUG) then {
diag_log "===========================APMSDB START OF REQUEST==================================";
diag_log format ["<ApmdDB>: DEBUG: CALLED FROM: %1",_fnc_scriptNameParent];
diag_log format ["<ApmsDB>: DEBUG: CALLED FROM: %1",_fnc_scriptNameParent];
diag_log format ["<ApmsDB>: DEBUG: REQUEST TYPE: %1",_originalrequest select 0];
diag_log format ["<ApmsDB>: DEBUG: ORIGINAL REQUEST: %1 ",_originalrequest];
diag_log format ["<ApmsDB>: DEBUG: RESPONSE: %1 ",_response];
......
......@@ -187,6 +187,7 @@ class CfgFunctions
class getServerTime {isGlobal = 1;};
class shutdown {};
class serverRequest {isGlobal = 1;};
class initExtensionCallback {};
};
......
......@@ -59,9 +59,26 @@ _request = [PROTOCOL_DBCALL_FUNCTION_EXECUTE_INIT_DB,[
]];
[_request] call DB_fnc_sendRequest;
// Start REST Server
_startRestServer = (call compile (["StartRestServer","DB","false"] call BASE_fnc_getCfgValue));
if (_startRestServer) then {
_serverAdress = ["RestServerAdress","DB","127.0.0.1"] call BASE_fnc_getCfgValue;
_serverPort = ["RestServerPort","DB","8000"] call BASE_fnc_getCfgValue;
diag_log format ["<ApmsDB>: INFO: STARTING REST SERVER... (%1) (%2)",_serverAdress,_serverPort];
_request = [PROTOCOL_REST_FUNCTION_STARTSERVER,[
PROTOCOL_REST_ARGUMENT_ADDRESS,_serverAdress,
PROTOCOL_REST_ARGUMENT_PORT,_serverPort
]];
_status = [_request] call DB_fnc_sendRequest;
if (_status isEqualType [] && {(_status select 0) isEqualTo "error"}) exitWith {diag_log "<ApmsDB>: ERROR: Unable to start REST server"};
diag_log format ["<ApmsDB>: INFO: %1",_status];
};
// Restore world variables
DB_var_worldVariables = call BASE_fnc_createNamespace;
_request = [PROTOCOL_DBCALL_FUNCTION_GET_WORLD_VARIABLES,[PROTOCOL_DBCALL_ARGUMENT_WORLDUUID,_worldUUID]];
DB_var_worldVariables = uiNamespace;//call BASE_fnc_createNamespace;
_request = [PROTOCOL_DBCALL_FUNCTION_GET_WORLD_VARIABLES,[]];
_variables = [_request] call DB_fnc_sendRequest;
_variables apply {
_x params ["_varName","_varData","_global"];
......@@ -72,6 +89,8 @@ _variables apply {
};
};
call DB_fnc_initExtensionCallback;
// Restore DB Objects
_restoreObjects = (call compile (["RestoreObjects","DB"] call BASE_fnc_getCfgValue));
if(_restoreObjects) then {
......
UpdateTime = 10 # (How often objects should be saved) In Minutes
# Start REST API server for server
# You can find more info from: (URL)
StartRestServer = false
RestServerAdress = 127.0.0.1
RestServerPort = 8000
RestoreObjects = true
RestorePlayers = true
......
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