#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"] private _typeBank = compileFinal createHashMapFromArray [ ["#base", EGVAR(common,BaseStore)], ["#type", "IBaseBank"], ["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", ["bank:get", _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(IndexRegistry) set [_uid, _regEntry]; [CRPC(bank,responseInitBank), [_finalAccount], _player] call CFUNC(targetEvent); }], ["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(bank,responseSyncBank), [_finalAccount], _player] call CFUNC(targetEvent); [CRPC(notifications,recieveNotification), ["info", "Bank", format ["Deposited $%1", _amount]], _player] call CFUNC(targetEvent); }], ["payment", { params [["_uid", "", [""]], ["_amount", 0, [0]]]; ["INFO", format ["Payment %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 _finalAccount = createHashMapFromArray [["bank", (_bank + _amount)]]; _self call ["mset", [_uid, _finalAccount]]; private _player = [_uid] call EFUNC(common,getPlayer); [CRPC(bank,responseSyncBank), [_finalAccount], _player] call CFUNC(targetEvent); [CRPC(notifications,recieveNotification), ["info", "Bank", format ["Paid $%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(bank,responseSyncBank), [_finalAccount], _player] call CFUNC(targetEvent); [CRPC(bank,responseSyncBank), [_finalTargetBank], _targetPlayer] call CFUNC(targetEvent); [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(bank,responseSyncBank), [_finalAccount], _player] call CFUNC(targetEvent); [CRPC(notifications,recieveNotification), ["info", "Bank", format ["Withdrew $%1", _amount]], _player] call CFUNC(targetEvent); }] ]; GVAR(BankStore) = createHashMapObject [[ ["#base", _typeBank], ["#type", "IBankStore"], ["#create", { GVAR(BankRegistry) = createHashMap; GVAR(IndexRegistry) = createHashMap; ["INFO", "Bank Store Initialized!", nil, nil] call EFUNC(common,log); }] ]]; SETMVAR(FORGE_BankStore,GVAR(BankStore)); GVAR(BankStore)