From 834e565cb4129988d06022cad1fcc2eb91aedcc3 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 24 Nov 2026 14:00:03 +0100 Subject: [PATCH 1/2] feat(main): add Administrator UI Enabled setting Turns the Administrator UI diary entry on or off, for communities with their own recording controls. Off, nobody gets the entry and anyone who has it loses it; a change during the mission applies to every player at once. Previously merged as #30 into feature/cba_rework, which never reached main. Co-Authored-By: Claude Opus 5.5 --- addons/main/XEH_preInit.sqf | 31 ++++++++++++++++++++++++++ addons/recorder/fnc_adminUIcontrol.sqf | 10 +++++++++ 2 files changed, 41 insertions(+) diff --git a/addons/main/XEH_preInit.sqf b/addons/main/XEH_preInit.sqf index 95eccbe..e006017 100644 --- a/addons/main/XEH_preInit.sqf +++ b/addons/main/XEH_preInit.sqf @@ -59,6 +59,37 @@ GVAR(allSettings) = [ false // requires restart to apply ], + /* + CBA Setting: OCAP_enabledAdministratorUI + Description: + Turns the Administrator UI in the briefing diary on or off. Off is useful for communities with their own recording controls (an AAR framework, a persistence system). Changing it during the mission applies it to every player at once. Default: true + + Setting Name: + Administrator UI Enabled + + Value Type: + Boolean + */ + [ + QGVARMAIN(enabledAdministratorUI), + "CHECKBOX", // setting type + [ + "Administrator UI Enabled", // Pretty name shown inside the ingame settings menu. Can be stringtable entry. + "Turns the Administrator UI in the briefing diary on or off. Off is useful for communities with their own recording controls (an AAR framework, a persistence system). Default: true" + ], + [COMPONENT_NAME, "Core"], // Pretty name of the category where the setting can be found. Can be stringtable entry. + true, // default enabled + true, // "_isGlobal" flag. Set this to true to always have this setting synchronized between all clients in multiplayer + { + // Applied to every player on the server, once the recorder is ready (at mission start the players get it as they connect) + if (!isServer || {isNil QEFUNC(recorder,adminUIcontrol)}) exitWith {}; + { + [getPlayerID _x, "connect"] call EFUNC(recorder,adminUIcontrol); + } forEach (allPlayers - entities "HeadlessClient_F"); + }, // function that will be executed once on mission start and every time the setting is changed. + false // requires restart to apply + ], + /* CBA Setting: OCAP_administratorList Description: diff --git a/addons/recorder/fnc_adminUIcontrol.sqf b/addons/recorder/fnc_adminUIcontrol.sqf index a1baefd..900a19b 100644 --- a/addons/recorder/fnc_adminUIcontrol.sqf +++ b/addons/recorder/fnc_adminUIcontrol.sqf @@ -8,6 +8,9 @@ - to add/remove when a player logs in or out as admin on the server - at mission start to determine if a player is in + - changing during the mission, for every player + + With off, nobody gets the entry and anyone who has it loses it. Parameters: _PID - PlayerID indicating unique network client on the server [String] @@ -95,6 +98,13 @@ _fnc_removeControls = { _unit setVariable [QGVARMAIN(hasAdminControls), false]; }; +// Administrator UI turned off: nobody gets the entry, and anyone who has it loses it +if (!GVARMAIN(enabledAdministratorUI)) exitWith { + if (_unit getVariable [QGVARMAIN(hasAdminControls), false]) then { + [_owner, _unit] call _fnc_removeControls; + }; +}; + // check if admin private _adminUIDs = missionNamespace getVariable [QGVARMAIN(administratorList), nil]; From cb60955f66c21532ee89b55ae6803ad260cc83d1 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 1 Dec 2026 10:18:49 +0100 Subject: [PATCH 2/2] fix(recorder): keep admin controls when the Administrator UI is disabled Turning the Administrator UI off cleared OCAP_hasAdminControls, which OCAP_recorder_isAuthorizedEventCaller also uses to authorize remote callers, so administrators and listed players using their own controls were rejected. The setting now only hides the diary entry: OCAP_hasAdminControls is granted and dropped as before, whatever the setting, and the entry is sent only while the UI is enabled. A setting change ("setting" event) re-sends or removes the entry for those with the controls, leaving the flag alone. tests/admin_ui_regressions.sqf covers an authorized remote caller with the UI disabled, an unauthorized one rejected, and live off/on transitions. Co-Authored-By: Claude Opus 5.5 --- addons/main/XEH_preInit.sqf | 6 +- addons/recorder/fnc_adminUIcontrol.sqf | 28 ++++--- tests/README.md | 21 +++++ tests/admin_ui_regressions.sqf | 108 +++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 tests/admin_ui_regressions.sqf diff --git a/addons/main/XEH_preInit.sqf b/addons/main/XEH_preInit.sqf index e006017..b45c8da 100644 --- a/addons/main/XEH_preInit.sqf +++ b/addons/main/XEH_preInit.sqf @@ -62,7 +62,7 @@ GVAR(allSettings) = [ /* CBA Setting: OCAP_enabledAdministratorUI Description: - Turns the Administrator UI in the briefing diary on or off. Off is useful for communities with their own recording controls (an AAR framework, a persistence system). Changing it during the mission applies it to every player at once. Default: true + Turns the Administrator UI in the briefing diary on or off. Off is useful for communities with their own recording controls (an AAR framework, a persistence system). It only hides the entry: administrators keep the right to raise the recording events. Changing it during the mission applies it to every player at once. Default: true Setting Name: Administrator UI Enabled @@ -75,7 +75,7 @@ GVAR(allSettings) = [ "CHECKBOX", // setting type [ "Administrator UI Enabled", // Pretty name shown inside the ingame settings menu. Can be stringtable entry. - "Turns the Administrator UI in the briefing diary on or off. Off is useful for communities with their own recording controls (an AAR framework, a persistence system). Default: true" + "Turns the Administrator UI in the briefing diary on or off. Off is useful for communities with their own recording controls (an AAR framework, a persistence system). Administrators keep their rights. Default: true" ], [COMPONENT_NAME, "Core"], // Pretty name of the category where the setting can be found. Can be stringtable entry. true, // default enabled @@ -84,7 +84,7 @@ GVAR(allSettings) = [ // Applied to every player on the server, once the recorder is ready (at mission start the players get it as they connect) if (!isServer || {isNil QEFUNC(recorder,adminUIcontrol)}) exitWith {}; { - [getPlayerID _x, "connect"] call EFUNC(recorder,adminUIcontrol); + [getPlayerID _x, "setting"] call EFUNC(recorder,adminUIcontrol); } forEach (allPlayers - entities "HeadlessClient_F"); }, // function that will be executed once on mission start and every time the setting is changed. false // requires restart to apply diff --git a/addons/recorder/fnc_adminUIcontrol.sqf b/addons/recorder/fnc_adminUIcontrol.sqf index 900a19b..e1c8b62 100644 --- a/addons/recorder/fnc_adminUIcontrol.sqf +++ b/addons/recorder/fnc_adminUIcontrol.sqf @@ -8,13 +8,13 @@ - to add/remove when a player logs in or out as admin on the server - at mission start to determine if a player is in - - changing during the mission, for every player + - changing during the mission, for every player ("setting") - With off, nobody gets the entry and anyone who has it loses it. + With off, nobody gets the entry and anyone who has it loses it. It only hides the entry: stays, so those players can still raise the recording events. Parameters: _PID - PlayerID indicating unique network client on the server [String] - _event - Event that triggered this call [[String], one of: "connect", "login", "logout"] + _event - Event that triggered this call [[String], one of: "connect", "login", "logout", "setting"] Returns: Nothing @@ -55,6 +55,11 @@ if (isNull _unit) exitWith { _fnc_addControls = { params ["_owner", "_unit"]; + // set variable on unit + _unit setVariable [QGVARMAIN(hasAdminControls), true]; + // the diary entry only while the Administrator UI is enabled + if (!GVARMAIN(enabledAdministratorUI)) exitWith {}; + // add controls to diary entry { [{ @@ -81,9 +86,6 @@ _fnc_addControls = { ]; }] call CBA_fnc_waitUntilAndExecute; } remoteExec ["call", _owner]; - - // set variable on unit - _unit setVariable [QGVARMAIN(hasAdminControls), true]; }; _fnc_removeControls = { @@ -94,15 +96,17 @@ _fnc_removeControls = { } remoteExec ["call", _owner]; // Variable: OCAP_hasAdminControls - // Applied on units processed in . Indicates whether or not they have the administrative diary entry available. Server missionNamespace only. + // Applied on units processed in . Indicates whether or not they have the administrative controls: the right to raise the recording events, and the diary entry while is on. Server missionNamespace only. _unit setVariable [QGVARMAIN(hasAdminControls), false]; }; -// Administrator UI turned off: nobody gets the entry, and anyone who has it loses it -if (!GVARMAIN(enabledAdministratorUI)) exitWith { - if (_unit getVariable [QGVARMAIN(hasAdminControls), false]) then { - [_owner, _unit] call _fnc_removeControls; - }; +// Administrator UI turned on or off: only the entry follows, the controls stay +if (_event isEqualTo "setting") exitWith { + if !(_unit getVariable [QGVARMAIN(hasAdminControls), false]) exitWith {}; + { + player removeDiarySubject QEGVAR(diary,adminControls_subject); + } remoteExec ["call", _owner]; + [_owner, _unit] call _fnc_addControls; }; // check if admin diff --git a/tests/README.md b/tests/README.md index 0c7ff3b..7fcdf11 100644 --- a/tests/README.md +++ b/tests/README.md @@ -94,3 +94,24 @@ or saved. The suite replaces recording state and resets per-unit recording variables, and a recording start it simulates also satisfies the auto-start waiter; restart the mission afterwards. It is an opt-in test artifact, not included in the release PBOs. + +`admin_ui_regressions.sqf` checks that the Administrator UI setting +(`OCAP_enabledAdministratorUI`) only shows or hides the diary entry. A player in +the administrator list raises `OCAP_setFocusStart` from their own machine and is +accepted with the UI disabled, after turning it on and after turning it off +again, while the entry appears and disappears on their client. Once out of the +list (and logged out), they are rejected with the UI off and on, and turning the +UI on gives them neither the entry nor `OCAP_hasAdminControls`. A server-local call is always +accepted. Execute it on the server with one connected player who is not logged +in as admin and not the listen host: + +```sqf +[testClient] execVM "tests\admin_ui_regressions.sqf"; +``` + +The client raises the event with `remoteExecCall` to `CBA_fnc_localEvent`, so +allow `CBA_fnc_localEvent` and `call` in the test mission's `CfgRemoteExec`. The +event's work (`OCAP_recorder_fnc_setFocusStart`) is stubbed, so it needs the test +build and no recording. The RPT must end with +`[OCAP admin UI] ALL TESTS PASSED`; the suite restores the list, the setting +and the client's entry afterwards. diff --git a/tests/admin_ui_regressions.sqf b/tests/admin_ui_regressions.sqf new file mode 100644 index 0000000..b78f870 --- /dev/null +++ b/tests/admin_ui_regressions.sqf @@ -0,0 +1,108 @@ +/* Run on the server in a disposable multiplayer mission; see tests/README.md. */ +params ["_client"]; +if (!isServer || {!canSuspend}) exitWith {throw "Run the tests with server-side execVM"}; +if (!isPlayer _client || {owner _client isEqualTo 2}) exitWith {throw "Pass a remote player (not a listen host)"}; +if (admin owner _client > 0) exitWith {throw "The client must not be logged in or voted in as admin"}; + +private _assert = { + params ["_condition", "_description"]; + if (!_condition) then {throw _description}; + diag_log format ["[OCAP admin UI] PASS: %1", _description]; +}; +private _subject = "OCAP_diary_adminControls_subject"; +private _pid = getPlayerID _client; +private _savedFocus = OCAP_recorder_fnc_setFocusStart; +private _savedList = OCAP_administratorList; +private _savedUI = OCAP_enabledAdministratorUI; +private _error = ""; + +// The event's work is replaced; only whether the listener lets the call through matters. +OCAP_test_focus = []; +OCAP_recorder_fnc_setFocusStart = {OCAP_test_focus pushBack (_this param [0, -1])}; + +// The client raises OCAP_setFocusStart with `_frame`, the way a replacement UI would, from +// its own machine (remoteExecutedOwner is the client); the barrier follows from the same sender. +private _raise = { + params ["_frame"]; + OCAP_test_done = false; + [_frame, { + ["OCAP_setFocusStart", [_this]] remoteExecCall ["CBA_fnc_localEvent", 2]; + {OCAP_test_done = true} remoteExecCall ["call", 2]; + }] remoteExecCall ["call", owner _client]; + private _deadline = diag_tickTime + 15; + waitUntil {sleep 0.05; OCAP_test_done || {diag_tickTime > _deadline}}; + [OCAP_test_done, format ["client raised the event with frame %1", _frame]] call _assert; +}; + +// Whether the client's player has the diary entry, asked on the client once it settled. +private _clientHasEntry = { + params ["_expected"]; + private _deadline = diag_tickTime + 15; + OCAP_test_entry = !_expected; + while {OCAP_test_entry isNotEqualTo _expected && {diag_tickTime < _deadline}} do { + OCAP_test_entry = nil; + [_subject, { + [[player diarySubjectExists _this], {OCAP_test_entry = _this select 0}] remoteExecCall ["call", 2]; + }] remoteExecCall ["call", owner _client]; + waitUntil {sleep 0.05; !isNil "OCAP_test_entry" || {diag_tickTime > _deadline}}; + if (isNil "OCAP_test_entry") then {OCAP_test_entry = !_expected}; + if (OCAP_test_entry isNotEqualTo _expected) then {sleep 0.5}; + }; + OCAP_test_entry isEqualTo _expected +}; + +try { + // Authorized remote caller (in the administrator list) with the Administrator UI disabled + OCAP_enabledAdministratorUI = false; + OCAP_administratorList = [getPlayerUID _client]; + [_pid, "connect"] call OCAP_recorder_fnc_adminUIcontrol; + [_client getVariable ["OCAP_hasAdminControls", false], "listed player has the controls with the UI disabled"] call _assert; + [[false] call _clientHasEntry, "client shows no diary entry with the UI disabled"] call _assert; + [101] call _raise; + [OCAP_test_focus isEqualTo [101], "authorized remote caller is accepted with the UI disabled"] call _assert; + + // Live off -> on: the entry appears, the rights are unchanged + OCAP_enabledAdministratorUI = true; + [_pid, "setting"] call OCAP_recorder_fnc_adminUIcontrol; + [_client getVariable ["OCAP_hasAdminControls", false], "turning the UI on keeps the controls"] call _assert; + [[true] call _clientHasEntry, "client shows the diary entry once the UI is on"] call _assert; + [102] call _raise; + [OCAP_test_focus isEqualTo [101, 102], "authorized remote caller is accepted with the UI enabled"] call _assert; + + // Live on -> off: the entry goes, the rights stay + OCAP_enabledAdministratorUI = false; + [_pid, "setting"] call OCAP_recorder_fnc_adminUIcontrol; + [[false] call _clientHasEntry, "client loses the diary entry once the UI is off"] call _assert; + [_client getVariable ["OCAP_hasAdminControls", false], "turning the UI off keeps the controls"] call _assert; + [103] call _raise; + [OCAP_test_focus isEqualTo [101, 102, 103], "authorized remote caller is still accepted after the UI is turned off"] call _assert; + + // Unauthorized caller: no longer listed and not an admin ("logout" drops the rights, as for an admin logging out) + OCAP_administratorList = []; + [_pid, "logout"] call OCAP_recorder_fnc_adminUIcontrol; + [!(_client getVariable ["OCAP_hasAdminControls", false]), "logging out drops the controls"] call _assert; + [104] call _raise; + [OCAP_test_focus isEqualTo [101, 102, 103], "unauthorized remote caller is rejected with the UI disabled"] call _assert; + OCAP_enabledAdministratorUI = true; + [_pid, "setting"] call OCAP_recorder_fnc_adminUIcontrol; + [!(_client getVariable ["OCAP_hasAdminControls", false]), "turning the UI on grants an unauthorized player no controls"] call _assert; + [105] call _raise; + [OCAP_test_focus isEqualTo [101, 102, 103], "unauthorized remote caller is rejected with the UI enabled"] call _assert; + [[false] call _clientHasEntry, "client still has no diary entry"] call _assert; + + // A server-local call (mission script) is always accepted + ["OCAP_setFocusStart", [106]] call CBA_fnc_localEvent; + [OCAP_test_focus isEqualTo [101, 102, 103, 106], "server-local call is accepted"] call _assert; +} catch { + _error = _exception; +}; + +OCAP_recorder_fnc_setFocusStart = _savedFocus; +OCAP_administratorList = _savedList; +OCAP_enabledAdministratorUI = _savedUI; +[_pid, "connect"] call OCAP_recorder_fnc_adminUIcontrol; +if (_error isNotEqualTo "") then { + diag_log format ["[OCAP admin UI] FAIL: %1", _error]; + throw _error; +}; +diag_log "[OCAP admin UI] ALL TESTS PASSED";