forge/arma/server/addons/bank/functions/fnc_initBankStore.sqf
Jacob Schmidt ebfe77a340 feat: implement complete Forge framework with Rust/Redis backend and Arma 3 integration
Implemented features:
- High-performance Rust extension with Redis persistence
- Actor/player management with loadout, position, and state tracking
- Banking system with deposit, withdraw, and transfer operations
- Physical and virtual garage/locker systems for vehicle and equipment storage
- Organization management with member tracking and permissions
- Client-side UI with React-like state management
- Server-side event-driven architecture with CBA Events
- Security: Self-transfer prevention at multiple layers
- Logging system with per-module log files
- ICOM module for inter-server communication

Co-Authored-By: Warp <agent@warp.dev>
2026-01-04 12:52:15 -06:00

146 lines
5.9 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: IDSolutions
* Initializes the bank store.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Examples:
* [] call forge_server_bank_fnc_initBankStore
*
* Public: Yes
*/
#pragma hemtt ignore_variables ["_self"]
GVAR(BankStore) = createHashMapObject [[
["#base", EGVAR(common,BaseStore)],
["#type", "IBankStore"],
["#create", {
GVAR(BankRegistry) = createHashMap;
GVAR(NameRegistry) = createHashMap;
_self set ["_registry", GVAR(BankRegistry)];
_self set ["_extCallPrefix", "bank"];
_self set ["_readMethod", "get"];
_self set ["_storeName", "Bank"];
_self set ["_syncEventName", CRPC(bank,responseSyncBank)];
["INFO", "Bank Store Initialized!", nil, nil] call EFUNC(common,log);
}],
["init", {
params [["_uid", "", [""]], ["_defaultAccount", createHashMap, [createHashMap]]];
private _finalAccount = createHashMap;
["bank:exists", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
private _exists = _result == "true";
if !(_exists) then {
_finalAccount = _defaultAccount;
_finalAccount set ["uid", _uid];
private _json = _self call ["toJSON", [_finalAccount]];
["bank:create", [_uid, _json]] call EFUNC(extension,extCall);
["INFO", format ["Created new bank account for %1", _uid], nil, nil] call EFUNC(common,log);
} else {
private _existingAccount = _self call ["fetch", [_uid]];
_finalAccount = _existingAccount;
{
if !(_x in _finalAccount) then { _finalAccount set [_x, _y]; };
} forEach _defaultAccount;
["INFO", format ["Found bank account for %1", _uid], nil, nil] call EFUNC(common,log);
};
GVAR(BankRegistry) set [_uid, _finalAccount, true];
private _player = [_uid] call EFUNC(common,getPlayer);
private _regEntry = createHashMapFromArray [["uid", _uid], ["name", (name _player)]];
GVAR(NameRegistry) set [_uid, _regEntry];
[CRPC(bank,responseInitBank), [_finalAccount], _player] call CFUNC(targetEvent);
_finalAccount
}],
["deposit", {
params [["_uid", "", [""]], ["_amount", 0, [0]]];
["INFO", format ["Deposit %1, for %2", _amount, _uid], nil, nil] call EFUNC(common,log);
private _account = GVAR(BankRegistry) getOrDefault [_uid, nil];
if (isNil "_account") exitWith { ["ERROR", "Empty/Invalid Account!", nil, nil] call EFUNC(common,log); };
private _bank = _account getOrDefault ["bank", 0];
private _cash = _account getOrDefault ["cash", 0];
if (_cash < _amount) exitWith { ["WARNING", "Insufficient Funds!", nil, nil] call EFUNC(common,log); };
private _finalAccount = createHashMapFromArray [
["bank", (_bank + _amount)],
["cash", (_cash - _amount)]
];
_self call ["mset", [_uid, _finalAccount]];
private _player = [_uid] call EFUNC(common,getPlayer);
[CRPC(notifications,recieveNotification), ["info", "Bank", format ["Deposited $%1", _amount]], _player] call CFUNC(targetEvent);
}],
["transfer", {
params [["_uid", "", [""]], ["_target", "", [""]], ["_from", "", [""]], ["_amount", 0, [0]]];
if (_uid isEqualTo _target) exitWith {
["WARNING", format ["Self-transfer attempt blocked for %1", _uid], nil, nil] call EFUNC(common,log);
};
private _account = GVAR(BankRegistry) getOrDefault [_uid, nil];
if (isNil "_account") exitWith { ["ERROR", "Empty/Invalid Account!", nil, nil] call EFUNC(common,log); };
private _targetAccount = GVAR(BankRegistry) getOrDefault [_target, nil];
if (isNil "_targetAccount") exitWith { ["ERROR", "Empty/Invalid Target Account!", nil, nil] call EFUNC(common,log); };
private _bank = _account getOrDefault [_from, 0];
if (_bank < _amount) exitWith { ["WARNING", "Insufficient Funds!", nil, nil] call EFUNC(common,log); };
private _targetBank = _targetAccount getOrDefault ["bank", 0];
private _finalAccount = createHashMapFromArray [[_from, (_bank - _amount)]];
private _finalTargetBank = createHashMapFromArray [["bank", (_targetBank + _amount)]];
_self call ["mset", [_uid, _finalAccount]];
_self call ["mset", [_target, _finalTargetBank]];
private _player = [_uid] call EFUNC(common,getPlayer);
private _targetPlayer = [_target] call EFUNC(common,getPlayer);
[CRPC(notifications,recieveNotification), ["info", "Bank", format ["Transferred $%1 to %2", _amount, (name _targetPlayer)]], _player] call CFUNC(targetEvent);
[CRPC(notifications,recieveNotification), ["info", "Bank", format ["Received $%1 from %2", _amount, (name _player)]], _targetPlayer] call CFUNC(targetEvent);
}],
["withdraw", {
params [["_uid", "", [""]], ["_amount", 0, [0]]];
["INFO", format ["Withdraw %1, for %2", _amount, _uid], nil, nil] call EFUNC(common,log);
private _account = GVAR(BankRegistry) getOrDefault [_uid, nil];
if (isNil "_account") exitWith { ["ERROR", "Empty/Invalid Account!", nil, nil] call EFUNC(common,log); };
private _bank = _account getOrDefault ["bank", 0];
private _cash = _account getOrDefault ["cash", 0];
if (_bank < _amount) exitWith { ["WARNING", "Insufficient Funds!", nil, nil] call EFUNC(common,log); };
private _finalAccount = createHashMapFromArray [
["bank", (_bank - _amount)],
["cash", (_cash + _amount)]
];
_self call ["mset", [_uid, _finalAccount]];
private _player = [_uid] call EFUNC(common,getPlayer);
[CRPC(notifications,recieveNotification), ["info", "Bank", format ["Withdrew $%1", _amount]], _player] call CFUNC(targetEvent);
}]
]];
SETMVAR(FORGE_BankStore,GVAR(BankStore));
GVAR(BankStore)