From 26f8deb4bad8b2a1ab07df993a17b1ef13a26a4a Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Wed, 17 Jul 2024 12:36:06 +0200 Subject: [PATCH] Updated using hashmap --- cScripts/cScripts_postInit.sqf | 2 +- .../functions/init/fn_init_eventHandlers.sqf | 34 +++++++++---- .../functions/systems/fn_getAttendance.sqf | 48 ++++++++++++++----- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/cScripts/cScripts_postInit.sqf b/cScripts/cScripts_postInit.sqf index 717c3cf90..030bc830a 100644 --- a/cScripts/cScripts_postInit.sqf +++ b/cScripts/cScripts_postInit.sqf @@ -29,7 +29,7 @@ if (EGVAR(Settings,showDiaryRecords)) then { call EFUNC(civ,init); onPlayerConnected { - [QEGVAR(log,player), [player]] call CBA_fnc_serverEvent; + [QEGVAR(log,player), [getPlayerUID player, player]] call CBA_fnc_serverEvent; }; INFO("postInit", "Initialization completed."); diff --git a/cScripts/functions/init/fn_init_eventHandlers.sqf b/cScripts/functions/init/fn_init_eventHandlers.sqf index e88297331..3622a21e7 100644 --- a/cScripts/functions/init/fn_init_eventHandlers.sqf +++ b/cScripts/functions/init/fn_init_eventHandlers.sqf @@ -40,12 +40,30 @@ INFO("InitEventHandlers","Creating Server EventHandlers"); }] call CBA_fnc_addEventHandler; [QEGVAR(log,player), { - params ["_player"]; - private _playerLog = missionNamespace getVariable [QEGVAR(log,players), []]; - _playerLog pushBack [ - _player, - name _player, - [_player] call EFUNC(gear,getLoadoutDisplayName) - ]; - missionNamespace setVariable [QEGVAR(log,players), _playerLog]; + params ["_guid","_player"]; + private _playerLog = GETMVAR(EGVAR(log,players),createHashMap); + INFO_3("PlayerLog","Connected %1 [%2] (GUID: %3)",name _player,typeOf _player,_guid); + + if (!isNil{_playerLog get _guid}) then { + INFO_1("PlayerLog","Updating Log Entry [%1]", isNil{_playerLog get _guid}); + private _data = _playerLog get _guid; + + private _connections = _data get "connections"; + _connections pushBack systemTimeUTC; + _data set ["connections", _connections]; + + _data set ["loadout", typeOf _player]; + + _playerLog set [_guid,_data]; + } else { + INFO_1("PlayerLog", "Creating Log Entry [%1]", isNil{_playerLog get _guid}); + private _entry = createHashMapFromArray [ + ['name', name _player], + ['loadout', typeOf _player], + ['connectTime', systemTimeUTC], + ['connections', [systemTimeUTC]] + ]; + _playerLog set [_guid,_entry]; + }; + SETMVAR(EGVAR(log,players),_playerLog); }] call CBA_fnc_addEventHandler; \ No newline at end of file diff --git a/cScripts/functions/systems/fn_getAttendance.sqf b/cScripts/functions/systems/fn_getAttendance.sqf index 1dff47a5e..3ab16a4d5 100644 --- a/cScripts/functions/systems/fn_getAttendance.sqf +++ b/cScripts/functions/systems/fn_getAttendance.sqf @@ -20,31 +20,53 @@ private _loggedPlayer = GETMVAR(EGVAR(log,players),[]); private _header = format["=== Attendance (Entries: %1) ===", count _loggedPlayer]; private _dateTime = systemTimeUTC apply { if (_x < 10) then { "0" + str _x } else { str _x } }; -private _year = _dateTime#0; -private _month = _dateTime#1; -private _day = _dateTime#2; -private _hour = _dateTime#3; -private _minute = _dateTime#4; -_dateTime = format["Date: %1-%2-%3 %4:%5z", _year, _month, _day, _hour, _minute]; +private _formatDateTime = format["Date: %1-%2-%3 %4:%5z",_dateTime#0,_dateTime#1,_dateTime#2,_dateTime#3,_dateTime#4]; // Export -private _entries = [_header, endl, _dateTime, endl, endl]; +private _entries = [_header, endl, _formatDateTime, endl, endl]; { - _x params ["_player","_name","_slot"]; - _entries append [_name, " (", _slot, ")", endl]; + private _name = _y get "name"; + + private _loadout = _y get "loadout"; + private _missionConfig = missionConfigFile >> "CfgLoadouts" >> _loadout; + private _displayName = getText (_missionConfig >> "displayName"); + if (_displayName == "") then { + private _config = configFile >> "CfgLoadouts" >> _loadout; + _displayName = getText (_config >> "displayName"); + }; + + private _connectTime = (_y get "connectTime") apply { if (_x < 10) then { "0" + str _x } else { str _x } }; + private _formatConnectTime = format["%1-%2-%3 %4:%5z",_connectTime#0,_connectTime#1,_connectTime#2,_connectTime#3,_connectTime#4]; + + private _connections = count (_y get "connections"); + + _entries append [_name, " (", _displayName, ") ", _formatConnectTime, " (Connected ", str _connections, " time(s))", endl]; } forEach _loggedPlayer; private _export = composeText _entries; - ["Mission attendees", str _export] call zen_common_fnc_exportText; // RPT SHOW_INFO("Attendance",_header); -SHOW_INFO("Attendance",_dateTime); +SHOW_INFO("Attendance",_formatDateTime); { - _x params ["_player","_name","_slot"]; - private _output = format["%1 (%2 [%3])", _name, _slot, typeOf _player]; + private _name = _y get "name"; + + private _loadout = _y get "loadout"; + private _missionConfig = missionConfigFile >> "CfgLoadouts" >> _loadout; + private _displayName = getText (_missionConfig >> "displayName"); + if (_displayName == "") then { + private _config = configFile >> "CfgLoadouts" >> _loadout; + _displayName = getText (_config >> "displayName"); + }; + + private _connectTime = (_y get "connectTime") apply { if (_x < 10) then { "0" + str _x } else { str _x } }; + private _formatConnectTime = format["%1-%2-%3 %4:%5z",_connectTime#0,_connectTime#1,_connectTime#2,_connectTime#3,_connectTime#4]; + + private _connections = count (_y get "connections"); + + private _output = [_name, " (", _displayName, " [", _loadout,"]) ", _formatConnectTime, " (Connected ", str _connections, " time(s))"] joinString ""; SHOW_INFO("Attendance",_output); } forEach _loggedPlayer;