diff --git a/cScripts/cScripts_postInit.sqf b/cScripts/cScripts_postInit.sqf index e070e0b5e..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), [name 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 889c5f7d3..3622a21e7 100644 --- a/cScripts/functions/init/fn_init_eventHandlers.sqf +++ b/cScripts/functions/init/fn_init_eventHandlers.sqf @@ -40,8 +40,30 @@ INFO("InitEventHandlers","Creating Server EventHandlers"); }] call CBA_fnc_addEventHandler; [QEGVAR(log,player), { - _this params ["_playerName"]; - private _playerLog = missionNamespace getVariable [QEGVAR(log,players), []]; - _playerLog pushBack _playerName; - 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 c89a4f7f5..3ab16a4d5 100644 --- a/cScripts/functions/systems/fn_getAttendance.sqf +++ b/cScripts/functions/systems/fn_getAttendance.sqf @@ -15,25 +15,59 @@ * */ -private _playerLog = missionNamespace getVariable [QEGVAR(log,players), []]; +private _loggedPlayer = GETMVAR(EGVAR(log,players),[]); -// Rpt -["=================================================== START", "Attendance"] call FUNC(info); -[format ["Attendance (Entries: %1)", count _playerLog], "Attendance"] call FUNC(info); +private _header = format["=== Attendance (Entries: %1) ===", count _loggedPlayer]; + +private _dateTime = systemTimeUTC apply { if (_x < 10) then { "0" + str _x } else { str _x } }; +private _formatDateTime = format["Date: %1-%2-%3 %4:%5z",_dateTime#0,_dateTime#1,_dateTime#2,_dateTime#3,_dateTime#4]; + +// Export +private _entries = [_header, endl, _formatDateTime, endl, endl]; { - _x params ["_name"]; - [_name, "Attendance", false, false] call FUNC(info); -} forEach _playerLog; - -["=================================================== END", "Attendence"] call FUNC(info); - -// Hint -[ - [], - ["All attended players have been"], - ["to your RPT log..."], - [""], - [""] -] call CBA_fnc_notify; - -_playerLog \ No newline at end of file + 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",_formatDateTime); +{ + 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; + +SHOW_INFO("Attendance","================================");