diff --git a/ArmaRAMDb_x64.dll b/ArmaRAMDb_x64.dll index ebdab1b..03a2b8f 100644 Binary files a/ArmaRAMDb_x64.dll and b/ArmaRAMDb_x64.dll differ diff --git a/ArmaRAMDb_x64.so b/ArmaRAMDb_x64.so index 0144c2e..4e4c400 100644 Binary files a/ArmaRAMDb_x64.so and b/ArmaRAMDb_x64.so differ diff --git a/addons/db/functions/fnc_addTask.sqf b/addons/db/functions/fnc_addTask.sqf new file mode 100644 index 0000000..51ed698 --- /dev/null +++ b/addons/db/functions/fnc_addTask.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_addTask + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Add task to queue. + * + * Arguments: + * 0: Type of task + * 1: Name of stored key (default: "") + * 2: Name of stored hash key field (default: "") + * 3: Index of stored value in list (default: -1) + * 4: Value to store in key [] (default: []) + * 5: Name of function to return data (default: "") + * 6: Unscheduled environment (default: false) + * 7: NetID of target to return data from function (default: "") + * + * Return Value: + * N/A + * + * Examples: + * ["hgetall", "", "", -1, [], "ramdb_db_fnc_test", false] call ramdb_db_fnc_addTask (Server or Singleplayer Only) + * ["hgetallid", getPlayerUID player, "", -1, [], "ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_addTask", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_taskType", "", [""]], ["_key", "", [""]], ["_keyField", "", [""]], ["_index", -1, [0]], ["_value", [], [[]]], ["_function", "", [""]], ["_call", false, [false]], ["_netId", "", [""]]]; + +private _task = [_taskType, _key, _keyField, _index, _value, _function, _call, _netId]; + +diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_addTask' Added Task '%1' to Queue", _task]; + +GVAR(taskQueue) pushBack _task; +diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_addTask' Queue: %1", GVAR(taskQueue)]; +diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_addTask' Queue Size: %1", count GVAR(taskQueue)]; + +if !(GVAR(isProcessing)) then { [] spawn FUNC(processQueue); }; \ No newline at end of file diff --git a/addons/db/functions/fnc_delete.sqf b/addons/db/functions/fnc_delete.sqf new file mode 100644 index 0000000..8d998be --- /dev/null +++ b/addons/db/functions/fnc_delete.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_delete + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Delete stored key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * + * Return Value: + * N/A + * + * Examples: + * [getPlayerUID player] call ramdb_db_fnc_delete (Server or Singleplayer Only) + * [getPlayerUID player] remoteExecCall ["ramdb_db_fnc_delete", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]]]; + +if (_key == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_delete' Invalid Input for Key '%1'", _key]; }; + +"ArmaRAMDb" callExtension ["del", [_key]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_fetch.sqf b/addons/db/functions/fnc_fetch.sqf new file mode 100644 index 0000000..b6a203b --- /dev/null +++ b/addons/db/functions/fnc_fetch.sqf @@ -0,0 +1,66 @@ +#include "script_component.hpp" + +/* + @file Title: ArmaRAMDb Framework by Creedcoder, J.Schmidt + @file Version: 0.1 + @file Name: fnc_fetch.sqf + @file Author: Creedcoder, J.Schmidt + @file edit: 03.25.2024 + Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + + Do not edit without permission! + + This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlikes 4.0 International License. + To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to Creative Commons, + 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. + + Fetch from DB: + ramdb_db_fetch_array + + ["uniqueID", "function", "index", "indextotal", "datachunk", "call", "netId"] +*/ + +diag_log _this; + +params ["_uniqueID", "_function", "_index", "_total", "_datachunk", "_call", "_netId"]; +private _dataString = ""; +private _index_array = []; +private _count_total = -1; + +// _uniqueID = parseNumber _uniqueID; +// _function +// _index = parseNumber _index; +// _total = parseNumber _total; +// _datachunk +// _call +// _netId + +ramdb_db_fetch_array pushBackUnique [_uniqueID, _function, _index, _total, _datachunk, _call, _netId]; + +_count_total = { + if (_uniqueID == _x select 0) then { + _index_array pushBackUnique [_x select 2, _x select 4]; + true + } else { + false + } +} count ramdb_db_fetch_array; + +if (_count_total == _total) then { + _index_array sort true; + for "_i" from 0 to (_total - 1) do { + _dataString = _dataString + ((_index_array select _i) select 1); + }; + + diag_log _dataString; + + // Old direct execution + // (parseSimpleArray _dataString) call (missionNamespace getVariable [_function, { + // hint "Function does not exist!"; + // }]); + + [_uniqueID, _function, _call, (parseSimpleArray _dataString), _netId] call FUNC(handler); + + // Cleanup + ramdb_db_fetch_array = ramdb_db_fetch_array select {!((_x select 0) in [_uniqueID])}; +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_get.sqf b/addons/db/functions/fnc_get.sqf new file mode 100644 index 0000000..c7bb170 --- /dev/null +++ b/addons/db/functions/fnc_get.sqf @@ -0,0 +1,49 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_get + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Get value of stored key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * 1: Name of function to return data (default: "") + * 2: Unscheduled environment (default: false) + * 3: NetID of target to return data from function (default: "") + * + * Return Value: + * N/A + * + * Examples: + * [getPlayerUID player, "ramdb_db_fnc_test"] call ramdb_db_fnc_get (Server or Singleplayer Only) + * [getPlayerUID player, "ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_get", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_function", "", [""]], ["_call", false, [false]], ["_netId", nil, [""]]]; + +if (_key == "" || _function == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_get' Invalid Input for Key '%1' or Function '%2'", _key, _function]; }; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + if (_call) then { + _return = "ArmaRAMDb" callExtension ["get", [_key, _function, _netId, _call]]; + [(_return select 0)] call FUNC(scheduler); + } else { + _return = "ArmaRAMDb" callExtension ["get", [_key, _function, _netId]]; + [(_return select 0)] call FUNC(scheduler); + }; +} else { + _return = "ArmaRAMDb" callExtension ["get", [_key, _function]]; + [(_return select 0)] call FUNC(scheduler); +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_handler.sqf b/addons/db/functions/fnc_handler.sqf new file mode 100644 index 0000000..d6a7ab0 --- /dev/null +++ b/addons/db/functions/fnc_handler.sqf @@ -0,0 +1,47 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_handler + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Handle data from DB. + * + * Arguments: + * 0: UniqueID for data chunk (default: "") + * 1: Name of function to return data (default: "") + * 2: Unscheduled environment (default: false) + * 3: Data from key [] (default: []) + * 4: NetID of target to return data to from function (default: nil) + * + * Return Value: + * [uniqueID, function, call, data, object] + * + * Examples: + * ["0123456789", "ramdb_db_fnc_test", false, ["Hello World!"]] call ramdb_db_fnc_handler (Server or Singleplayer Only) + * ["0123456789", "ramdb_db_fnc_test", false, ["Hello World!"], netId player] remoteExecCall ["ramdb_db_fnc_handler", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_uniqueID", "", [""]], ["_function", "", [""]], ["_call", false, [false]], ["_data", [], [[]]], ["_netId", nil, [""]]]; + +if (_function == "" || count _data == 0) exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_handler' Invalid Input for Function '%1' or Data '%2'", _function, _data]; }; + +private _func = call compile format ["%1", _function]; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + private _target = objectFromNetId _netId; + + if (_call) then { _data remoteExecCall [_function, _target, false]; } else { _data remoteExec [_function, _target, false]; }; +} else { + if (_call) then { _data call _func; } else { _data spawn _func; }; +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashGet.sqf b/addons/db/functions/fnc_hashGet.sqf new file mode 100644 index 0000000..d47840d --- /dev/null +++ b/addons/db/functions/fnc_hashGet.sqf @@ -0,0 +1,49 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashGet + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Get value of field in hash stored in key from DB. + * + * Arguments: + * 0: Name of stored field in hash (default: "") + * 1: Name of function to return data (default: "") + * 2: Unscheduled environment (default: false) + * 3: NetID of target to return data from function (default: nil) + * + * Return Value: + * N/A + * + * Examples: + * ["loadout", "ramdb_db_fnc_test", false] call ramdb_db_fnc_hashGet (Server or Singleplayer Only) + * ["loadout", "ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_hashGet", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_keyField", "", [""]], ["_function", "", [""]], ["_call", false, [false]], ["_netId", nil, [""]]]; + +if (_keyField == "" || _function == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashGet' Invalid Input for KeyField '%1' or Function '%2'", _keyField, _function]; }; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + if (_call) then { + _return = "ArmaRAMDb" callExtension ["hget", [_keyField, _function, _netId, _call]]; + [(_return select 0)] call FUNC(scheduler); + } else { + _return = "ArmaRAMDb" callExtension ["hget", [_keyField, _function, _netId]]; + [(_return select 0)] call FUNC(scheduler); + }; +} else { + _return = "ArmaRAMDb" callExtension ["hget", [_keyField, _function]]; + [(_return select 0)] call FUNC(scheduler); +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashGetAll.sqf b/addons/db/functions/fnc_hashGetAll.sqf new file mode 100644 index 0000000..80c2598 --- /dev/null +++ b/addons/db/functions/fnc_hashGetAll.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashGetAll + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Get all fields and values of hash stored in key from DB. + * + * Arguments: + * 0: Name of function to return data (default: "") + * 1: Unscheduled environment (default: false) + * 2: NetID of target to return data from function (default: nil) + * + * Return Value: + * N/A + * + * Examples: + * ["ramdb_db_fnc_test", false] call ramdb_db_fnc_hashGetAll (Server or Singleplayer Only) + * ["ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_hashGetAll", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_function", "", [""]], ["_call", false, [false]], ["_netId", nil, [""]]]; + +if (_function isEqualTo "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashGetAll' Invalid Input for Function '%1'", _function]; }; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + if (_call) then { + _return = "ArmaRAMDb" callExtension ["hgetall", [_function, _netId, _call]]; + [(_return select 0)] call FUNC(scheduler); + } else { + _return = "ArmaRAMDb" callExtension ["hgetall", [_function, _netId]]; + [(_return select 0)] call FUNC(scheduler); + }; +} else { + _return = "ArmaRAMDb" callExtension ["hgetall", [_function]]; + [(_return select 0)] call FUNC(scheduler); +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashGetAllId.sqf b/addons/db/functions/fnc_hashGetAllId.sqf new file mode 100644 index 0000000..148bfd1 --- /dev/null +++ b/addons/db/functions/fnc_hashGetAllId.sqf @@ -0,0 +1,49 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashGetAllId + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Get all fields and values of hash stored in key from DB. + * + * Arguments: + * 0: Name of stored key with hash (default: "") + * 1: Name of function to return data (default: "") + * 2: Unscheduled environment (default: false) + * 3: NetID of target to return data from function (default: nil) + * + * Return Value: + * N/A + * + * Examples: + * [getPlayerUID player, "ramdb_db_fnc_test", false] call ramdb_db_fnc_hashGetAllId (Server or Singleplayer Only) + * [getPlayerUID player, "ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_hashGetAllId", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_function", "", [""]], ["_call", false, [false]], ["_netId", nil, [""]]]; + +if (_key == "" || _function == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashGetAllId' Invalid Input for Key '%1' or Function '%2'", _key, _function]; }; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + if (_call) then { + _return = "ArmaRAMDb" callExtension ["hgetallid", [_key, _function, _netId, _call]]; + [(_return select 0)] call FUNC(scheduler); + } else { + _return = "ArmaRAMDb" callExtension ["hgetallid", [_key, _function, _netId]]; + [(_return select 0)] call FUNC(scheduler); + }; +} else { + _return = "ArmaRAMDb" callExtension ["hgetallid", [_key, _function]]; + [(_return select 0)] call FUNC(scheduler); +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashGetId.sqf b/addons/db/functions/fnc_hashGetId.sqf new file mode 100644 index 0000000..164c427 --- /dev/null +++ b/addons/db/functions/fnc_hashGetId.sqf @@ -0,0 +1,50 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashGetId + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Get value of field in hash stored at key from DB. + * + * Arguments: + * 0: Name of stored key with hash (default: "") + * 1: Name of stored field in hash (default: "") + * 2: Name of function to return data (default: "") + * 3: Unscheduled environment (default: false) + * 4: NetID of target to return data from function (default: nil) + * + * Return Value: + * N/A + * + * Examples: + * [getPlayerUID player, "loadout", "ramdb_db_fnc_test", false] call ramdb_db_fnc_hashGetId (Server or Singleplayer Only) + * [getPlayerUID player, "loadout", "ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_hashGetId", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_keyField", "", [""]], ["_function", "", [""]], ["_call", false, [false]], ["_netId", nil, [""]]]; + +if (_key == "" || _keyField == "" || _function == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashGetId' Invalid Input for Key '%1', KeyField '%2' or Function '%3'", _key, _keyField, _function]; }; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + if (_call) then { + _return = "ArmaRAMDb" callExtension ["hgetid", [_key, _keyField, _function, _netId, _call]]; + [(_return select 0)] call FUNC(scheduler); + } else { + _return = "ArmaRAMDb" callExtension ["hgetid", [_key, _keyField, _function, _netId]]; + [(_return select 0)] call FUNC(scheduler); + }; +} else { + _return = "ArmaRAMDb" callExtension ["hgetid", [_key, _keyField, _function]]; + [(_return select 0)] call FUNC(scheduler); +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashSet.sqf b/addons/db/functions/fnc_hashSet.sqf new file mode 100644 index 0000000..dec3ac8 --- /dev/null +++ b/addons/db/functions/fnc_hashSet.sqf @@ -0,0 +1,36 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashSet + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Set value of field in hash stored at key from DB. + * + * Arguments: + * 0: Name of stored field in hash (default: "") + * 1: Value to store in hash field [] (default: []) + * + * Return Value: + * N/A + * + * Examples: + * ["loadout", [getUnitLoadout player]] call ramdb_db_fnc_hashSet (Server or Singleplayer Only) + * ["loadout", [getUnitLoadout player]] remoteExecCall ["ramdb_db_fnc_hashSet", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_keyField", "", [""]], ["_data", [], [[]]]]; + +if (_keyField == "" || count _data == 0) exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSet' Invalid Input for KeyField '%1' or Data '%2'", _keyField, _data]; }; + +"ArmaRAMDb" callExtension ["hset", [_keyField, _data]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashSetBulk.sqf b/addons/db/functions/fnc_hashSetBulk.sqf new file mode 100644 index 0000000..e270251 --- /dev/null +++ b/addons/db/functions/fnc_hashSetBulk.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashSetBulk + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Set fields and values in hash stored at key from DB. + * + * Arguments: + * 0: Fields and Values to store in hash [] (default: []) + * + * Return Value: + * N/A + * + * Examples: + * ["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] call ramdb_db_fnc_hashSetBulk (Server or Singleplayer Only) + * ["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] remoteExecCall ["ramdb_db_fnc_hashSetBulk", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_data", [], [[]]]]; + +if (count _data == 0) exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetBulk' Invalid Input for Data '%1'", _data]; }; + +"ArmaRAMDb" callExtension ["hset", _data]; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashSetId.sqf b/addons/db/functions/fnc_hashSetId.sqf new file mode 100644 index 0000000..0d6ee04 --- /dev/null +++ b/addons/db/functions/fnc_hashSetId.sqf @@ -0,0 +1,37 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashSetId + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Set value of field in hash stored at key from DB. + * + * Arguments: + * 0: Name of stored key with hash (default: "") + * 1: Name of stored hash key field (default: "") + * 2: Value to store in hash field [] (default: []) + * + * Return Value: + * N/A + * + * Examples: + * [getPlayerUID player, "loadout", [getUnitLoadout player]] call ramdb_db_fnc_hashSetId (Server or Singleplayer Only) + * [getPlayerUID player, "loadout", [getUnitLoadout player]] remoteExecCall ["ramdb_db_fnc_hashSetId", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_keyField", "", [""]], ["_data", [], [[]]]]; + +if (_key == "" || _keyField == "" || count _data == 0) exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetId' Invalid Input for Key '%1', KeyField '%2' or Data '%3'", _key, _keyField, _data]; }; + +"ArmaRAMDb" callExtension ["hsetid", [_key, _keyField, _data]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashSetIdBulk.sqf b/addons/db/functions/fnc_hashSetIdBulk.sqf new file mode 100644 index 0000000..eb694ab --- /dev/null +++ b/addons/db/functions/fnc_hashSetIdBulk.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashSetIdBulk + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Set fields and values in hash stored at key from DB. + * + * Arguments: + * 0: Fields and Values to store in hash [] (default: []) + * + * Return Value: + * N/A + * + * Examples: + * [getPlayerUID player, "loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] call ramdb_db_fnc_hashSetIdBulk (Server or Singleplayer Only) + * [getPlayerUID player, "loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] remoteExecCall ["ramdb_db_fnc_hashSetIdBulk", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_data", [], [[]]]]; + +if (count _data == 0) exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetIdBulk' Invalid Input for Data '%1'", _data]; }; + +"ArmaRAMDb" callExtension ["hsetid", _data]; \ No newline at end of file diff --git a/addons/db/functions/fnc_init.sqf b/addons/db/functions/fnc_init.sqf new file mode 100644 index 0000000..1c1db0e --- /dev/null +++ b/addons/db/functions/fnc_init.sqf @@ -0,0 +1,37 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_init + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Initial Extension settings. + * + * Arguments: + * N/A + * + * Return Value: + * N/A + * + * Examples: + * N/A + * + * Public: Yes + */ + +ramdb_db_buffer = 10240; + +private _dll = "ArmaRAMDb" callExtension ["version", []]; + +diag_log text (format ["ArmaRAMDb: DLL Version %1 found", _dll]); +diag_log text "ArmaRAMDb: Functions loaded and Initializtion completed!"; +diag_log text (format ["ArmaRAMDb: Buffer size set to %1 Bytes", ramdb_db_buffer]); +diag_log text "ArmaRAMDb: Ready for use!"; \ No newline at end of file diff --git a/addons/db/functions/fnc_listAdd.sqf b/addons/db/functions/fnc_listAdd.sqf new file mode 100644 index 0000000..e92384f --- /dev/null +++ b/addons/db/functions/fnc_listAdd.sqf @@ -0,0 +1,36 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_listAdd + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Add element to list stored at key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * 1: Value to insert into key [] (default: []) + * + * Return Value: + * N/A + * + * Examples: + * ["events", ["Server state saved to DB 071620241600"]] call ramdb_db_fnc_listAdd (Server or Singleplayer Only) + * ["events", ["Server state saved to DB 071620241600"]] remoteExecCall ["ramdb_db_fnc_listAdd", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_data", [], [[]]]]; + +if (_key == "" || count _data == 0) exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listAdd' Invalid Input for Key '%1' or Data '%2'", _key, _data]; }; + +"ArmaRAMDb" callExtension ["listadd", [_key, _data]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_listGet.sqf b/addons/db/functions/fnc_listGet.sqf new file mode 100644 index 0000000..278969d --- /dev/null +++ b/addons/db/functions/fnc_listGet.sqf @@ -0,0 +1,50 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_listGet + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Get element of list stored at key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * 1: Index of stored value in list (default: -1) + * 2: Name of function to return data (default: "") + * 3: Unscheduled environment (default: false) + * 4: NetID of target to return data from function (default: nil) + * + * Return Value: + * N/A + * + * Examples: + * ["events", 0, "ramdb_db_fnc_test", false] call ramdb_db_fnc_listGet (Server or Singleplayer Only) + * ["events", 0, "ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_listGet", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_index", -1, [0]], ["_function", "", [""]], ["_call", false, [false]], ["_netId", nil, [""]]]; + +if (_key == "" || _function == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listGet' Invalid Input for Key '%1' or Function '%2'", _key, _function]; }; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + if (_call) then { + _return = "ArmaRAMDb" callExtension ["listidx", [_key, _index, _function, _netId, _call]]; + [(_return select 0)] call FUNC(scheduler); + } else { + _return = "ArmaRAMDb" callExtension ["listidx", [_key, _index, _function, _netId]]; + [(_return select 0)] call FUNC(scheduler); + }; +} else { + _return = "ArmaRAMDb" callExtension ["listidx", [_key, _index, _function]]; + [(_return select 0)] call FUNC(scheduler); +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_listLoad.sqf b/addons/db/functions/fnc_listLoad.sqf new file mode 100644 index 0000000..a7c65d7 --- /dev/null +++ b/addons/db/functions/fnc_listLoad.sqf @@ -0,0 +1,49 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_listLoad + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Get all elements of list stored at key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * 1: Name of function to return data (default: "") + * 2: Unscheduled environment (default: false) + * 3: NetID of target to return data from function (default: nil) + * + * Return Value: + * N/A + * + * Examples: + * ["events", "ramdb_db_fnc_test", false] call ramdb_db_fnc_listLoad (Server or Singleplayer Only) + * ["events", "ramdb_db_fnc_test", false, netId player] remoteExecCall ["ramdb_db_fnc_listLoad", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_function", "", [""]], ["_call", false, [false]], ["_netId", nil, [""]]]; + +if (_key == "" || _function == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listLoad' Invalid Input for Key '%1' or Function '%2'", _key, _function]; }; + +if ((!isNil "_netId") and (_netId isNotEqualTo "")) then { + if (_call) then { + _return = "ArmaRAMDb" callExtension ["listrng", [_key, 0, -1, _function, _netId, _call]]; + [(_return select 0)] call FUNC(scheduler); + } else { + _return = "ArmaRAMDb" callExtension ["listrng", [_key, 0, -1, _function, _netId]]; + [(_return select 0)] call FUNC(scheduler); + }; +} else { + _return = "ArmaRAMDb" callExtension ["listrng", [_key, 0, -1, _function]]; + [(_return select 0)] call FUNC(scheduler); +}; \ No newline at end of file diff --git a/addons/db/functions/fnc_listRemove.sqf b/addons/db/functions/fnc_listRemove.sqf new file mode 100644 index 0000000..36cc13a --- /dev/null +++ b/addons/db/functions/fnc_listRemove.sqf @@ -0,0 +1,36 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_listRemove + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Remove element of list stored at key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * 1: Index of stored value in list (default: -1) + * + * Return Value: + * N/A + * + * Examples: + * ["events", 0] call ramdb_db_fnc_listRemove (Server or Singleplayer Only) + * ["events", 0] remoteExecCall ["ramdb_db_fnc_listRemove", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_index", -1, [0]]]; + +if (_key == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listRemove' Invalid Input for Key '%1'", _key]; }; + +"ArmaRAMDb" callExtension ["listrem", [_key, _index]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_listSet.sqf b/addons/db/functions/fnc_listSet.sqf new file mode 100644 index 0000000..b71f0bc --- /dev/null +++ b/addons/db/functions/fnc_listSet.sqf @@ -0,0 +1,37 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_listSet + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Set element of list stored at key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * 1: Index of stored value in list (default: -1) + * 2: Value to set for index [] (default: []) + * + * Return Value: + * N/A + * + * Examples: + * ["events", 0, ["Hello World!"]] call ramdb_db_fnc_listSet (Server or Singleplayer Only) + * ["events", 0, ["Hello World!"]] remoteExecCall ["ramdb_db_fnc_listSet", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_index", -1, [0]], ["_data", [], [[]]]]; + +if (_key == "" || count _data == 0) exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listSet' Invalid Input for Key '%1' or Data '%2'", _key, _data]; }; + +"ArmaRAMDb" callExtension ["listset", [_key, _index, _data]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_printAddonName.sqf b/addons/db/functions/fnc_printAddonName.sqf new file mode 100644 index 0000000..e812783 --- /dev/null +++ b/addons/db/functions/fnc_printAddonName.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +systemChat format ["Thank you for using the %1", 'ADDON']; \ No newline at end of file diff --git a/addons/db/functions/fnc_processQueue.sqf b/addons/db/functions/fnc_processQueue.sqf new file mode 100644 index 0000000..8a02dce --- /dev/null +++ b/addons/db/functions/fnc_processQueue.sqf @@ -0,0 +1,69 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_processQueue + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Process queue of tasks. + * + * Arguments: + * N/A + * + * Return Value: + * N/A + * + * Examples: + * [] spawn ramdb_db_fnc_processQueue (Server or Singleplayer Only) + * [] remoteExec ["ramdb_db_fnc_processQueue", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +GVAR(isProcessing) = true; + +while { count GVAR(taskQueue) > 0} do { + private _task = GVAR(taskQueue) deleteAt 0; + private _taskType = _task select 0; + private _key = _task select 1; + private _keyField = _task select 2; + private _index = _task select 3; + private _value = _task select 4; + private _function = _task select 5; + private _call = _task select 6; + private _netId = _task select 7; + + diag_log text format ["Initializing Task: %1", _task]; + + switch (_taskType) do { + case "get": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _function, _call, _netId] call FUNC(get); }; + case "set": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _value] call FUNC(set); }; + case "del": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key] call FUNC(delete); }; + case "hget": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_keyField, _function, _call, _netId] call FUNC(hashGet); }; + case "hgetid": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _keyField, _function, _call, _netId] call FUNC(hashGetId); }; + case "hgetall": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_function, _call, _netId] call FUNC(hashGetAll); }; + case "hgetallid": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _function, _call, _netId] call FUNC(hashGetAllId); }; + case "hset": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_keyField, _value] call FUNC(hashSet); }; + case "hsetbulk": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_value] call FUNC(hashSetBulk); }; + case "hsetid": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _keyField, _value] call FUNC(hashSetId); }; + case "hsetidbulk": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_value] call FUNC(hashSetIdBulk); }; + case "listadd": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _value] call FUNC(listAdd); }; + case "listidx": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _index, _function, _call, _netId] call FUNC(listGet); }; + case "listrng": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _function, _call, _netId] call FUNC(listLoad); }; + case "listrem": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _index] call FUNC(listRemove); }; + case "listset": { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_processQueue' Processing Task '%1'", _taskType]; [_key, _index, _value] call FUNC(listSet); }; + }; + + sleep 1; + +}; + +GVAR(isProcessing) = false; \ No newline at end of file diff --git a/addons/db/functions/fnc_save.sqf b/addons/db/functions/fnc_save.sqf new file mode 100644 index 0000000..6c86c58 --- /dev/null +++ b/addons/db/functions/fnc_save.sqf @@ -0,0 +1,31 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_save + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Save to disc. + * + * Arguments: + * N/A + * + * Return Value: + * N/A + * + * Examples: + * [] call ramdb_db_fnc_save (Server or Singleplayer Only) + * [] remoteExecCall ["ramdb_db_fnc_save", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +"ArmaRAMDb" callExtension ["save", []]; \ No newline at end of file diff --git a/addons/db/functions/fnc_scheduler.sqf b/addons/db/functions/fnc_scheduler.sqf new file mode 100644 index 0000000..3ee1be6 --- /dev/null +++ b/addons/db/functions/fnc_scheduler.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_scheduler + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Scheduled Environment for extension. + * + * Arguments: + * 0: Task ID from extension (default: "") + * + * Return Value: + * N/A + * + * Examples: + * ["071620241600_get"] call ramdb_db_fnc_scheduler (Server or Singleplayer Only) + * ["071620241600_get"] remoteExecCall ["ramdb_db_fnc_scheduler", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +private _params = call compile format ["%1", (_this select 0)]; +private _taskID = _params select 0; +private _function = _params select 1; +private _array = _taskID splitString "_"; +private _id = _array select 0; +private _taskType = _array select 1; +private _addTaskIDToMap = { + params ["_taskType", "_taskID"]; + + private _varName = format ["ramdb_db_%1_map", _taskType]; + private _taskMap = missionNamespace getVariable [_varName, createHashMap]; + _taskMap set [_taskID, _function]; + + missionNamespace setVariable [_varName, _taskMap]; + _myHashMap = missionNamespace getVariable [_varName, createHashMap]; +}; + +[_taskType, _taskID] call _addTaskIDToMap; \ No newline at end of file diff --git a/addons/db/functions/fnc_set.sqf b/addons/db/functions/fnc_set.sqf new file mode 100644 index 0000000..ce17026 --- /dev/null +++ b/addons/db/functions/fnc_set.sqf @@ -0,0 +1,36 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_set + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Set value of stored key from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * 1: Value to store in key [] (default: []) + * + * Return Value: + * N/A + * + * Examples: + * ["test", ["Hello World!"]] call ramdb_db_fnc_set (Server or Singleplayer Only) + * ["test", ["Hello World!"]] remoteExecCall ["ramdb_db_fnc_set", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_data", "", [[]]]]; + +if (_key == "" || _data == "") exitWith { diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_set' Invalid Input for Key '%1' or Data '%2'", _key, _data]; }; + +"ArmaRAMDb" callExtension ["set", [_key, _data]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_test.sqf b/addons/db/functions/fnc_test.sqf new file mode 100644 index 0000000..3fcde59 --- /dev/null +++ b/addons/db/functions/fnc_test.sqf @@ -0,0 +1,34 @@ +#include "script_component.hpp" + +/* + * Function: ramdb_db_fnc_test + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Test function. + * + * Arguments: + * 0: Value + * + * Return Value: + * Value + * + * Examples: + * ["Hello World!"] spawn ramdb_db_fnc_test (Server or Singleplayer Only) + * ["Hello World!"] remoteExec ["ramdb_db_fnc_test", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +_res = _this; +ramdb_db_test = _res; + +hint format ["%1", _res]; \ No newline at end of file diff --git a/addons/db/functions/script_component.hpp b/addons/db/functions/script_component.hpp new file mode 100644 index 0000000..4e2d473 --- /dev/null +++ b/addons/db/functions/script_component.hpp @@ -0,0 +1 @@ +#include "..\script_component.hpp" \ No newline at end of file diff --git a/extension/bin/Release/net8.0/linux-x64/publish/ArmaRAMDb_x64.so b/extension/bin/Release/net8.0/linux-x64/publish/ArmaRAMDb_x64.so index 0144c2e..4e4c400 100644 Binary files a/extension/bin/Release/net8.0/linux-x64/publish/ArmaRAMDb_x64.so and b/extension/bin/Release/net8.0/linux-x64/publish/ArmaRAMDb_x64.so differ diff --git a/extension/bin/Release/net8.0/win-x64/publish/ArmaRAMDb_x64.dll b/extension/bin/Release/net8.0/win-x64/publish/ArmaRAMDb_x64.dll index ebdab1b..03a2b8f 100644 Binary files a/extension/bin/Release/net8.0/win-x64/publish/ArmaRAMDb_x64.dll and b/extension/bin/Release/net8.0/win-x64/publish/ArmaRAMDb_x64.dll differ diff --git a/extension/src/HashStore.cs b/extension/src/HashStore.cs index 098e7ad..0e97519 100644 --- a/extension/src/HashStore.cs +++ b/extension/src/HashStore.cs @@ -1,37 +1,57 @@ using System.Collections.Concurrent; +#pragma warning disable IDE0130 // Namespace does not match folder structure namespace ArmaRAMDb +#pragma warning restore IDE0130 // Namespace does not match folder structure { internal class HashStore { private static readonly ConcurrentDictionary> _hashTables = RAMDb._hashTables; - public static bool HashDelete(string tableName) + public static async Task HashDelete(string tableName) { - var result = _hashTables.TryRemove(tableName, out _); + await Task.Yield(); + bool result = _hashTables.TryRemove(tableName, out _); Main.Log($"HashDelete: {tableName} - Success: {result}", "debug"); - return result; } - public static string HashGet(string tableName, string key) + public static async Task HashGet(string tableName, string key, string function, string uniqueID, string entity = null, string call = "false", int bufferSize = Main.ARDB_BUFFERSIZE) { + if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(key) || string.IsNullOrEmpty(function)) + { + Main.Log($"ArmaRAMDb 'tableName, 'key' or 'function' cannot be empty", "debug"); + return; + } + + await Task.Yield(); + if (_hashTables.TryGetValue(tableName, out var table)) { string data = table.TryGetValue(key, out string value) ? value : string.Empty; Main.Log($"HashGet: {tableName} - {key}", "debug"); Main.Log($"Value: {data}", "debug"); - return data; + + Utils.CheckByteCount(uniqueID, data, function, entity, Convert.ToBoolean(call), bufferSize); + } + else + { + Main.Log($"Table not found: {tableName}", "debug"); } - - Main.Log($"Table not found: {tableName}", "debug"); - return string.Empty; } - public static Dictionary HashGetAll(string tableName) + public static async Task HashGetAllAsync(string tableName, string function, string uniqueId, string entity = null, string call = "false", int bufferSize = Main.ARDB_BUFFERSIZE) { Main.Log($"Getting contents for table: {tableName}", "debug"); + if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(function)) + { + Main.Log($"ArmaRAMDb 'tableName' or 'function' cannot be empty", "debug"); + return; + } + + await Task.Yield(); + if (_hashTables.TryGetValue(tableName, out var table)) { var contents = table.ToDictionary(kv => kv.Key, kv => kv.Value); @@ -42,45 +62,53 @@ namespace ArmaRAMDb Main.Log($"Key: {entry.Key}, Value: {entry.Value}", "debug"); } - return contents; + string data = string.Join(",", contents.Select(kv => $"[\"{kv.Key}\",{kv.Value}]")); + Utils.CheckByteCount(uniqueId, $"[{data}]", function, entity, Convert.ToBoolean(call), bufferSize); + } + else + { + Main.Log($"Table {tableName} not found", "debug"); } - - Main.Log($"Table {tableName} not found", "debug"); - return []; } - public static bool HashRemove(string tableName, string key) + public static async Task HashRemoveAsync(string tableName, string key) { + await Task.Yield(); + if (_hashTables.TryGetValue(tableName, out var table)) { - var result = table.TryRemove(key, out _); - Main.Log($"HashRemove: {tableName} - {key} - Success: {result}", "debug"); - return result; + table.TryRemove(key, out _); + } + else + { + Main.Log($"Table not found: {tableName}", "debug"); } - - Main.Log($"Table {tableName} or Key {key} not found", "debug"); - return false; } - public static bool HashSet(string tableName, string key, string value) + public static async Task HashSetBulkAsync(string tableName, Dictionary values) { var table = _hashTables.GetOrAdd(tableName, _ => new ConcurrentDictionary()); - table.AddOrUpdate(key, value, (_, _) => value); - Main.Log($"HashSet: {tableName} - {key} - {value}", "debug"); - return true; - } + await Task.Yield(); - public static bool HashSetBulk(string tableName, Dictionary values) - { - var table = _hashTables.GetOrAdd(tableName, _ => new ConcurrentDictionary()); foreach (var kv in values) { - table.AddOrUpdate(kv.Key, kv.Value, (_, _) => kv.Value); - Main.Log($"HashSetBulk: {tableName} - {kv.Key} - {kv.Value}", "debug"); + var value = kv.Value; + if (value.StartsWith('[') && value.EndsWith(']')) + { + table.AddOrUpdate(kv.Key, value, (_, _) => value); + } + else + { + table.AddOrUpdate(kv.Key, $"[\"{value}\"]", (_, _) => $"[\"{value}\"]"); + } + Main.Log($"HashSet: {tableName} - {kv.Key} - {value}", "debug"); } + } - return true; + public static async Task HashSetAsync(string tableName, string key, string value) + { + await HashSetBulkAsync(tableName, new Dictionary { { key, value } }); } } } \ No newline at end of file diff --git a/extension/src/KeyValueStore.cs b/extension/src/KeyValueStore.cs index fdb04b8..f6701db 100644 --- a/extension/src/KeyValueStore.cs +++ b/extension/src/KeyValueStore.cs @@ -1,33 +1,50 @@ using System.Collections.Concurrent; +#pragma warning disable IDE0130 // Namespace does not match folder structure namespace ArmaRAMDb +#pragma warning restore IDE0130 // Namespace does not match folder structure { internal class KeyValueStore { private static readonly ConcurrentDictionary _keyValues = RAMDb._keyValues; - public static string GetValue(string key) + public static async Task GetAsync(string key, string function, string uniqueId, string entity = null, string call = "false", int buffersize = Main.ARDB_BUFFERSIZE) { + if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(function)) + { + Main.Log($"ArmaRAMDb 'key' or 'function' cannot be empty", "debug"); + return; + } + + await Task.Yield(); + string value = _keyValues.TryGetValue(key, out string data) ? data : string.Empty; - Main.Log($"GetValue: {key} - Value: {value}", "debug"); - return value; + + Utils.CheckByteCount(uniqueId, value, function, entity, Convert.ToBoolean(call), buffersize); } - public static bool DeleteValue(string key) + public static async Task SetAsync(string key, string value) { - var result = _keyValues.TryRemove(key, out _); - - Main.Log($"DeleteValue: {key} - Success: {result}", "debug"); - return result; - } - - public static bool SetValue(string key, string value) - { - _keyValues.AddOrUpdate(key, value, (_, _) => value); + await Task.Yield(); + if (value.StartsWith('[') && value.EndsWith(']')) + { + _keyValues.AddOrUpdate(key, value, (_, _) => value); + } + else + { + _keyValues.AddOrUpdate(key, $"[\"{value}\"]", (_, _) => $"[\"{value}\"]"); + } + Main.Log($"SetValue: {key} - Value: {value}", "debug"); - return true; + } + + public static async Task DeleteAsync(string key) + { + await Task.Yield(); + var result = _keyValues.TryRemove(key, out _); + Main.Log($"DeleteValue: {key} - Success: {result}", "debug"); } } } \ No newline at end of file diff --git a/extension/src/ListStore.cs b/extension/src/ListStore.cs index f56e11e..39d3f31 100644 --- a/extension/src/ListStore.cs +++ b/extension/src/ListStore.cs @@ -1,107 +1,118 @@ using System.Collections.Concurrent; +#pragma warning disable IDE0130 // Namespace does not match folder structure namespace ArmaRAMDb +#pragma warning restore IDE0130 // Namespace does not match folder structure { internal class ListStore { private static readonly ConcurrentDictionary> _lists = RAMDb._lists; - public static bool ListAdd(string listName, string value) + public static async Task ListAddAsync(string listName, string value) { - if (_lists.TryGetValue(listName, out var list)) - { - lock (list) - { - list.Add(value); - Main.Log($"ListAdd: {listName} - Value: {value}", "debug"); - return true; - } - } - - Main.Log($"List not found: {listName}", "debug"); - return false; - } - - public static bool ListDelete(string listName) - { - var result = _lists.TryRemove(listName, out _); - - Main.Log($"ListDelete: {listName} - Success: {result}", "debug"); - return result; - } - - public static string ListIndex(string listName, int index) - { - if (_lists.TryGetValue(listName, out var list)) - { - lock (list) - { - string value = index >= 0 && index < list.Count ? list[index] : string.Empty; - Main.Log($"ListIndex: {listName} - Index: {index} - Value: {value}", "debug"); - return value; - } - } - - Main.Log($"List not found: {listName}", "debug"); - return string.Empty; - } - - public static List ListRange(string listName, int startIndex, int endIndex) - { - if (_lists.TryGetValue(listName, out var list)) - { - lock (list) - { - startIndex = Math.Max(0, startIndex); - endIndex = Math.Min(list.Count - 1, endIndex); - - if (startIndex <= endIndex) - { - int count = endIndex - startIndex + 1; - var value = list.GetRange(startIndex, count); - Main.Log($"ListRange: {listName} - StartIndex: {startIndex} - EndIndex: {endIndex} - Count: {count}", "debug"); - return value; - } - } - } + await Task.Yield(); - Main.Log($"List not found: {listName}", "debug"); - return []; + lock (_lists) + { + if (!_lists.TryGetValue(listName, out List list)) + { + list = []; + _lists[listName] = list; + } + + lock (list) + { + if (value.StartsWith('[') && value.EndsWith(']')) + { + list.Add(value); + } + else + { + list.Add($"[\"{value}\"]"); + } + Main.Log($"ListAdd: {listName} - Value: {value}", "debug"); + } + } } - public static bool ListRemove(string listName, string value) + public static async Task ListIndexAsync(string listName, string index, string function, string uniqueId, string entity = null, string call = "false", int bufferSize = Main.ARDB_BUFFERSIZE) { + await Task.Yield(); + + if (_lists.TryGetValue(listName, out var list)) + { + lock (list) + { + int idx = int.Parse(index); + string value = idx >= 0 && idx < list.Count ? list[idx] : string.Empty; + Main.Log($"ListIndex: {listName} - Index: {idx} - Value: {value}", "debug"); + Utils.CheckByteCount(uniqueId, value, function, entity, Convert.ToBoolean(call), bufferSize); + } + } + } + + public static async Task ListRangeAsync(string listName, string startIndex, string endIndex, string function, string uniqueId, string entity = null, string call = "false", int bufferSize = Main.ARDB_BUFFERSIZE) + { + await Task.Yield(); + + if (_lists.TryGetValue(listName, out var list)) + { + lock (list) + { + int start = int.Parse(startIndex); + int end = int.Parse(endIndex); + start = Math.Max(0, start); + end = Math.Min(list.Count - 1, end); + + if (start <= end) + { + int count = end - start + 1; + var value = list.GetRange(start, count); + string data = string.Join(",", value); + Main.Log($"ListRange: {listName} - StartIndex: {start} - EndIndex: {end} - Count: {count}", "debug"); + Utils.CheckByteCount(uniqueId, $"[{data}]", function, entity, Convert.ToBoolean(call), bufferSize); + } + } + } + } + + public static async Task ListSetAsync(string listName, string index, string value) + { + await Task.Yield(); + + if (_lists.TryGetValue(listName, out var list)) + { + lock (list) + { + int idx = int.Parse(index); + if (idx >= 0 && idx < list.Count) + { + if (value.StartsWith('[') && value.EndsWith(']')) + { + list[idx] = value; + } + else + { + list[idx] = $"[\"{value}\"]"; + } + Main.Log($"ListSet: {listName} - Index: {idx} - Value: {value}", "debug"); + } + } + } + } + + public static async Task ListRemoveAsync(string listName, string value) + { + await Task.Yield(); + if (_lists.TryGetValue(listName, out var list)) { lock (list) { int removedCount = list.RemoveAll(item => item == value); Main.Log($"ListRemove: {listName} - Value: {value} - Removed Count: {removedCount}", "debug"); - return removedCount > 0; } } - - Main.Log($"List not found: {listName}", "debug"); - return false; - } - - public static bool ListSet(string listName, int index, string value) - { - if (_lists.TryGetValue(listName, out var list)) - { - lock (list) - { - if (index >= 0 && index < list.Count) - { - list[index] = value; - Main.Log($"ListSet: {listName} - Index: {index} - Value: {value}", "debug"); - return true; - } - } - } - - Main.Log($"List not found: {listName}", "debug"); - return false; } } } \ No newline at end of file diff --git a/extension/src/Main.cs b/extension/src/Main.cs index b701737..8ad92ed 100644 --- a/extension/src/Main.cs +++ b/extension/src/Main.cs @@ -2,7 +2,9 @@ using System.Text; using System.Xml.Linq; +#pragma warning disable IDE0130 // Namespace does not match folder structure namespace ArmaRAMDb +#pragma warning restore IDE0130 // Namespace does not match folder structure { public class CallContext { @@ -16,6 +18,7 @@ namespace ArmaRAMDb public class Main { private const string ARDB_VERSION = "1.0.0"; + public const int ARDB_BUFFERSIZE = 1024; public static string ARDB_LOGFOLDER { get; private set; } = "\\@ramdb\\logs"; public static bool ARDB_DEBUG {get; private set; } = false; public static bool ARDB_INITCHECK {get; private set; } = false; @@ -200,55 +203,47 @@ namespace ArmaRAMDb WriteOutput(output, "Async"); return 200; case "get": - HandleGetOperation(args, argc); + HandleGetOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_get\",{args[0]}]"); return 100; case "hdel": - HandleHashDeleteOperation(args, argc); + HandleHDelOperation(args, argc); WriteOutput(output, "Async"); return 200; case "hdelid": - HandleHashDeleteIdOperation(args, argc); + HandleHDelIdOperation(args, argc); WriteOutput(output, "Async"); return 200; case "hget": - HandleHashGetOperation(args, argc); + HandleHGetOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_hget\",{args[1]}]"); return 100; case "hgetid": - HandleHashGetIdOperation(args, argc); + HandleHGetIdOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_hgetid\",{args[0]}]"); return 100; case "hgetall": - HandleHashGetAllOperation(args, argc); + HandleHGetAllOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_hgetall\",{args[0]}]"); return 100; case "hgetallid": - HandleHashGetAllIdOperation(args, argc); + HandleHGetAllIdOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_hgetallid\",{args[0]}]"); return 100; case "hrem": - HandleHashRemoveOperation(args, argc); + HandleHRemOperation(args, argc); WriteOutput(output, "Async"); return 200; case "hremid": - HandleHashRemoveIdOperation(args, argc); + HandleHRemIdOperation(args, argc); WriteOutput(output, "Async"); return 200; case "hset": - HandleHashSetOperation(args, argc); + HandleHSetOperation(args, argc); WriteOutput(output, "Async"); return 200; case "hsetid": - HandleHashSetIdOperation(args, argc); - WriteOutput(output, "Async"); - return 200; - case "hsetbulk": - HandleHashSetBulkOperation(args, argc); - WriteOutput(output, "Async"); - return 200; - case "hsetbulkid": - HandleHashSetBulkIdOperation(args, argc); + HandleHSetIdOperation(args, argc); WriteOutput(output, "Async"); return 200; case "isloaded": @@ -258,22 +253,18 @@ namespace ArmaRAMDb HandleListAddOperation(args, argc); WriteOutput(output, "Async"); return 200; - case "listdel": - HandleListDeleteOperation(args, argc); - WriteOutput(output, "Async"); - return 200; case "listidx": - HandleListIndexOperation(args, argc); + HandleListIdxOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_listindex\",{args[0]}]"); return 100; + case "listrem": + HandleListRemOperation(args, argc); + WriteOutput(output, "Async"); + return 200; case "listrng": - HandleListRangeOperation(args, argc); + HandleListRngOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_listrange\",{args[0]}]"); return 100; - case "listrem": - HandleListRemoveOperation(args, argc); - WriteOutput(output, "Async"); - return 200; case "listset": HandleListSetOperation(args, argc); WriteOutput(output, "Async"); @@ -294,7 +285,7 @@ namespace ArmaRAMDb WriteOutput(output, ARDB_VERSION); return 100; default: - WriteOutput(output, "Available functions: delete, get, hget, hgetid, hgetall, hgetallid, hset, hsetid, hsetbulk, hsetbulkid, isloaded, load, save, set, version"); + WriteOutput(output, "Available functions: del, get, hdel, hdelid, hget, hgetid, hgetall, hgetallid, hrem, hremid, hset, hsetid, isloaded, listadd, listidx, listrem, listrng, listset, load, save, set, version"); return -1; } } @@ -352,226 +343,241 @@ namespace ArmaRAMDb } #pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashDeleteOperation(List args, int argc) + private static void HandleHDelOperation(List args, int argc) #pragma warning restore IDE0060 // Remove unused parameter { - HashStore.HashDelete(STEAMID); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashDeleteIdOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - HashStore.HashDelete(args[0]); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashGetOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - var value = HashStore.HashGet(STEAMID, args[0]); - - Log($"HashGet: {SerializeList([value])}", "debug"); - Callback("ArmaRAMDb", args[1].Trim('"'), SerializeList([value])); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashGetIdOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - var value = HashStore.HashGet(args[0], args[1]); - - Log($"HashGetId: {SerializeList([value])}", "debug"); - Callback("ArmaRAMDb", args[2].Trim('"'), SerializeList([value])); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashGetAllOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - var contents = HashStore.HashGetAll(STEAMID); - var list = contents.SelectMany(kv => new[] { kv.Key, kv.Value }).ToList(); - - Log($"HashGetAll: {SerializeList(list)}", "debug"); - Callback("ArmaRAMDb", args[0].Trim('"'), SerializeList(list)); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashGetAllIdOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - var hashId = args[0]; - var contents = HashStore.HashGetAll(hashId); - var list = contents.SelectMany(kv => new[] { kv.Key, kv.Value }).ToList(); - - Log($"HashGetAllId: {SerializeList(list)}", "debug"); - Callback("ArmaRAMDb", args[1].Trim('"'), SerializeList(list)); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashRemoveOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - HashStore.HashRemove(STEAMID, args[0]); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashRemoveIdOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - var value = HashStore.HashRemove(args[0], args[1]); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashSetOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - Log($"HashSet: {SerializeList(args)}", "debug"); - HashStore.HashSet(STEAMID, args[0], args[1]); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashSetIdOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - Log($"HashSetId: {SerializeList(args)}", "debug"); - HashStore.HashSet(args[0], args[1], args[2]); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashSetBulkOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - var values = new Dictionary(); - - for (int i = 0; i < args.Count; i += 2) + Task.Run(async () => { - string key = args[i]; - string value = args[i + 1]; - values.Add(key, value); - } - - Log($"BulkHashSet: Keys={string.Join(",", values.Keys)}", "debug"); - HashStore.HashSetBulk(STEAMID, values); + await HashStore.HashDelete(STEAMID); + }); } #pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHashSetBulkIdOperation(List args, int argc) + private static void HandleHDelIdOperation(List args, int argc) #pragma warning restore IDE0060 // Remove unused parameter { - var hashId = args[0]; - var values = new Dictionary(); - - for (int i = 1; i < args.Count; i += 2) + Task.Run(async () => { - string key = args[i]; - string value = args[i + 1]; - values.Add(key, value); - } - - Log($"BulkHashSetId: Keys={string.Join(",", values.Keys)}", "debug"); - HashStore.HashSetBulk(hashId, values); + await HashStore.HashDelete(args[0].Trim('"')); + }); + } + + private static void HandleHGetOperation(long _id, List args, int argc) + { + Task.Run(async () => + { + string _uniqueID = $"{_id}_hget"; + if (argc == 2) + await HashStore.HashGet(STEAMID, args[0].Trim('"'), args[1].Trim('"'), _uniqueID); + if (argc == 3) + await HashStore.HashGet(STEAMID, args[0].Trim('"'), args[1].Trim('"'), _uniqueID, args[2].Trim('"')); + if (argc == 4) + await HashStore.HashGet(STEAMID, args[0].Trim('"'), args[1].Trim('"'), _uniqueID, args[2].Trim('"'), args[3].Trim('"')); + }); + } + + private static void HandleHGetIdOperation(long _id, List args, int argc) + { + Task.Run(async () => + { + string _uniqueID = $"{_id}_hgetid"; + if (argc == 3) + await HashStore.HashGet(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), _uniqueID); + if (argc == 4) + await HashStore.HashGet(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), _uniqueID, args[3].Trim('"')); + if (argc == 5) + await HashStore.HashGet(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), _uniqueID, args[3].Trim('"'), args[4].Trim('"')); + }); + } + + private static void HandleHGetAllOperation(long _id, List args, int argc) + { + Task.Run(async () => + { + string _uniqueID = $"{_id}_hgetall"; + if (argc == 1) + await HashStore.HashGetAllAsync(STEAMID, args[0].Trim('"'), _uniqueID); + if (argc == 2) + await HashStore.HashGetAllAsync(STEAMID, args[0].Trim('"'), _uniqueID, args[1].Trim('"')); + if (argc == 3) + await HashStore.HashGetAllAsync(STEAMID, args[0].Trim('"'), _uniqueID, args[1].Trim('"'), args[2].Trim('"')); + }); + } + + private static void HandleHGetAllIdOperation(long _id, List args, int argc) + { + Task.Run(async () => + { + string _uniqueID = $"{_id}_hgetallid"; + if (argc == 2) + await HashStore.HashGetAllAsync(args[0].Trim('"'), args[1].Trim('"'), _uniqueID); + if (argc == 3) + await HashStore.HashGetAllAsync(args[0].Trim('"'), args[1].Trim('"'), _uniqueID, args[2].Trim('"')); + if (argc == 4) + await HashStore.HashGetAllAsync(args[0].Trim('"'), args[1].Trim('"'), _uniqueID, args[2], args[3].Trim('"')); + }); } #pragma warning disable IDE0060 // Remove unused parameter + private static void HandleHRemOperation(List args, int argc) +#pragma warning restore IDE0060 // Remove unused parameter + { + Task.Run(async () => + { + await HashStore.HashRemoveAsync(STEAMID, args[0].Trim('"')); + }); + } + +#pragma warning disable IDE0060 // Remove unused parameter + private static void HandleHRemIdOperation(List args, int argc) +#pragma warning restore IDE0060 // Remove unused parameter + { + Task.Run(async () => + { + await HashStore.HashRemoveAsync(args[0].Trim('"'), args[1].Trim('"')); + }); + } + + private static void HandleHSetOperation(List args, int argc) + { + Task.Run(async () => + { + if (argc > 2) + { + var bulkValues = new Dictionary(); + for (var i = 0; i < argc; i += 2) + { + bulkValues[args[i].Trim('"')] = args[i + 1]; + } + await HashStore.HashSetBulkAsync(STEAMID, bulkValues); + } + else + { + await HashStore.HashSetAsync(STEAMID, args[0].Trim('"'), args[1].Trim('"')); + } + }); + } + + private static void HandleHSetIdOperation(List args, int argc) + { + Task.Run(async () => + { + if (argc > 4) + { + var bulkValues = new Dictionary(); + for (var i = 1; i < argc; i += 2) + { + bulkValues[args[i].Trim('"')] = args[i + 1]; + } + await HashStore.HashSetBulkAsync(args[0].Trim('"'), bulkValues); + } + else + { + await HashStore.HashSetAsync(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"')); + } + }); + } + private static void HandleListAddOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter { - var key = args[0]; - var value = args[1]; - - Log($"ListAdd: {SerializeList([key, value])}", "debug"); - ListStore.ListAdd(key, value); + Task.Run(async () => + { + switch (argc) + { + case > 2: + for (var i = 0; i < argc; i++) + { + await ListStore.ListAddAsync(args[0].Trim('"'), args[i]); + } + break; + default: + await ListStore.ListAddAsync(args[0].Trim('"'), args[1].Trim('"')); + break; + } + }); } #pragma warning disable IDE0060 // Remove unused parameter - private static void HandleListDeleteOperation(List args, int argc) + private static void HandleListRemOperation(List args, int argc) #pragma warning restore IDE0060 // Remove unused parameter { - var listId = args[0]; - - Log($"ListDelete: {SerializeList([listId])}", "debug"); - ListStore.ListDelete(listId); + Task.Run(async () => + { + await ListStore.ListSetAsync(args[0].Trim('"'), args[1].Trim('"'), "RAMDBREMOVE"); + await ListStore.ListRemoveAsync(args[0].Trim('"'), "RAMDBREMOVE"); + }); } -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleListIndexOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter + private static void HandleListIdxOperation(long _id, List args, int argc) { - var listId = args[0]; - var key = args[1]; - var value = ListStore.ListIndex(listId, int.Parse(key)); - - Log($"ListIndex: {SerializeList([key, value])}", "debug"); - Callback("ArmaRAMDb", args[2].Trim('"'), SerializeList([value])); + Task.Run(async () => + { + string _uniqueID = $"{_id}_listidx"; + if (argc == 3) + await ListStore.ListIndexAsync(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), _uniqueID); + if (argc == 4) + await ListStore.ListIndexAsync(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), _uniqueID, args[3].Trim('"')); + if (argc == 5) + await ListStore.ListIndexAsync(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), _uniqueID, args[3].Trim('"'), args[4].Trim('"')); + }); } -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleListRangeOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter + private static void HandleListRngOperation(long _id, List args, int argc) { - var listId = args[0]; - var startIndex = int.Parse(args[1]); - var endIndex = int.Parse(args[2]); - - var values = ListStore.ListRange(listId, startIndex, endIndex); - - Log($"ListRange: ListId={listId} Start={startIndex} End={endIndex} Values={SerializeList(values)}", "debug"); - Callback("ArmaRAMDb", args[3].Trim('"'), SerializeList(values)); - } - -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleListRemoveOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter - { - var listId = args[0]; - var index = int.Parse(args[1]); - - ListStore.ListSet(listId, index, "RAMDBREMOVE"); - ListStore.ListRemove(listId, "RAMDBREMOVE"); + Task.Run(async () => + { + string _uniqueID = $"{_id}_listrng"; + if (argc == 4) + await ListStore.ListRangeAsync(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), args[3].Trim('"'), _uniqueID); + if (argc == 5) + await ListStore.ListRangeAsync(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), args[3].Trim('"'), _uniqueID, args[4].Trim('"')); + if (argc == 6) + await ListStore.ListRangeAsync(args[0].Trim('"'), args[1].Trim('"'), args[2].Trim('"'), args[3].Trim('"'), _uniqueID, args[4].Trim('"'), args[5].Trim('"')); + }); } #pragma warning disable IDE0060 // Remove unused parameter private static void HandleListSetOperation(List args, int argc) #pragma warning restore IDE0060 // Remove unused parameter { - var listId = args[0]; - var index = int.Parse(args[1]); - var value = args[2]; - - ListStore.ListSet(listId, index, value); + Task.Run(async () => + { + await ListStore.ListSetAsync(args[0].Trim('"'), args[1].Trim('"'), args[2]); + }); } #pragma warning disable IDE0060 // Remove unused parameter private static void HandleSetOperation(List args, int argc) #pragma warning restore IDE0060 // Remove unused parameter { - var key = args[0]; - var value = args[1]; - - KeyValueStore.SetValue(key, value); - Log($"Set: Key={key} Value={value}", "debug"); + Task.Run(async () => + { + await KeyValueStore.SetAsync(args[0].Trim('"'), args[1]); + }); } -#pragma warning disable IDE0060 // Remove unused parameter - private static void HandleGetOperation(List args, int argc) -#pragma warning restore IDE0060 // Remove unused parameter + private static void HandleGetOperation(long _id, List args, int argc) { - var key = args[0]; - var value = KeyValueStore.GetValue(key); - - Log($"Get: Key={key} Value={value}", "debug"); - Callback("ArmaRAMDb", args[1].Trim('"'), SerializeList([value])); + Task.Run(async () => + { + string _uniqueID = $"{_id}_get"; + if (argc == 2) + await KeyValueStore.GetAsync(args[0].Trim('"'), args[1].Trim('"'), _uniqueID); + if (argc == 3) + await KeyValueStore.GetAsync(args[0].Trim('"'), args[1].Trim('"'), _uniqueID, args[2].Trim('"')); + if (argc == 4) + await KeyValueStore.GetAsync(args[0].Trim('"'), args[1].Trim('"'), _uniqueID, args[2].Trim('"'), args[3].Trim('"')); + }); } #pragma warning disable IDE0060 // Remove unused parameter private static void HandleDeleteOperation(List args, int argc) #pragma warning restore IDE0060 // Remove unused parameter { - var key = args[0]; - - KeyValueStore.DeleteValue(key); - Log($"Delete: Key={key}", "debug"); + Task.Run(async () => + { + await KeyValueStore.DeleteAsync(args[0].Trim('"')); + }); } } } \ No newline at end of file diff --git a/extension/src/RAMDb.cs b/extension/src/RAMDb.cs index 8747737..50a388a 100644 --- a/extension/src/RAMDb.cs +++ b/extension/src/RAMDb.cs @@ -1,7 +1,9 @@ using System.Xml.Linq; using System.Collections.Concurrent; +#pragma warning disable IDE0130 // Namespace does not match folder structure namespace ArmaRAMDb +#pragma warning restore IDE0130 // Namespace does not match folder structure { internal class RAMDb(string path = RAMDb.DEFAULT_STORAGE_PATH) : IDisposable { diff --git a/extension/src/Utils.cs b/extension/src/Utils.cs new file mode 100644 index 0000000..bdc063d --- /dev/null +++ b/extension/src/Utils.cs @@ -0,0 +1,70 @@ +using System.Text; + +#pragma warning disable IDE0130 // Namespace does not match folder structure +namespace ArmaRAMDb +#pragma warning restore IDE0130 // Namespace does not match folder structure +{ + internal class Utils + { + public static string Base64Decode(string encodedString) + { + byte[] data = Convert.FromBase64String(encodedString); + return Encoding.UTF8.GetString(data); + } + + public static string Base64Encode(string plainText) + { + byte[] data = Encoding.UTF8.GetBytes(plainText); + return Convert.ToBase64String(data); + } + + public static string BuildArray(string text) + { + string str = $"[\"{text}\"]"; + return str; + } + + public static List SplitIntoChunks(string data, int chunkSize) + { + int chunksNeeded = (int)Math.Ceiling((double)data.Length / chunkSize); + List chunks = []; + + for (int i = 0; i < chunksNeeded; i++) + { + int start = i * chunkSize; + int end = Math.Min(data.Length, start + chunkSize); + chunks.Add(data[start..end]); + } + + return chunks; + } + + public static void CheckByteCount(string uniqueId, string data, string function, string entity, bool call, int bufferSize) + { + if (Encoding.UTF8.GetByteCount(data) <= bufferSize) + { + if (!data.StartsWith('[')) + data = BuildArray(data); + Main.Log($"{data}", "debug"); + + string dataAsString = $"[\"{uniqueId}\",\"{function}\",{call},{data},\"{entity}\"]"; + Main.Log($"{dataAsString}", "debug"); + Main.Callback("ArmaRAMDb", "ramdb_db_fnc_handler", dataAsString); + } + else + { + if (!data.StartsWith('[')) + data = BuildArray(data); + Main.Log($"{data}", "debug"); + var chunks = SplitIntoChunks(data, bufferSize); + int totalChunks = chunks.Count; + + foreach (string chunk in chunks) + { + string chunkAsString = $"[{uniqueId},{function},{chunks.IndexOf(chunk)},{totalChunks},\"{chunk}\",{call},\"{entity}\"]"; + Main.Callback("ArmaRAMDb", "ramdb_db_fnc_fetch", chunkAsString); + } + } + } + } +} \ No newline at end of file