112 lines
3.5 KiB
Plaintext
112 lines
3.5 KiB
Plaintext
#include "..\script_component.hpp"
|
|
|
|
/*
|
|
* Author: IDSolutions
|
|
* Handles the UI events.
|
|
*
|
|
* Arguments:
|
|
* None
|
|
*
|
|
* Return Value:
|
|
* None
|
|
*
|
|
* Example:
|
|
* [] call forge_client_bank_fnc_handleUIEvents;
|
|
*
|
|
* Public: No
|
|
*/
|
|
|
|
params ["_control", "_isConfirmDialog", "_message"];
|
|
|
|
private _alert = fromJSON _message;
|
|
private _event = _alert get "event";
|
|
private _data = _alert get "data";
|
|
private _display = displayChild findDisplay 46;
|
|
|
|
private _uid = GVAR(BankClass) get "uid";
|
|
private _account = GVAR(BankClass) get "account";
|
|
private _cash = _account get "cash";
|
|
private _bank = _account get "bank";
|
|
private _pin = _account get "pin";
|
|
|
|
diag_log format ["[FORGE:Client:Bank] Handling UI event: %1 with data: %2", _event, _data];
|
|
|
|
switch (_event) do {
|
|
// ========================================================================
|
|
// DATA REQUESTS
|
|
// ========================================================================
|
|
case "bank::sync": {
|
|
private _org = 0; // TODO: Get org balance
|
|
private _players = SREG(bank,IndexRegistry);
|
|
private _accountData = createHashMapFromArray [
|
|
["uid", _uid],
|
|
["cash", _cash],
|
|
["bank", _bank],
|
|
["org", _org],
|
|
["pin", _pin],
|
|
["players", _players]
|
|
];
|
|
|
|
_control ctrlWebBrowserAction ["ExecJS", format ["syncDataFromArma(%1)", toJSON _accountData]];
|
|
};
|
|
|
|
// ========================================================================
|
|
// BANK OPERATIONS
|
|
// ========================================================================
|
|
case "bank::deposit": {
|
|
private _amount = _data get "amount";
|
|
if (_amount > _cash) exitWith { hint "Insufficient cash!"; };
|
|
|
|
[SRPC(bank,requestDeposit), [_uid, _amount]] call CFUNC(serverEvent);
|
|
};
|
|
case "bank::withdraw": {
|
|
private _amount = _data get "amount";
|
|
if (_amount > _bank) exitWith { hint "Insufficient funds!"; };
|
|
|
|
[SRPC(bank,requestWithdraw), [_uid, _amount]] call CFUNC(serverEvent);
|
|
};
|
|
case "bank::transfer": {
|
|
private _amount = _data get "amount";
|
|
private _from = _data get "from";
|
|
private _target = _data get "target";
|
|
|
|
// Prevent self-transfers
|
|
if (_target isEqualTo _uid) exitWith {
|
|
hint "Cannot transfer to yourself!";
|
|
diag_log "[FORGE:Client:Bank] Attempted self-transfer blocked";
|
|
};
|
|
|
|
private _fromAmount = _account get _from;
|
|
if (_amount > _fromAmount) exitWith { hint "Insufficient funds!"; };
|
|
|
|
[SRPC(bank,requestTransfer), [_uid, _target, _from, _amount]] call CFUNC(serverEvent);
|
|
};
|
|
case "bank::close": {
|
|
_display closeDisplay 1;
|
|
};
|
|
|
|
// ========================================================================
|
|
// ATM OPERATIONS
|
|
// ========================================================================
|
|
case "atm::withdraw": {
|
|
private _amount = _data get "amount";
|
|
if (_amount > _bank) exitWith { hint "Insufficient funds!"; };
|
|
|
|
[SRPC(bank,requestWithdraw), [_uid, _amount]] call CFUNC(serverEvent);
|
|
};
|
|
case "atm::deposit": {
|
|
private _amount = _data get "amount";
|
|
if (_amount > _cash) exitWith { hint "Insufficient cash!"; };
|
|
|
|
[SRPC(bank,requestDeposit), [_uid, _amount]] call CFUNC(serverEvent);
|
|
};
|
|
case "atm::close": {
|
|
_display closeDisplay 1;
|
|
};
|
|
default {
|
|
diag_log format ["[FORGE:Client:Bank] Unhandled UI event: %1", _event];
|
|
};
|
|
};
|
|
|
|
true;
|