feat: Implement admin event handling and improve player data saving
All checks were successful
Build / Build (push) Successful in 25s
All checks were successful
Build / Build (push) Successful in 25s
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.
This commit is contained in:
parent
a1fc5090ad
commit
eec98d03eb
24
.vscode/tasks.json
vendored
24
.vscode/tasks.json
vendored
@ -1,24 +0,0 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Start Arma 3 Server",
|
||||
"type": "process",
|
||||
"command": "wscript.exe",
|
||||
"args": [
|
||||
"D:\\SteamLibrary\\steamapps\\common\\Arma 3\\start_serverhub_hidden.vbs"
|
||||
],
|
||||
"presentation": {
|
||||
"reveal": "silent",
|
||||
"panel": "shared",
|
||||
"showReuseMessage": false,
|
||||
"clear": true
|
||||
},
|
||||
"problemMatcher": [],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1 +1,3 @@
|
||||
PREP(initAdmin);
|
||||
PREP(initAdmin);
|
||||
PREP(initAdminStore);
|
||||
PREP(verifyAdminStore);
|
@ -1,3 +1,56 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
call FUNC(initAdmin);
|
||||
call FUNC(initAdmin);
|
||||
call FUNC(initAdminStore);
|
||||
|
||||
[QGVAR(handleEvents), {
|
||||
params ["_event", "_params"];
|
||||
|
||||
diag_log format ["[FORGE: Admin] Received event: %1 with params: %2", _event, _params];
|
||||
|
||||
switch (_event) do {
|
||||
case "advanceAll": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_params params ["_amount"];
|
||||
|
||||
if (isNil "_amount") exitWith { diag_log "Amount cannot be empty!"; };
|
||||
|
||||
_adminStore call ["handleTransfer", ["advanceAll", _amount]];
|
||||
};
|
||||
case "handlePayday": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
|
||||
_adminStore call ["handleTransfer", ["payday"]];
|
||||
};
|
||||
case "handleTransfer": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_params params ["_condition", "_amount", "_uid"];
|
||||
|
||||
if (isNil "_condition") exitWith { diag_log "Condition cannot be empty!"; };
|
||||
|
||||
_adminStore call ["handleTransfer", [_condition, _amount, _uid]];
|
||||
};
|
||||
case "sendMessage": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_params params ["_uid", "_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 "updatePaygrade": {
|
||||
private _adminStore = call FUNC(verifyAdminStore);
|
||||
_params params ["_uid", "_paygrade"];
|
||||
|
||||
if (_uid isEqualTo "" && _paygrade isEqualTo "") exitWith { diag_log "UID or Paygrade cannot be empty!"; };
|
||||
|
||||
_adminStore call ["updatePaygrade", [_uid, _paygrade]];
|
||||
};
|
||||
default {
|
||||
diag_log format ["Unknown event: %1 with params: %2", _event, _params];
|
||||
};
|
||||
};
|
||||
}] call CFUNC(addEventHandler);
|
119
addons/admin/functions/fnc_initAdminStore.sqf
Normal file
119
addons/admin/functions/fnc_initAdminStore.sqf
Normal file
@ -0,0 +1,119 @@
|
||||
#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);
|
32
addons/admin/functions/fnc_verifyAdminStore.sqf
Normal file
32
addons/admin/functions/fnc_verifyAdminStore.sqf
Normal file
@ -0,0 +1,32 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
/*
|
||||
* Function: forge_server_admin_fnc_verifyAdminStore
|
||||
* Author: IDSolutions
|
||||
*
|
||||
* [Description]
|
||||
* Ensures the admin store is initialized and returns the store object.
|
||||
* Acts as a singleton accessor for the admin store interface.
|
||||
* If the store doesn't exist yet, it initializes it first.
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* Admin Store <OBJECT> - The admin store interface object
|
||||
*
|
||||
* Example:
|
||||
* private _adminStore = call forge_server_admin_fnc_verifyAdminStore
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
private _store = GETMVAR(FORGE_ADMIN_STORE_REG,nil);
|
||||
|
||||
if (isNil "_store") then {
|
||||
_store = call FUNC(initAdminStore);
|
||||
|
||||
diag_log text "[FORGE Admin] Admin store initialized";
|
||||
};
|
||||
|
||||
_store
|
@ -27,38 +27,22 @@ addMissionEventHandler ["HandleDisconnect", {
|
||||
|
||||
private _data = [
|
||||
_uid,
|
||||
// "armory_unlocks", [_unit getVariable ["Armory_Unlocks", _default_armory_unlocks]],
|
||||
// "garage_unlocks", [_unit getVariable ["Garage_Unlocks", _default_garage_unlocks]],
|
||||
"armory_unlocks", [GETVAR(_unit,Armory_Unlocks,_default_armory_unlocks)],
|
||||
"garage_unlocks", [GETVAR(_unit,Garage_Unlocks,_default_garage_unlocks)],
|
||||
// "locker", [_unit getVariable ["FORGE_Locker", []]],
|
||||
// "garage", [_unit getVariable ["FORGE_Garage", []]],
|
||||
"locker", [GETVAR(_unit,FORGE_Locker,[])],
|
||||
"garage", [GETVAR(_unit,FORGE_Garage,[])],
|
||||
// "cash", [_unit getVariable ["FORGE_Cash", 0]],
|
||||
// "bank", [_unit getVariable ["FORGE_Bank", 0]],
|
||||
"cash", [GETVAR(_unit,FORGE_Cash,0)],
|
||||
"bank", [GETVAR(_unit,FORGE_Bank,0)],
|
||||
// "number", [_unit getVariable ["FORGE_Phone_Number", "unknown"]],
|
||||
// "email", [_unit getVariable ["FORGE_Email", "unknown@spearnet.mil"]],
|
||||
"number", [GETVAR(_unit,FORGE_Phone_Number,"unknown")],
|
||||
"email", [GETVAR(_unit,FORGE_Email,"unknown@spearnet.mil")],
|
||||
// "paygrade", [_unit getVariable ["Paygrade", "E1"]],
|
||||
"paygrade", [GETVAR(_unit,Paygrade,"E1")],
|
||||
"number", [GETVAR(_unit,FORGE_Phone_Number,QUOTE(unknown))],
|
||||
"email", [GETVAR(_unit,FORGE_Email,QUOTE(unknown@spearnet.mil))],
|
||||
"paygrade", [GETVAR(_unit,FORGE_PayGrade,QUOTE(E1))],
|
||||
"reputation", [rating _unit],
|
||||
"loadout", [getUnitLoadout _unit],
|
||||
// "holster", [_unit getVariable ["FORGE_Holster_Weapon", true]],
|
||||
"holster", [GETVAR(_unit,FORGE_Holster_Weapon,true)],
|
||||
"position", [getPosASLVisual _unit],
|
||||
"direction", [getDirVisual _unit]
|
||||
];
|
||||
|
||||
// if (vehicle _unit == _unit) then {
|
||||
// _data pushBack "currentWeapon";
|
||||
// _data pushBack [currentMuzzle _unit];
|
||||
// _data pushBack "stance";
|
||||
// _data pushBack [stance _unit];
|
||||
// };
|
||||
if (isNull objectParent _unit) then {
|
||||
_data pushBack "currentWeapon";
|
||||
_data pushBack [currentMuzzle _unit];
|
||||
|
Loading…
x
Reference in New Issue
Block a user