From 4ced5080058327aafaeeca59679683e4be864ad3 Mon Sep 17 00:00:00 2001 From: IndigoFox Date: Fri, 26 Jan 2024 21:06:47 -0800 Subject: [PATCH] add global broadcast on players waiting longer than threshold, log --- functions/respawn/fn_init.sqf | 99 ++++++++++++++++++++---- functions/settings/fn_addCBASettings.sqf | 9 +++ 2 files changed, 93 insertions(+), 15 deletions(-) diff --git a/functions/respawn/fn_init.sqf b/functions/respawn/fn_init.sqf index 7ba95d1..44cee2d 100644 --- a/functions/respawn/fn_init.sqf +++ b/functions/respawn/fn_init.sqf @@ -1,3 +1,9 @@ + +// if a player files for reinsert using self-interaction +// they're added to the queue along with their nearest base location and the time they filed +// if a player's time in the queue exceeds the configured timeout, a message will be posted every 5 minutes on a cycle based around +// the player's time in the queue stating how long they have been waiting, their name, and their group's name + // execute for all if (isNil "milsim_respawn_setting_reinsertion_maxRangeToReady") then { // configured in CBA settings @@ -12,34 +18,49 @@ if (isServer) then { milsim_respawn_reinsertionQueue = []; publicVariable "milsim_respawn_reinsertionQueue"; + milsim_respawn_reinsertionOverTimeoutLastNotificationTime = 0; + // register event handlers ["milsim_respawn_fileReinsertRequest", { - params ["_unit", "_closestBaseName"]; - milsim_respawn_reinsertionQueue pushBackUnique [_unit, _closestBaseName]; + params ["_unit", "_closestBaseName", "_time"]; + milsim_respawn_reinsertionQueue pushBackUnique [_unit, _closestBaseName, _time]; diag_log text format [ - "[milsim] (respawn_reinsertion) ADDED name=%1 playerUID=%2 closestBase=%3", - name _unit, getPlayerUID _unit, _closestBaseName + "[milsim] (respawn_reinsertion) ADDED name=%1 playerUID=%2 filedAtBase=%3", + name _unit, + getPlayerUID _unit, + _closestBaseName ]; publicVariable "milsim_respawn_reinsertionQueue"; }] call CBA_fnc_addEventHandler; ["milsim_respawn_removeReinsertRequest", { params ["_unit"]; - if (count (milsim_respawn_reinsertionQueue select {_x#0 isEqualTo _unit}) isEqualTo 0) exitWith {}; - milsim_respawn_reinsertionQueue = milsim_respawn_reinsertionQueue select {_x#0 isNotEqualTo _unit}; - diag_log text format ["[milsim] (respawn_reinsertion) REMOVED BY REQUEST name=%1 playerUID=%2", - name _unit, getPlayerUID _unit + private _unitArrs = milsim_respawn_reinsertionQueue select {_x#0 isEqualTo _unit}; + if (count _unitArrs isEqualTo 0) exitWith {}; + + milsim_respawn_reinsertionQueue = milsim_respawn_reinsertionQueue - _unitArrs; + // sort _unitArrs by time in queue, descending + [_unitArrs, [], { + _x#2 + }, "DESCEND"] call BIS_fnc_sortBy; + (_unitArrs#0) params ["_unit", "_baseName", "_timeFiled"]; // _unitArr = [unit, baseName, timeInQueue] + private _timeInQueue = diag_tickTime - (_timeFiled); + diag_log text format ["[milsim] (respawn_reinsertion) REMOVED BY REQUEST name=%1 playerUID=%2 filedAtBase=%3 inQueue=%4s", + name _unit, + getPlayerUID _unit, + _baseName, + _timeInQueue ]; publicVariable "milsim_respawn_reinsertionQueue"; }] call CBA_fnc_addEventHandler; - // every 60 seconds, revalidate any players in the queue - // compare their distance to the nearest base, and remove them if they're too far away (or dead) + [{ + // every 60 seconds, revalidate any players in the queue + // compare their distance to the nearest base, and remove them if they're too far away (or dead) private _stillValid = []; { - private _queueData = _x; - private _player = _queueData#0; + _x params ["_player", "_baseName", "_timeFiled"]; // _unitArr = [unit, baseName, timeInQueue] private _nearBase = false; private _nearestDistance = 99999; { @@ -57,14 +78,62 @@ if (isServer) then { _stillValid pushBackUnique _queueData; } else { diag_log text format [ - "[milsim] (respawn_reinsertion) REMOVED AUTOMATICALLY name=%1 playerUID=%2 nearestBase=%3m", - name _player, getPlayerUID _player, _nearestDistance + "[milsim] (respawn_reinsertion) REMOVED AUTOMATICALLY name=%1 playerUID=%2 filedAtBase=%3 nearestBaseDistance=%4m inQueue=%5s", + name _unit, + getPlayerUID _unit, + _baseName, + _nearestDistance, + diag_tickTime - _timeFiled ]; }; } forEach milsim_respawn_reinsertionQueue; + // broadcast new list to all machines milsim_respawn_reinsertionQueue = _stillValid; publicVariable "milsim_respawn_reinsertionQueue"; + + + // if at least 1 player in the queue has been waiting longer than the configured timeout, + // show a notification to all players if the last notification was more than 5 minutes ago + private _needNotification = + diag_tickTime - milsim_respawn_reinsertionOverTimeoutLastNotificationTime > 60*5 // if last notification was more than 5 minutes ago + if (_needNotification) then { + private _timeout = missionNamespace getVariable ["milsim_respawn_setting_reinsertion_timeout", 60*20]; // default 20 minutes + private _timeoutPlayers = milsim_respawn_reinsertionQueue select {alive (_x#0) && (diag_tickTime - (_x#2)) > _timeout}; + if (count _timeoutPlayers > 0) then { + // sort _timeoutPlayers by time in queue, descending + _timeoutPlayers = [_timeoutPlayers, [], { + _x#2 + }, "DESCEND"] call BIS_fnc_sortBy; + private _playerLines = _timeoutPlayers apply { + private _timeInQueue = diag_tickTime - (_x#2); + private _groupId = groupID (_x#0); + [format [ + "%1: %2 [%2s]", + _groupId, + name (_x#0), + [_timeInQueue, "MM:SS"] call BIS_fnc_secondsToString + ], 0.8, [0.8, 0.8, 0.8, 1]]; + }; + ["Players are still waiting for Re-insert!", _playerLines] remoteExec ["CBA_fnc_notify", -2]; + + milsim_respawn_reinsertionOverTimeoutLastNotificationTime = diag_tickTime; + + diag_log text format [ + "[milsim] (respawn_reinsertion) PLAYERS WAITING LONGER THAN %1s: %2", + _timeout, + _timeoutPlayers apply { + format[ + "%1: %2 [%3]", + groupID (_x#0), + name _x#0, + diag_tickTime - (_x#2) + ] + } + ]; + + }; + }; }, 60] call CBA_fnc_addPerFrameHandler; }; @@ -92,7 +161,7 @@ if (hasInterface) then { params ["_target", "_player", "_params"]; private _closestBase = [milsim_respawn_bases, _player] call BIS_fnc_nearestPosition; private _closestBaseName = _closestBase getVariable ["name", "unknown"]; - ["milsim_respawn_fileReinsertRequest", [_player, _closestBaseName]] call CBA_fnc_serverEvent; + ["milsim_respawn_fileReinsertRequest", [_player, _closestBaseName, diag_tickTime]] call CBA_fnc_serverEvent; [["Re-insert Request Filed"], [format["Pickup at %1", _closestBaseName]]] call CBA_fnc_notify; }, { diff --git a/functions/settings/fn_addCBASettings.sqf b/functions/settings/fn_addCBASettings.sqf index c19dd52..7b87c51 100644 --- a/functions/settings/fn_addCBASettings.sqf +++ b/functions/settings/fn_addCBASettings.sqf @@ -162,6 +162,15 @@ true ] call CBA_fnc_addSetting; +[ + "milsim_respawn_setting_reinsertion_timeout", // variable + "SLIDER", // type + ["Request Timeout", "How long should at least one person be waiting before prompting a global notification."], // title + ["17th Battalion", "Re-insert Queue"], // category + [60*10, 60*30, 60*20, 0, false], // [_min, _max, _default, _trailingDecimals, _isPercentage + true +] call CBA_fnc_addSetting; + diag_log text "[MILSIM] (settings) Custom CBA settings initialized"; nil; \ No newline at end of file