#include "..\script_component.hpp" /* * Function: forge_server_db_fnc_initDB * Author: J. Schmidt * * Description: * Initializes the database system, creating the interface for other modules * * Arguments: * None * * Return Value: * Database interface object */ private _storeInterface = createHashMapObject [[ ["#type", "IStore"], ["#create", { private _storeRegistry = GETVAR(profileNamespace,FORGE_STORE_REG,createHashMap); _self set ["stores", _storeRegistry]; true }], ["save", { private _stores = _self get "stores"; SETVAR(profileNamespace,FORGE_STORE_REG,_stores); saveProfileNamespace; true }], ["create", { params [["_name", "", [""]]]; if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); nil }; private _stores = _self get "stores"; private _store = createHashMap; _stores set [_name, _store]; _self call ["save"]; _store }], ["set", { params [["_name", "", [""]]]; if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); nil }; private _stores = _self get "stores"; private _store = _self call ["get", [_name]]; if (isNil "_store") then { _store = _self call ["create", [_name]]; }; _store }], ["get", { params [["_name", "", [""]]]; if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); nil }; private _stores = _self get "stores"; _stores get _name }], ["delete", { params [["_name", "", [""]]]; if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); false }; private _stores = _self get "stores"; private _store = _self call ["get", [_name]]; if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); false }; _stores deleteAt _name; true }], ["hset", { params [["_name", "", [""]], ["_key", "", [""]], ["_value", "", ["", [], 0, false, createHashMap]]]; if (_name == "" || _key == "") exitWith { ERROR_MSG("Store name and, or key cannot be empty"); false }; private _stores = _self get "stores"; private _store = _self call ["get", [_name]]; if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); false }; _store set [_key, _value]; _stores set [_name, _store]; _self call ["save"]; true }], ["hget", { params [["_name", "", [""]], ["_key", "", [""]]]; if (_name == "" || _key == "") exitWith { ERROR_MSG("Store name and, or key cannot be empty"); _default }; private _store = _self call ["get", [_name]]; if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); _default }; _store get _key }], ["hdel", { params [["_name", "", [""]], ["_key", "", [""]]]; if (_name == "" || _key == "") exitWith { ERROR_MSG("Store name and, or key cannot be empty"); false }; private _store = _self call ["get", [_name]]; if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); false }; _store deleteAt _key; true }] ]]; SETPVAR(missionNamespace,FORGE_STORE_REG,_storeInterface); GETMVAR(FORGE_STORE_REG,nil)