
This commit refines the event handling for both admin and bank functionalities, ensuring better clarity and consistency in logging. Key changes include: - Updated event names in admin handling to follow a consistent naming convention. - Improved parameter handling in admin event functions, ensuring validation checks are in place. - Enhanced logging messages to provide clearer context regarding the source of events and actions taken. - Introduced bank event handling for deposit, transfer, withdrawal, and balance inquiries, with appropriate validation and logging. These changes aim to improve the maintainability and readability of the codebase while ensuring robust event management.
70 lines
3.0 KiB
Plaintext
70 lines
3.0 KiB
Plaintext
#include "script_component.hpp"
|
|
|
|
call FUNC(initBank);
|
|
call FUNC(initBankStore);
|
|
|
|
[QGVAR(handleEvents), {
|
|
params ["_event", "_data"];
|
|
|
|
diag_log text format ["[FORGE::Server::Bank::XEH_preInit] Received event: '%1' with data: '%2'", _event, _data];
|
|
|
|
switch (_event) do {
|
|
case "BANK::DEPOSIT": {
|
|
private _bankStore = call FUNC(verifyBankStore);
|
|
_data params [["_uid", "", [""]], ["_amount", 0, [0]]];
|
|
|
|
if (_uid isEqualTo "" || _amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleDeposit] Invalid UID and amount!"; };
|
|
|
|
_bankStore call ["deposit", [_uid, _amount]];
|
|
};
|
|
case "BANK::TRANSFER": {
|
|
private _bankStore = call FUNC(verifyBankStore);
|
|
_data params [["_fromUid", "", [""]], ["_toUid", "", [""]], ["_amount", 0, [0]]];
|
|
|
|
if (_fromUid isEqualTo "" || _toUid isEqualTo "" || _amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleTransfer] Invalid UIDs and amount!"; };
|
|
|
|
_bankStore call ["transfer", [_fromUid, _toUid, _amount]];
|
|
};
|
|
case "BANK::WITHDRAW": {
|
|
private _bankStore = call FUNC(verifyBankStore);
|
|
_data params [["_uid", "", [""]], ["_amount", 0, [0]]];
|
|
|
|
if (_uid isEqualTo "" || _amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleWithdraw] Invalid UID and amount!"; };
|
|
|
|
_bankStore call ["withdraw", [_uid, _amount]];
|
|
};
|
|
case "BANK::GET::BALANCE": {
|
|
private _bankStore = call FUNC(verifyBankStore);
|
|
_data params [["_uid", "", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleGetBalance] Invalid UID, UID cannot be empty!"; };
|
|
|
|
_bankStore call ["getBalance", [_uid]];
|
|
};
|
|
case "BANK::GET::CASH": {
|
|
private _bankStore = call FUNC(verifyBankStore);
|
|
_data params [["_uid", "", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleGetCash] Invalid UID, UID cannot be empty!"; };
|
|
|
|
_bankStore call ["getCash", [_uid]];
|
|
};
|
|
case "BANK::HANDLE::PLAYER::LOAD": {
|
|
private _bankStore = call FUNC(verifyBankStore);
|
|
_data params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handlePlayerLoad] Invalid UID, UID cannot be empty!"; };
|
|
|
|
_bankStore call ["handlePlayerLoad", [_uid, _bankValue, _cashValue]];
|
|
};
|
|
case "BANK::GET::TRANSACTION::HISTORY": {
|
|
private _bankStore = call FUNC(verifyBankStore);
|
|
_data params [["_uid", "", [""]], ["_limit", 10, [0]]];
|
|
|
|
_bankStore call ["getTransactionHistory", [_uid, _limit]];
|
|
};
|
|
default {
|
|
diag_log format ["[FORGE::Server::Bank::XEH_preInit] Unknown event: %1 with data: %2", _event, _data];
|
|
};
|
|
};
|
|
}] call CFUNC(addEventHandler); |