client/addons/org/functions/fnc_initOrgStore.sqf
Jacob Schmidt 613f05d52a Refactor: Database and Client Updates
This commit introduces several changes related to database interactions and client-side functionality:

*   **Database Response Handling:** Implements a mechanism to handle responses from server requests, specifically for database operations. This includes setting up a callback system to process results based on request IDs.
*   **Store Functionality:** Corrects a typo in the `fnc_buyItem.sqf` script, changing `EFUNC(armory,addArmoryItem)` to `EFUNC(arsenal,addArmoryItem)`.
*   **Inventory Management:** Improves the `fnc_moveInventory.sqf` script by correcting a conditional statement to ensure proper handling of inventory items.
*   **Configuration Updates:** Updates the mod configuration (`CfgMods.hpp`) to use the correct path for the mod picture.
*   **Client Initialization:** Adds a client registration call to the server during client post-initialization (`XEH_postInit_client.sqf`).
*   **Workflow Update:** Updates the build workflow to use the latest Ubuntu runner.
*   **Database Preparation:** Removes unnecessary preparations from `XEH_postInit.sqf` and `XEH_PREP.hpp`.
2025-03-28 09:46:24 -05:00

134 lines
4.5 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Function: forge_client_org_fnc_initOrgStore
* Author: J. Schmidt
*
* Description:
* Initializes player organization data using the database interface
*
* Arguments:
* None
*
* Return Value:
* Organization interface <OBJECT>
*/
private _orgStoreInterface = createHashMapObject [[
["#type", "IOrganizationStore"],
["#create", {
private _store = GETMVAR(FORGE_STORE_REG,nil);
if (isNil "_store") exitWith { ERROR_MSG("Store not initialized"); false };
private _orgStore = _store call ["getStore", ["organizations"]];
private _orgNameIndex = _store call ["getStore", ["organizationNameIndex"]];
private _orgRegistry = GETVAR(profileNamespace,FORGE_ORG_REG,createHashMap);
if (isNil "_orgStore" || isNil "_orgNameIndex") then { _orgStore = _store call ["createStore", ["organizations"]]; };
if (isNil "_orgNameIndex") then { _orgNameIndex = _store call ["createStore", ["organizationNameIndex"]]; };
private _name = _orgRegistry get "name";
private _uid = _orgRegistry get "owner";
if (!isNil "_name" && !isNil "_uid") then {
private _key = format ["%1_%2", _uid, _name];
_orgStore set [_key, _orgRegistry];
_orgNameIndex set [_key, _name];
};
true
}],
["post", {
params [["_uid", "", [""]], ["_name", "", [""]], ["_initialFunds", 0, [0]], ["_initialReputation", 0, [0]]];
if (_uid == "" || _name == "") exitWith { ERROR_MSG("Owner UID and, or name cannot be empty"); nil };
private _store = GETMVAR(FORGE_STORE_REG,nil);
private _key = format ["%1_%2", _uid, _name];
private _timestamp = systemTimeUTC apply { if (_x < 10) then { "0" + str _x } else { str _x }};
private _dateTime = format ["%1-%2-%3_%4:%5:%6.%7", _timestamp#0, _timestamp#1, _timestamp#2, _timestamp#3, _timestamp#4, _timestamp#5, _timestamp#6];
private _orgRegistry = GETVAR(profileNamespace,FORGE_ORG_REG,createHashMap);
private _existingOrgKey = _store call ["get", ["organizationNameIndex", _key]];
private _existingOrg = nil;
private _orgData = nil;
if !(isNil "_existingOrgKey") then {
_existingOrg = _store call ["get", ["organizations", _existingOrgKey]];
};
if !(isNil "_existingOrg") then {
_orgData = _existingOrg;
} else {
_orgData = createHashMapFromArray [
["name", _name],
["owner", _uid],
["funds", _initialFunds],
["reputation", _initialReputation],
["assets", createHashMap],
["members", createHashMap],
["invites", createHashMap],
["logs", []],
["created", _dateTime]
];
_orgRegistry set [_key, _orgData];
SETVAR(profileNamespace,FORGE_ORG_REG,_orgRegistry);
saveProfileNamespace;
};
_store call ["set", ["organizationNameIndex", _key, _name]];
_store call ["set", ["organizations", _key, _orgData]];
_orgData
}],
["get", {
private _store = GETMVAR(FORGE_STORE_REG,nil);
private _orgStore = _store call ["getStore", ["organizations"]];
if (isNil "_orgStore") exitWith { createHashMap };
_orgStore
}],
["getByKey", {
params [["_key", "", [""]]];
if (_key == "") exitWith { ERROR_MSG("Key cannot be empty"); nil };
private _store = GETMVAR(FORGE_STORE_REG,nil);
private _org = _store call ["get", ["organizations", _key]]
if (isNil "_org") exitWith { ERROR_MSG_1("Organization with composite key %1 not found", _key); nil };
_org
}],
["delete", {
params [["_key", "", [""]]];
if (_key == "") exitWith { ERROR_MSG("Key cannot be empty"); false };
private _store = GETMVAR(FORGE_STORE_REG,nil);
private _key = _store call ["get", ["organizationNameIndex", _key, nil]];
_store call ["delete", ["organizationNameIndex", _key]];
if (isNil "_key") exitWith { ERROR_MSG_1("Key for organization not found", _key); false };
_store call ["delete", ["organizations", _key]];
private _orgRegistry = GETVAR(profileNamespace,FORGE_ORG_REG,createHashMap);
_orgRegistry deleteAt _key;
SETVAR(profileNamespace,FORGE_ORG_REG,_orgRegistry);
saveProfileNamespace;
true
}]
]];
SETMVAR(FORGE_ORG_STORE_REG,_orgStoreInterface);
GETMVAR(FORGE_ORG_STORE_REG,nil)