Skip to content

Commit

Permalink
Added more stable eventhander for player connections and logging (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBrostrom authored Jul 30, 2024
1 parent c70f784 commit bf28fc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 0 additions & 4 deletions cScripts/cScripts_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@ if (EGVAR(Settings,showDiaryRecords)) then {

call EFUNC(civ,init);

onPlayerConnected {
[QEGVAR(log,player), [getPlayerUID player, player]] call CBA_fnc_serverEvent;
};

INFO("postInit", "Initialization completed.");
19 changes: 13 additions & 6 deletions cScripts/functions/init/fn_init_eventHandlers.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ INFO("InitEventHandlers","Creating Server EventHandlers");
}] call CBA_fnc_addEventHandler;

[QEGVAR(log,player), {
params ["_guid","_player"];
params ["_guid","_name"];
private _unit = [_guid] call BIS_fnc_getUnitByUID;
private _playerLog = GETMVAR(EGVAR(log,players),createHashMap);
INFO_3("PlayerLog","Connected %1 [%2] (GUID: %3)",name _player,typeOf _player,_guid);
INFO_3("PlayerLog","Connected %1 [%2] (GUID: %3)",_name,typeOf _unit,_guid);

if (!isNil{_playerLog get _guid}) then {
INFO_1("PlayerLog","Updating Log Entry [%1]", isNil{_playerLog get _guid});
Expand All @@ -52,18 +53,24 @@ INFO("InitEventHandlers","Creating Server EventHandlers");
_connections pushBack systemTimeUTC;
_data set ["connections", _connections];

_data set ["loadout", typeOf _player];
private _loadout = GETVAR(EGVAR(Gear,LoadoutClass), typeOf _unit);
_data set ["loadout", GETVAR(EGVAR(Gear,LoadoutClass), typeOf _unit)];

_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],
['name', _name],
['loadout', _loadout],
['connectTime', systemTimeUTC],
['connections', [systemTimeUTC]]
];
_playerLog set [_guid,_entry];
};
SETMVAR(EGVAR(log,players),_playerLog);
}] call CBA_fnc_addEventHandler;
}] call CBA_fnc_addEventHandler;

addMissionEventHandler ["PlayerConnected", {
params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];
[QEGVAR(log,player), [_uid, _name]] call CBA_fnc_serverEvent;
}];

0 comments on commit bf28fc7

Please sign in to comment.