Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to force target debug console from server's config #1364

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
104 changes: 59 additions & 45 deletions addons/diagnostic/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LOG(MSG_INIT);

ADDON = false;

#include "initSettings.sqf"

#include "XEH_PREP.sqf"

[QGVAR(debug), {_this call CBA_fnc_debug}] call CBA_fnc_addEventHandler;
Expand All @@ -18,55 +20,67 @@ GVAR(projectileTrackedUnits) = [];

ADDON = true;

if (getMissionConfigValue ["EnableTargetDebug", 0] == 1 || {getNumber (configFile >> "EnableTargetDebug") == 1}) then {
INFO("EnableTargetDebug is enabled.");

[QGVAR(watchVariable), {
params ["_clientID", "_varIndex", "_statementText"];
TRACE_3("targetWatchVariable",_clientID,_varIndex,_statementText);

private _timeStart = diag_tickTime;
private _returnString = _statementText call {
private ["_clientID", "_statementText", "_varName", "_timeStart", "_x"]; // prevent these variables from being overwritten
_this = ([nil] apply compile _this) select 0;
if (isNil "_this") exitWith {"<any>"};
str _this
};
_returnString = _returnString select [0, 1000]; // limit string length
private _duration = diag_tickTime - _timeStart;

private _varName = format ["CBA_targetWatchVar_%1_%2", _clientID, _varIndex];
(missionNamespace getVariable [_varName, []]) params [["_responseStatement", "", [""]], ["_responseReturn", "", [""]], ["_lastDuration", 0, [0]]];

if (_responseStatement isEqualTo _statementText) then {
_duration = 0.1 * _duration + 0.9 * _lastDuration; // if statement is the same, get an average
// Wait initializion of settings to set global variable
["CBA_settingsInitialized", {
GVAR(settingsInitialized) = true;
}] call CBA_fnc_addEventHandler;

0 spawn {
waitUntil{!(isNil QGVAR(settingsInitialized))};
if (
getMissionConfigValue ["EnableTargetDebug", 0] == 1
|| {getNumber (configFile >> "EnableTargetDebug") == 1}
|| {GVAR(enableTargetDebug)}
) then {
INFO("EnableTargetDebug is enabled.");

[QGVAR(watchVariable), {
params ["_clientID", "_varIndex", "_statementText"];
TRACE_3("targetWatchVariable",_clientID,_varIndex,_statementText);

private _timeStart = diag_tickTime;
private _returnString = _statementText call {
private ["_clientID", "_statementText", "_varName", "_timeStart", "_x"]; // prevent these variables from being overwritten
_this = ([nil] apply compile _this) select 0;
if (isNil "_this") exitWith {"<any>"};
str _this
};
_returnString = _returnString select [0, 1000]; // limit string length
private _duration = diag_tickTime - _timeStart;

private _varName = format ["CBA_targetWatchVar_%1_%2", _clientID, _varIndex];
(missionNamespace getVariable [_varName, []]) params [["_responseStatement", "", [""]], ["_responseReturn", "", [""]], ["_lastDuration", 0, [0]]];

if (_responseStatement isEqualTo _statementText) then {
_duration = 0.1 * _duration + 0.9 * _lastDuration; // if statement is the same, get an average
};

missionNamespace setVariable [_varName, [_statementText, _returnString, _duration]];
if (_clientID != CBA_clientID) then {
publicVariable _varName; // send back over network
};
}] call CBA_fnc_addEventHandler;


if (isNil QGVAR(clientIDs)) then {
GVAR(clientIDs) = [[2, format ["[SERVER] %1", profileName]]];
};

missionNamespace setVariable [_varName, [_statementText, _returnString, _duration]];
if (_clientID != CBA_clientID) then {
publicVariable _varName; // send back over network
};
}] call CBA_fnc_addEventHandler;


if (isNil QGVAR(clientIDs)) then {
GVAR(clientIDs) = [[2, format ["[SERVER] %1", profileName]]];
};

if (isServer) then {
addMissionEventHandler ["PlayerConnected", {
params ["", "", "_name", "", "_owner"];
if (isServer) then {
addMissionEventHandler ["PlayerConnected", {
params ["", "", "_name", "", "_owner"];

if (_owner == 2) exitWith {};
GVAR(clientIDs) pushBackUnique [_owner, _name];
publicVariable QGVAR(clientIDs);
}];
if (_owner == 2) exitWith {};
GVAR(clientIDs) pushBackUnique [_owner, _name];
publicVariable QGVAR(clientIDs);
}];

addMissionEventHandler ["PlayerDisconnected", {
params ["", "", "_name", "", "_owner"];
addMissionEventHandler ["PlayerDisconnected", {
params ["", "", "_name", "", "_owner"];

GVAR(clientIDs) deleteAt (GVAR(clientIDs) find [_owner, _name]);
publicVariable QGVAR(clientIDs);
}];
GVAR(clientIDs) deleteAt (GVAR(clientIDs) find [_owner, _name]);
publicVariable QGVAR(clientIDs);
}];
};
};
};
9 changes: 7 additions & 2 deletions addons/diagnostic/fnc_initTargetDebugConsole.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Function: CBA_diagnostic_fnc_initTargetDebugConsole

Description:
Adds additional watch statements that are run on a remote target and have their values returned to the client.
Requires `EnableTargetDebug = 1;` in addon root config or description.ext or 3den scenario attribute with the same name
Requires `EnableTargetDebug = 1;` in addon root config or description.ext or 3den scenario attribute with the same name or in server/mission's config

Author:
(based on BIS's RscDebugConsole.sqf)
Expand All @@ -18,7 +18,12 @@ Author:
#define EXEC_RESULT_CTRL (parsingNamespace getVariable ["BIS_RscDebugConsoleExpressionResultCtrl", controlNull])
#define EXEC_SEND_RESULT {[EXEC_RESULT, {EXEC_RESULT_CTRL ctrlSetText str _this}] remoteExec ["call", remoteExecutedOwner]}

if !(getMissionConfigValue ["EnableTargetDebug", 0] == 1 || {getNumber (configFile >> "EnableTargetDebug") == 1}) exitWith {};
waitUntil{!isNil QGVAR(settingsInitialized)};
if !(
getMissionConfigValue ["EnableTargetDebug", 0] == 1
|| {getNumber (configFile >> "EnableTargetDebug") == 1}
|| {GVAR(enableTargetDebug)}
) exitWith {};

params ["_display"];
TRACE_1("adding server watch debug",_display);
Expand Down
12 changes: 12 additions & 0 deletions addons/diagnostic/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[
QGVAR(enableTargetDebug),
"CHECKBOX",
LLSTRING(EnableTargetDebug),
LLSTRING(Category),
false, // default value
1, // isGlobal
nil,
true
] call CBA_fnc_addSetting;

10 changes: 10 additions & 0 deletions addons/diagnostic/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,15 @@
<Italian>[CBA] Abilita il debug remoto. Richiede la console di debug.</Italian>
<Czech>[CBA] Povoluje ladění vzdáleného cíle. Vyžaduje ladící konzoli.</Czech>
</Key>
<Key ID="STR_CBA_Diagnostic_Category">
<English>CBA Diagnostics</English>
<German>CBA Diagnose</German>
<Polish>CBA Diagnostyka</Polish>
<Italian>Armi Diagnostica</Italian>
<Czech>Diagnostika CBA</Czech>
<Turkish>CBA Teşhis</Turkish>
<French>CBA Diagnostics</French>
<Russian>CBA Диагностика</Russian>
</Key>
</Package>
</Project>
2 changes: 1 addition & 1 deletion addons/settings/fnc_addSetting.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Parameters:
_title - Display name or display name + tooltip (optional, default: same as setting name) <STRING, ARRAY>
_category - Category for the settings menu + optional sub-category <STRING, ARRAY>
_valueInfo - Extra properties of the setting depending of _settingType. See examples below <ANY>
_isGlobal - 1: all clients share the same setting, 2: setting can't be overwritten (optional, default: 0) <ARRAY>
_isGlobal - 1: all clients share the same setting, 2: setting can't be overwritten (optional, default: 0) <BOOL, NUMBER>
_script - Script to execute when setting is changed. (optional) <CODE>
_needRestart - Setting will be marked as needing mission restart after being changed. (optional, default false) <BOOL>

Expand Down