Compare commits
No commits in common. "2ff4a37677b08681bb12919bb5c37da21a892952" and "17d5942de485a6b7d613ea21d9cb1f56d8d8f2d8" have entirely different histories.
2ff4a37677
...
17d5942de4
@ -4,53 +4,53 @@ call FUNC(initAdmin);
|
||||
call FUNC(initAdminStore);
|
||||
|
||||
[QGVAR(handleEvents), {
|
||||
params ["_event", "_data"];
|
||||
params ["_event", "_params"];
|
||||
|
||||
diag_log format ["[FORGE::Server::Admin::XEH_preInit] Received event: %1 with data: %2", _event, _data];
|
||||
diag_log format ["[FORGE: Admin] Received event: %1 with params: %2", _event, _params];
|
||||
|
||||
switch (_event) do {
|
||||
case "ADMIN::ADVANCE::ALL": {
|
||||
case "advanceAll": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_data params [["_amount", 0, [0]]];
|
||||
_params params ["_amount"];
|
||||
|
||||
if (_amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Admin::XEH_preInit::advanceAll] Invalid amount!"; };
|
||||
if (isNil "_amount") exitWith { diag_log "Amount cannot be empty!"; };
|
||||
|
||||
_adminStore call ["handleTransfer", ["advanceAll", _amount]];
|
||||
};
|
||||
case "ADMIN::PAYDAY": {
|
||||
case "handlePayday": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
|
||||
_adminStore call ["handleTransfer", ["payday"]];
|
||||
};
|
||||
case "ADMIN::TRANSFER": {
|
||||
case "handleTransfer": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_data params [["_condition", "", [""]], ["_amount", 0, [0]], ["_uid", "", [""]]];
|
||||
_params params ["_condition", "_amount", "_uid"];
|
||||
|
||||
if (_condition isEqualTo "" || _amount isEqualTo 0 || _uid isEqualTo "") exitWith { diag_log "[FORGE::Server::Admin::XEH_preInit::handleTransfer] Invalid condition, amount, or UID!"; };
|
||||
if (isNil "_condition") exitWith { diag_log "Condition cannot be empty!"; };
|
||||
|
||||
_adminStore call ["handleTransfer", [_condition, _amount, _uid]];
|
||||
};
|
||||
case "ADMIN::SEND::MESSAGE": {
|
||||
case "sendMessage": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_data params [["_uid", "", [""]], ["_message", "", [""]]];
|
||||
_params params ["_uid", "_message"];
|
||||
|
||||
if (_message isEqualTo "") exitWith { diag_log "[FORGE::Server::Admin::XEH_preInit::sendMessage] Invalid message!"; };
|
||||
if (isNil "_message") exitWith { diag_log "Message cannot be empty!"; };
|
||||
if (_uid isEqualTo "") then {
|
||||
_adminStore call ["broadcastMessage", [_message]];
|
||||
} else {
|
||||
_adminStore call ["sendMessage", [_uid, _message]];
|
||||
};
|
||||
};
|
||||
case "ADMIN::UPDATE::PAYGRADE": {
|
||||
case "updatePaygrade": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_data params [["_uid", "", [""]], ["_paygrade", "", [""]]];
|
||||
_params params ["_uid", "_paygrade"];
|
||||
|
||||
if (_uid isEqualTo "" || _paygrade isEqualTo "") exitWith { diag_log "[FORGE::Server::Admin::XEH_preInit::updatePaygrade] Invalid UID or paygrade!"; };
|
||||
if (_uid isEqualTo "" && _paygrade isEqualTo "") exitWith { diag_log "UID or Paygrade cannot be empty!"; };
|
||||
|
||||
_adminStore call ["updatePaygrade", [_uid, _paygrade]];
|
||||
};
|
||||
default {
|
||||
diag_log format ["[FORGE::Server::Admin::XEH_preInit] Unknown event: %1 with data: %2", _event, _data];
|
||||
diag_log format ["Unknown event: %1 with params: %2", _event, _params];
|
||||
};
|
||||
};
|
||||
}] call CFUNC(addEventHandler);
|
@ -13,6 +13,6 @@
|
||||
_cpof allowDamage false;
|
||||
_cpof setVariable ["isCPOF", true, true];
|
||||
|
||||
diag_log text format ["[FORGE::Server::Admin::initAdmin] ClassName: '%1' Pos: '%2' Dir: '%3'", _className, _pos, _dir];
|
||||
diag_log text format ["[FORGE Admin] ClassName: '%1' Pos: '%2' Dir: '%3'", _className, _pos, _dir];
|
||||
|
||||
} forEach ("true" configClasses (missionConfigFile >> "CfgCpofs" >> "cpofs"));
|
@ -26,7 +26,7 @@ private _store = GETMVAR(FORGE_ADMIN_STORE_REG,nil);
|
||||
if (isNil "_store") then {
|
||||
_store = call FUNC(initAdminStore);
|
||||
|
||||
diag_log text "[FORGE::Server::Admin::verifyAdminStore] Admin store initialized";
|
||||
diag_log text "[FORGE Admin] Admin store initialized";
|
||||
};
|
||||
|
||||
_store
|
@ -1,3 +1 @@
|
||||
PREP(initBank);
|
||||
PREP(initBankStore);
|
||||
PREP(verifyBankStore);
|
||||
PREP(initBank);
|
@ -1,70 +1,3 @@
|
||||
#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);
|
||||
call FUNC(initBank);
|
@ -26,5 +26,5 @@
|
||||
_bank setVariable ["BIS_enableRandomization", false];
|
||||
};
|
||||
|
||||
diag_log text format ["[FORGE::Server::Bank::initBank] ClassName: '%1' Pos: '%2' Dir: '%3'", _className, _pos, _dir];
|
||||
diag_log text format ["[FORGE Bank] ClassName: '%1' Pos: '%2' Dir: '%3'", _className, _pos, _dir];
|
||||
} forEach ("true" configClasses (missionConfigFile >> "CfgBanks" >> "banks"));
|
@ -1,178 +0,0 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
/*
|
||||
* Author: IDSolutions
|
||||
* Initializes a server-side bank store interface for managing banking operations.
|
||||
* Provides CRUD operations for bank data, including database persistence.
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* <HASHMAP> Bank store object
|
||||
*
|
||||
* Example:
|
||||
* private _bankStore = call forge_server_bank_fnc_initBank;
|
||||
* _bankStore call ["deposit", [getPlayerUID player, 1000]];
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
private _bankStore = createHashMapObject [[
|
||||
["#type", "IBankStore"],
|
||||
["#create", {
|
||||
_self set ["accounts", createHashMap];
|
||||
_self set ["transactions", []];
|
||||
_self set ["isLoaded", true];
|
||||
|
||||
true
|
||||
}],
|
||||
["handlePlayerLoad", {
|
||||
params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]]];
|
||||
|
||||
if (_uid isEqualTo "") exitWith { false };
|
||||
|
||||
_self call ["updateAccount", [_uid, _bankValue, _cashValue]];
|
||||
|
||||
diag_log text format ["[FORGE::Server::Bank::Store::handlePlayerLoad] Loaded player data for '%1' - Bank: '%2', Cash: '%3'", _uid, _bankValue, _cashValue];
|
||||
|
||||
true
|
||||
}],
|
||||
["updateAccount", {
|
||||
params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]], ["_isSave", false, [false]]];
|
||||
|
||||
if (_uid isEqualTo "") exitWith { false };
|
||||
|
||||
private _accounts = _self get "accounts";
|
||||
private _account = _accounts getOrDefault [_uid, createHashMap];
|
||||
|
||||
_account set ["bank", _bankValue];
|
||||
_account set ["cash", _cashValue];
|
||||
|
||||
_accounts set [_uid, _account];
|
||||
_self set ["accounts", _accounts];
|
||||
|
||||
if (_isSave) then {
|
||||
["hsetid", _uid, "bank", -1, [_bankValue]] call dragonfly_db_fnc_addTask;
|
||||
["hsetid", _uid, "cash", -1, [_cashValue]] call dragonfly_db_fnc_addTask;
|
||||
};
|
||||
|
||||
diag_log text format ["[FORGE::Server::Bank::Store::updateAccount] Updated player data for '%1' - Bank: '%2', Cash: '%3'", _uid, _bankValue, _cashValue];
|
||||
|
||||
true
|
||||
}],
|
||||
["getBalance", {
|
||||
params [["_uid", "", [""]]];
|
||||
|
||||
if (_uid isEqualTo "") exitWith { 0 };
|
||||
|
||||
private _accounts = _self get "accounts";
|
||||
private _account = _accounts getOrDefault [_uid, createHashMap];
|
||||
|
||||
_account getOrDefault ["bank", 0]
|
||||
}],
|
||||
["getCash", {
|
||||
params [["_uid", "", [""]]];
|
||||
|
||||
if (_uid isEqualTo "") exitWith { 0 };
|
||||
|
||||
private _accounts = _self get "accounts";
|
||||
private _account = _accounts getOrDefault [_uid, createHashMap];
|
||||
|
||||
_account getOrDefault ["cash", 0]
|
||||
}],
|
||||
["deposit", {
|
||||
params [["_uid", "", [""]], ["_amount", 0, [0]]];
|
||||
|
||||
if (_uid isEqualTo "" || _amount <= 0) exitWith { false };
|
||||
|
||||
private _accounts = _self get "accounts";
|
||||
private _account = _accounts getOrDefault [_uid, createHashMap];
|
||||
private _currentCash = _account getOrDefault ["cash", 0];
|
||||
private _currentBalance = _account getOrDefault ["bank", 0];
|
||||
|
||||
if (_currentCash < _amount) exitWith { false };
|
||||
|
||||
private _newBalance = _currentBalance + _amount;
|
||||
private _newCash = _currentCash - _amount;
|
||||
|
||||
_self call ["updateAccount", [_uid, _newBalance, _newCash, true]];
|
||||
|
||||
private _transactions = _self get "transactions";
|
||||
|
||||
_transactions pushBack [_uid, "deposit", _amount, time];
|
||||
_self set ["transactions", _transactions];
|
||||
|
||||
true
|
||||
}],
|
||||
["withdraw", {
|
||||
params [["_uid", "", [""]], ["_amount", 0, [0]]];
|
||||
|
||||
if (_uid isEqualTo "" || _amount <= 0) exitWith { false };
|
||||
|
||||
private _accounts = _self get "accounts";
|
||||
private _account = _accounts getOrDefault [_uid, createHashMap];
|
||||
private _currentBalance = _account getOrDefault ["bank", 0];
|
||||
private _currentCash = _account getOrDefault ["cash", 0];
|
||||
|
||||
if (_currentBalance < _amount) exitWith { false };
|
||||
|
||||
private _newBalance = _currentBalance - _amount;
|
||||
private _newCash = _currentCash + _amount;
|
||||
|
||||
_self call ["updateAccount", [_uid, _newBalance, _newCash, true]];
|
||||
|
||||
private _transactions = _self get "transactions";
|
||||
|
||||
_transactions pushBack [_uid, "withdraw", _amount, time];
|
||||
_self set ["transactions", _transactions];
|
||||
|
||||
true
|
||||
}],
|
||||
["transfer", {
|
||||
params [["_fromUid", "", [""]], ["_toUid", "", [""]], ["_amount", 0, [0]]];
|
||||
|
||||
if (_fromUid isEqualTo "" || _toUid isEqualTo "" || _amount <= 0) exitWith { false };
|
||||
|
||||
private _accounts = _self get "accounts";
|
||||
private _fromAccount = _accounts getOrDefault [_fromUid, createHashMap];
|
||||
private _toAccount = _accounts getOrDefault [_toUid, createHashMap];
|
||||
private _fromBalance = _fromAccount getOrDefault ["bank", 0];
|
||||
private _toBalance = _toAccount getOrDefault ["bank", 0];
|
||||
|
||||
if (_fromBalance < _amount) exitWith { false };
|
||||
|
||||
_self call ["updateAccount", [_fromUid, _fromBalance - _amount, 0, true]];
|
||||
_self call ["updateAccount", [_toUid, _toBalance + _amount, 0, true]];
|
||||
|
||||
private _transactions = _self get "transactions";
|
||||
|
||||
_transactions pushBack [_fromUid, "transfer_out", _amount, time, _toUid];
|
||||
_transactions pushBack [_toUid, "transfer_in", _amount, time, _fromUid];
|
||||
_self set ["transactions", _transactions];
|
||||
|
||||
true
|
||||
}],
|
||||
["getTransactionHistory", {
|
||||
params [["_uid", "", [""]], ["_limit", 10, [0]]];
|
||||
|
||||
private _transactions = _self get "transactions";
|
||||
private _filteredTransactions = [];
|
||||
|
||||
if (_uid isEqualTo "") then {
|
||||
_filteredTransactions = _transactions;
|
||||
} else {
|
||||
{
|
||||
if ((_x select 0) == _uid) then { _filteredTransactions pushBack _x; };
|
||||
} forEach _transactions;
|
||||
};
|
||||
|
||||
_filteredTransactions sort false;
|
||||
_filteredTransactions resize (_limit min (count _filteredTransactions));
|
||||
|
||||
_filteredTransactions
|
||||
}]
|
||||
]];
|
||||
|
||||
SETMVAR(FORGE_BANK_STORE_REG,_bankStore);
|
||||
GETMVAR(FORGE_BANK_STORE_REG,_bankStore);
|
@ -1,32 +0,0 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
/*
|
||||
* Function: forge_server_bank_fnc_verifyBankStore
|
||||
* Author: IDSolutions
|
||||
*
|
||||
* [Description]
|
||||
* Ensures the bank store is initialized and returns the store object.
|
||||
* Acts as a singleton accessor for the bank store interface.
|
||||
* If the store doesn't exist yet, it initializes it first.
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* Bank Store <OBJECT> - The bank store interface object
|
||||
*
|
||||
* Example:
|
||||
* private _bankStore = call forge_server_bank_fnc_verifyBankStore
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
private _store = GETMVAR(FORGE_BANK_STORE_REG,nil);
|
||||
|
||||
if (isNil "_store") then {
|
||||
_store = call FUNC(initBankStore);
|
||||
|
||||
diag_log text "[FORGE::Server::Bank::verifyBankStore] Bank store initialized";
|
||||
};
|
||||
|
||||
_store
|
Loading…
x
Reference in New Issue
Block a user