server/addons/admin/functions/fnc_initAdminStore.sqf
Jacob Schmidt eec98d03eb
All checks were successful
Build / Build (push) Successful in 25s
feat: Implement admin event handling and improve player data saving
This commit introduces admin event handling to manage various administrative actions and enhances the player data saving process.

The following changes were made:

-   Implemented event handling for admin actions such as advancing funds, handling paydays, transferring funds, sending messages, and updating paygrades. These events are triggered via the `QGVAR(handleEvents)` event handler.
-   Added `initAdminStore` and `verifyAdminStore` functions to manage the admin store.
-   Refactored the `fnc_handleDisconnect.sqf` script to use the `GETVAR` macro for retrieving player data, ensuring consistency and readability.
-   Replaced hardcoded default values with `QUOTE()` wrapped values in `fnc_handleDisconnect.sqf` for better maintainability and configuration.
2025-05-03 19:33:45 -05:00

119 lines
3.9 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Function: forge_server_admin_fnc_initAdminStore
* Author: IDSolutions
*
* Description:
* Initializes a server-side admin store interface for managing admin operations
* Provides CRUD operations for admin data, including database persistence through ArmaDragonflyClient
*
* Creates a hashMap object with methods for:
* - Sending messages to players
* - Managing player data
* - Performing administrative tasks
*
* Returns: <HASHMAP>
*
* Example:
* private _adminStore = call forge_server_admin_fnc_initAdminStore;
* _adminStore call ["sendMessage", [getPlayerUID player, "Hello, this is a test message"]];
*/
private _adminStore = createHashMapObject [[
["#type", "IAdminStore"],
["broadcastMessage", {
params ["_message"];
[format ["Incoming Message from Field Commander: <br/>%1", _message], "warning", 5] remoteExec ["forge_client_misc_fnc_notify", 0];
}],
["sendMessage", {
params ["_uid", "_message"];
private _target = objNull;
{
if (getPlayerUID _x == _uid) exitWith { _target = _x; };
} forEach allPlayers;
if (!isNull _target) then {
[format ["Incoming Message from Field Commander: <br/>%1", _message], "warning", 5] remoteExec ["forge_client_misc_fnc_notify", _target];
};
}],
["updatePaygrade", {
params ["_uid", "_paygrade"];
private _target = objNull;
{
if (getPlayerUID _x == _uid) exitWith { _target = _x; };
} forEach allPlayers;
if (!isNull _target) then { SETPVAR(_target,FORGE_PayGrade,_paygrade); };
}],
["handleTransfer", {
params ["_condition", "_amount", "_uid"];
switch (_condition) do {
case ("advance"): {
private _target = objNull;
{
if (getPlayerUID _x == _uid) exitWith { _target = _x; };
} forEach allPlayers;
if (isNull _target) exitWith {};
private _bank = GETVAR(_target,FORGE_Bank,0);
private _newBalance = _bank + _amount;
SETPVAR(_target,FORGE_Bank,_newBalance);
};
case ("advanceAll"): {
{
private _player = _x;
private _bank = GETVAR(_player,FORGE_Bank,0);
private _newBalance = _bank + _amount;
SETPVAR(_player,FORGE_Bank,_newBalance);
} forEach allPlayers;
};
case ("deduct"): {
private _target = objNull;
{
if (getPlayerUID _x == _uid) exitWith { _target = _x; };
} forEach allPlayers;
if (isNull _target) exitWith {};
private _bank = GETVAR(_target,FORGE_Bank,0);
private _newBalance = _bank - _amount;
if (_newBalance < 0) then { _newBalance = 0; };
SETPVAR(_target,FORGE_Bank,_newBalance);
};
case ("payday"): {
private _payGrades = (missionConfigFile >> "CfgPaygrades" >> "payGrades") call BIS_fnc_getCfgData;
{
private _player = _x;
private _payGrade = GETVAR(_player,FORGE_PayGrade,nil);
{
_x params ["_payGradeIndex", "_payGradeBonus"];
if (_payGradeIndex == _payGrade) then {
private _bank = GETVAR(_player,FORGE_Bank,0);
private _newBalance = _bank + _payGradeBonus;
SETPVAR(_player,FORGE_Bank,_newBalance);
};
} forEach _payGrades;
} forEach allPlayers;
};
};
}]
]];
SETMVAR(FORGE_ADMIN_STORE_REG,_adminStore);
GETMVAR(FORGE_ADMIN_STORE_REG,_adminStore);