Commit 367909d4 authored by Razer's avatar Razer
Browse files

ApmsDB: Moved world functions to separate folder

parent 53738741
......@@ -10,25 +10,19 @@
*/
/*
DESCRIPTION:
Get servers "REAL WORLD" time. (Based on servers timezone)
EXAMPLES:
_date = call DB_fnc_getServerTime;
RETURNS:
Empty array if failed. timeout, not scheduled or server error
ARRAY: - [year, month, day, hour, minute, second]
*/
if!(canSuspend) exitWith {[]};
// CLIENT REQUEST VALUE
if(hasInterface) exitWith {
[] remoteExec ["DB_fnc_getServerTime",2];
private _timeout = diag_tickTime + 3;
waitUntil {(count(missionNamespace getVariable ["DB_var_ServerTimeTmp",[]]) > 0) || diag_tickTime > _timeout};
if(diag_tickTime > _timeout) exitWith {[]}; // Timeout
private _return = +(missionNamespace getVariable ["DB_var_ServerTimeTmp",[]]);
missionNamespace setVariable ["DB_var_ServerTimeTmp",nil]; // Remove temp variable
_return
};
// Client request
if(!isServer) exitWith {_this call DB_fnc_serverRequest};
// SERVER DATA HANDLING
......@@ -39,7 +33,7 @@ private _return = [_request] call DB_fnc_sendRequest;
// Return data to client
if(isRemoteExecuted && {remoteExecutedOwner != 2}) exitWith {
[missionNamespace,["DB_var_ServerTimeTmp",_return]] remoteExec ["setVariable",remoteExecutedOwner];
[missionNamespace,[("DB_var_response_" + _fnc_scriptName),_return]] remoteExecCall ["setVariable",remoteExecutedOwner];
};
// Return data to server
......
/*
* 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/
*/
// ["myVariable",""] call DB_fnc_getWorldData;
// World data object SHOULD be the first object to get restored, priority 101
params [["_varName","",[""]],"_default"];
if(missionNamespace getVariable ["DB_var_restoreObjectInProgress",true]) exitWith {diag_log "<ApmsDB>: ERROR: Cannot read world data. Object has not been restored yet!"};
if(_varName == "") exitWith {};
if(isNull DB_var_worldDataObject) then {
call DB_fnc_createWorldDataObject;
};
if(isNull DB_var_worldDataObject) exitWith {diag_log "<ApmsDB>: ERROR: Unable to create world data object!"};
private _varName = "_svar_" + _varName;
private _data = DB_var_worldDataObject getVariable _varName;
if(isNil "_data" && !isNil "_default") exitWith {_default};
if(isNil "_data") exitWith {};
_data
\ 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/
*/
// Returns true if successfully set false if not
params [["_varName","",[""]],["_data",nil],["_overWrite",true,[true]]];
if(missionNamespace getVariable ["DB_var_restoreObjectInProgress",true]) exitWith {diag_log "<ApmsDB>: ERROR: Cannot read world data. Object has not been restored yet!";false};
if(_varName == "" || isNil "_data") exitWith {false};
if(isNull DB_var_worldDataObject) then {
call DB_fnc_createWorldDataObject;
};
if(isNull DB_var_worldDataObject) exitWith {diag_log "<ApmsDB>: ERROR: Unable to create world data object!";false};
private _exit = false;
if!(_overWrite) then {
_oldData = [_varName] call DB_fnc_getWorldData;
if!(isNil "_oldData") exitWith {diag_log format ["<ApmsDB>: WARNING: Variable already set. (OLD DATA: %1 )",_oldData]; _exit = true};
};
if(_exit) exitWith {false};
diag_log format ["<ApmsDB>: INFO: Setting new world data variable: ( '%1' ) : ( %2 )",_varName,_data];
private _varName = "_svar_" + _varName;
DB_var_worldDataObject setVariable [_varName,_data];
[DB_var_worldDataObject] call DB_fnc_updateObject;
true
\ 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/
*/
/*
DESCRIPTION:
Get variable from world (server). You can also get variables from another world if world UUID used as param.
PARAMS:
1 - STRING: Variable name.
2 - STRING (Optional): World UUID to get the variable from. If no world UUID used, current world will be used.
3 - ANY (Optional): Default data if no data found with this variable name.
EXAMPLES:
_data = ["myVariable"] call DB_fnc_getWorldVariable;
_data = ["myVariable",_worldUUID] call DB_fnc_getWorldVariable;
_data = ["myVariable","","NO VARIABLE FOUND"] call DB_fnc_getWorldVariable;
RETURNS:
Variable data, or default param
*/
/*
If world UUID
*/
#include "\ApmsDB\constants.hpp"
params [["_varName","",[""]],["_worldUUID","",[""]],"_default"];
if (_varName == "") exitWith {};
private _varIndex = DB_var_worldVariables findIf {_x select 0 == _varName};
private _data = if (_varIndex == -1) then {
if (_worldUUID == "" || {call DB_fnc_getWorldUUID == _worldUUID}) exitWith {};
private _request = [PROTOCOL_DBCALL_FUNCTION_GET_WORLD_VARIABLES,[PROTOCOL_DBCALL_ARGUMENT_WORLDUUID,_worldUUID]];
private _return = [_request] call DB_fnc_sendRequest;
if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {};
_varIndex = _return findIf {_x select 0 == _varName};
[nil,((_return select _varIndex) select 1)] select (_varIndex != -1);
} else {
(DB_var_worldVariables select _varIndex) select 1
};
if (isNil "_data") exitWith {
if (isNil "_default") exitWith {};
_default
};
_data
\ 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/
*/
/*
DESCRIPTION:
Add world variable to DB. You can only set variables to world where this function was called from.
PARAMS:
1: STRING - Variable name.
2: ANY - Variable data.
EXAMPLES:
_myData = [10,"TEST"];
["MyVariable",_myData] call DB_fnc_setWorldVariable;
// Remove variable
["MyVariable",nil] call DB_fnc_setWorldVariable;
RETURNS:
TRUE if success, FALSE if failed.
*/
#include "\ApmsDB\constants.hpp"
params [["_varName","",[""]],"_data"];
if (_varName == "") exitWith {false};
private _noChanges = false;
// Use global variable to remove need to call libredex everytime when using getVariable
private _varIndex = DB_var_worldVariables findIf {_x select 0 == _varName};
if (_varIndex != -1) then {
if (isNil "_data") exitWith {DB_var_worldVariables deleteAt _varIndex; _noChanges = true}; // Remove variable
private _oldVarName = ((DB_var_worldVariables select _varIndex) select 0);
private _oldData = ((DB_var_worldVariables select _varIndex) select 1);
if (_oldData isEqualTo _data && (_varName isEqualTo _oldVarName)) exitWith {_noChanges = true}; // Same data
DB_var_worldVariables set [_varIndex,[_varName,_data]];
} else {
if (isNil "_data") exitWith {_noChanges = true}; // No data to be set
DB_var_worldVariables pushBack [_varName,_data];
};
if (_noChanges) exitWith {true}; // No data were changed or it was reseted to nil
private _request = [PROTOCOL_DBCALL_FUNCTION_SET_WORLD_VARIABLES,[PROTOCOL_DBCALL_ARGUMENT_VARIABLES,(DB_var_worldVariables)]];
private _return = [_request] call DB_fnc_sendRequest;
if (_return isEqualType [] && {(_return select 0) isEqualTo "error"}) exitWith {
if (_varIndex != -1) then {
DB_var_worldVariables deleteAt _varIndex;
} else {
DB_var_worldVariables deleteAt ((count (DB_var_worldVariables)) - 1);
};
false
};
true
\ No newline at end of file
......@@ -20,7 +20,7 @@ DB_var_restoreObjectInProgress = true;
DB_var_savingObjects = true;
DB_var_runObjectMon = true;
_requiredVersion = [1,0,5,1];
_requiredVersion = parseSimpleArray(DLLVERSIONSTRING);
_request = [PROTOCOL_LIBARY_FUNCTION_CHECK_VERSION,[]];
_version = [_request] call DB_fnc_sendRequest;
if !(_version select 2 > _requiredVersion select 2 || _version select 2 == _requiredVersion select 2 && _version select 3 >= _requiredVersion select 3) exitWith {
......
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