forge/arma/server/addons/locker/functions/fnc_initLockerStore.sqf
Jacob Schmidt 53bc8db7d0 Handle bank account sync in UI bridge
- Route bank sync payloads through the client bridge
- Refresh account state without rebuilding the full session
- Split CAD dispatcher UI into modular source files
2026-04-02 09:10:12 -05:00

235 lines
8.6 KiB
Plaintext

#include "..\script_component.hpp"
/*
* File: fnc_initLockerStore.sqf
* Author: IDSolutions
* Date: 2025-12-17
* Last Update: 2026-04-01
* Public: No
*
* Description:
* Initializes the Locker store for managing player locker items.
* Locker hot state is owned by the extension; SQF acts as a thin bridge.
*
* Arguments:
* None
*
* Return Value:
* Locker store object [HASHMAP OBJECT]
*
* Example:
* call forge_server_locker_fnc_initLockerStore
*/
#pragma hemtt ignore_variables ["_self"]
GVAR(LockerBaseStore) = compileFinal createHashMapFromArray [
["#base", EGVAR(common,BaseStore)],
["#type", "LockerBaseStore"],
["#create", compileFinal {
["INFO", "Locker Store Initialized!"] call EFUNC(common,log);
}],
["callHotLocker", compileFinal {
params [["_function", "", [""]], ["_arguments", [], [[]]]];
if (_function isEqualTo "") exitWith { createHashMap };
[_function, _arguments] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
if !(_isSuccess) exitWith { createHashMap };
if !(_result isEqualType "") exitWith { createHashMap };
if ((_result find "Error:") == 0) exitWith {
["ERROR", format ["Locker extension call '%1' failed: %2", _function, _result]] call EFUNC(common,log);
createHashMap
};
private _data = fromJSON _result;
if !(_data isEqualType createHashMap) exitWith { createHashMap };
_data
}],
["loadHotLocker", compileFinal {
params [["_uid", "", [""]], ["_initialize", false, [false]]];
if (_uid isEqualTo "") exitWith { createHashMap };
private _command = ["locker:hot:get", "locker:hot:init"] select _initialize;
_self call ["callHotLocker", [_command, [_uid]]]
}],
["init", compileFinal {
params [["_uid", "", [""]]];
private _player = [_uid] call EFUNC(common,getPlayer);
if (isNull _player) exitWith { createHashMap };
private _locker = _self call ["loadHotLocker", [_uid, true]];
if (_locker isEqualTo createHashMap) then {
["ERROR", format ["Failed to initialize locker for %1! Using fallback locker.", _uid]] call EFUNC(common,log);
};
[CRPC(locker,responseInitLocker), [_locker], _player] call CFUNC(targetEvent);
_locker
}],
["get", compileFinal {
params [["_uid", "", [""]], ["_field", "", [""]]];
private _locker = _self call ["loadHotLocker", [_uid, false]];
if (_locker isEqualTo createHashMap) then {
_locker = _self call ["loadHotLocker", [_uid, true]];
};
if (_field isEqualTo "") exitWith { _locker };
_locker getOrDefault [_field, createHashMap]
}],
["override", compileFinal {
params [
["_uid", "", [""]],
["_data", createHashMap, [createHashMap]],
["_save", false, [false]]
];
if (_uid isEqualTo "") exitWith { createHashMap };
if !(_data isEqualType createHashMap) exitWith { createHashMap };
private _locker = _self call ["callHotLocker", ["locker:hot:override", [_uid, toJSON _data]]];
if (_save && { _locker isNotEqualTo createHashMap }) then {
private _savedLocker = _self call ["callHotLocker", ["locker:hot:save", [_uid]]];
if (_savedLocker isNotEqualTo createHashMap) then {
_locker = _savedLocker;
} else {
_locker = createHashMap;
};
};
_locker
}],
["set", compileFinal {
params [
["_uid", "", [""]],
["_field", "", [""]],
["_value", nil, [0, "", [], false, createHashMap, objNull, grpNull]],
["_sync", false, [false]]
];
if (_uid isEqualTo "" || { _field isEqualTo "" }) exitWith { createHashMap };
private _locker = _self call ["get", [_uid, ""]];
if !(_locker isEqualType createHashMap) exitWith { createHashMap };
_locker set [_field, _value];
private _updatedLocker = _self call ["override", [_uid, _locker, _sync]];
if !(_updatedLocker isEqualType createHashMap) exitWith { createHashMap };
if (_updatedLocker isEqualTo createHashMap) exitWith { createHashMap };
createHashMapFromArray [[_field, _updatedLocker getOrDefault [_field, _value]]]
}],
["mset", compileFinal {
params [
["_uid", "", [""]],
["_fieldValuePairs", createHashMap, [createHashMap]],
["_sync", false, [false]]
];
if (_uid isEqualTo "") exitWith { createHashMap };
if !(_fieldValuePairs isEqualType createHashMap) exitWith { createHashMap };
private _locker = _self call ["get", [_uid, ""]];
if !(_locker isEqualType createHashMap) exitWith { createHashMap };
{ _locker set [_x, _y]; } forEach _fieldValuePairs;
private _updatedLocker = _self call ["override", [_uid, _locker, _sync]];
if !(_updatedLocker isEqualType createHashMap) exitWith { createHashMap };
if (_updatedLocker isEqualTo createHashMap) exitWith { createHashMap };
+_fieldValuePairs
}],
["save", compileFinal {
params [["_uid", "", [""]]];
if (_uid isEqualTo "") exitWith { createHashMap };
_self call ["callHotLocker", ["locker:hot:save", [_uid]]]
}],
["remove", compileFinal {
params [["_uid", "", [""]]];
if (_uid isEqualTo "") exitWith { false };
["locker:hot:remove", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
_isSuccess && { _result isEqualTo "OK" }
}],
["grantItems", compileFinal {
params [["_uid", "", [""]], ["_items", [], [[]]], ["_commit", false, [false]]];
private _result = createHashMapFromArray [
["success", false],
["message", "Locker grant failed."],
["patch", createHashMap],
["granted", []],
["locker", createHashMap]
];
private _locker = +(_self call ["get", [_uid, ""]]);
private _patch = createHashMap;
private _granted = [];
{
private _className = _x getOrDefault ["classname", ""];
private _category = toLowerANSI (_x getOrDefault ["category", ""]);
private _quantity = floor ((_x getOrDefault ["quantity", 0]) max 0);
private _lockerCategory = switch (_category) do {
case "item";
case "attachment": { "item" };
case "weapon": { "weapon" };
case "magazine": { "magazine" };
case "backpack": { "backpack" };
default { "" };
};
if (_className isEqualTo "" || { _lockerCategory isEqualTo "" } || { _quantity <= 0 }) then {
["WARN", format ["Skipping invalid locker grant entry: %1 (category: %2)", _className, _category]] call EFUNC(common,log);
} else {
private _entry = +(_locker getOrDefault [_className, createHashMap]);
private _amount = _entry getOrDefault ["amount", 0];
private _updatedEntry = createHashMapFromArray [
["amount", (_amount + _quantity)],
["classname", _className],
["category", _lockerCategory]
];
_locker set [_className, _updatedEntry];
_patch set [_className, _updatedEntry];
_granted pushBack (createHashMapFromArray [
["classname", _className],
["category", _lockerCategory],
["quantity", _quantity]
]);
};
} forEach _items;
if ((count (keys _locker)) > 25) exitWith {
_result set ["message", "Locker capacity would exceed 25 unique items. Clear space before checkout."];
_result
};
if (_commit) then {
private _savedLocker = _self call ["override", [_uid, _locker, false]];
if !(_savedLocker isEqualType createHashMap) exitWith {
_result set ["message", "Locker cache update returned invalid data."];
_result
};
if (_savedLocker isEqualTo createHashMap) exitWith {
_result set ["message", "Failed to update locker cache."];
_result
};
_locker = _savedLocker;
};
_result set ["success", true];
_result set ["message", ""];
_result set ["patch", _patch];
_result set ["granted", _granted];
_result set ["locker", _locker];
_result
}]
];
GVAR(LockerStore) = createHashMapObject [GVAR(LockerBaseStore)];
GVAR(LockerStore)