Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions addons/main/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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). 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

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). 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
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, "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
],

/*
CBA Setting: OCAP_administratorList
Description:
Expand Down
24 changes: 19 additions & 5 deletions addons/recorder/fnc_adminUIcontrol.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

- <OCAP_recorder_fnc_eh_onUserAdminStateChanged> to add/remove when a player logs in or out as admin on the server
- <OCAP_recorder_fnc_eh_onUserSelectedPlayer> at mission start to determine if a player is in <OCAP_administratorList>
- <OCAP_enabledAdministratorUI> changing during the mission, for every player ("setting")

With <OCAP_enabledAdministratorUI> off, nobody gets the entry and anyone who has it loses it. It only hides the entry: <OCAP_hasAdminControls> 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
Expand Down Expand Up @@ -52,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
{
[{
Expand All @@ -78,9 +86,6 @@ _fnc_addControls = {
];
}] call CBA_fnc_waitUntilAndExecute;
} remoteExec ["call", _owner];

// set variable on unit
_unit setVariable [QGVARMAIN(hasAdminControls), true];
};

_fnc_removeControls = {
Expand All @@ -91,10 +96,19 @@ _fnc_removeControls = {
} remoteExec ["call", _owner];

// Variable: OCAP_hasAdminControls
// Applied on units processed in <OCAP_recorder_fnc_adminUIControl>. Indicates whether or not they have the administrative diary entry available. Server missionNamespace only.
// Applied on units processed in <OCAP_recorder_fnc_adminUIControl>. Indicates whether or not they have the administrative controls: the right to raise the recording events, and the diary entry while <OCAP_enabledAdministratorUI> is on. Server missionNamespace only.
_unit setVariable [QGVARMAIN(hasAdminControls), false];
};

// 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
private _adminUIDs = missionNamespace getVariable [QGVARMAIN(administratorList), nil];

Expand Down
21 changes: 21 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ 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.

`chat_redaction_regressions.sqf` checks that a `#login` chat command reaches the
extension with everything after `#login` masked, in any case and behind any
Unicode whitespace, a non-breaking space included, while ordinary chat and
Expand Down
108 changes: 108 additions & 0 deletions tests/admin_ui_regressions.sqf
Original file line number Diff line number Diff line change
@@ -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";
Loading