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

Debug watching for any client #659

Merged
merged 3 commits into from
May 3, 2017
Merged
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
8 changes: 4 additions & 4 deletions addons/diagnostic/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class Cfg3DEN {
class AttributeCategories {
class States {
class Attributes {
class EnableServerDebug {
property = "EnableServerDebug";
class EnableTargetDebug {
property = "EnableTargetDebug";
value = 0;
control = "CheckboxNumber";
displayName = CSTRING(EnableServerDebug);
tooltip = CSTRING(EnableServerDebug_tooltip);
displayName = CSTRING(EnableTargetDebug);
tooltip = CSTRING(EnableTargetDebug_tooltip);
defaultValue = "0";
expression = "true";
wikiType = "[[Bool]]";
Expand Down
9 changes: 2 additions & 7 deletions addons/diagnostic/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

class Extended_DisplayLoad_EventHandlers {
class RscDisplayDebugPublic {
Expand All @@ -24,10 +19,10 @@ class Extended_DisplayLoad_EventHandlers {
};
class RscDisplayInterrupt {
GVAR(extendedDebug) = QUOTE(_this call (uiNamespace getVariable 'FUNC(initExtendedDebugConsole)'));
GVAR(serverDebug) = QUOTE(_this call (uiNamespace getVariable 'FUNC(initServerDebugConsole)'));
GVAR(serverDebug) = QUOTE(_this call (uiNamespace getVariable 'FUNC(initTargetDebugConsole)'));
};
class RscDisplayMPInterrupt {
GVAR(extendedDebug) = QUOTE(_this call (uiNamespace getVariable 'FUNC(initExtendedDebugConsole)'));
GVAR(serverDebug) = QUOTE(_this call (uiNamespace getVariable 'FUNC(initServerDebugConsole)'));
GVAR(serverDebug) = QUOTE(_this call (uiNamespace getVariable 'FUNC(initTargetDebugConsole)'));
};
};
30 changes: 0 additions & 30 deletions addons/diagnostic/XEH_postInit.sqf

This file was deleted.

49 changes: 49 additions & 0 deletions addons/diagnostic/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,52 @@ GVAR(projectileStartedDrawing) = false;
GVAR(projectileTrackedUnits) = [];

ADDON = true;

if (getMissionConfigValue ["EnableTargetDebug", 0] isEqualTo 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"];
_this = ([nil] apply compile _this) select 0;
if (isNil "_this") exitWith {"#NIL"};
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, profileName]];
};

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

GVAR(clientIDs) pushBackUnique [_owner, _name];
publicVariable QGVAR(clientIDs);
}];

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

GVAR(clientIDs) deleteAt (GVAR(clientIDs) find [_owner, _name]);
publicVariable QGVAR(clientIDs);
}];
};
};
2 changes: 1 addition & 1 deletion addons/diagnostic/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#include "XEH_PREP.sqf"

PREP(initExtendedDebugConsole);
PREP(initServerDebugConsole);
PREP(initTargetDebugConsole);
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/* ----------------------------------------------------------------------------
Function: CBA_diagnostic_fnc_initServerDebugConsole
Function: CBA_diagnostic_fnc_initTargetDebugConsole

Description:
Adds addition watch statements that are run on the server and have their values returned to the client.
Requires `enableServerDebug = 1; `in description.ext
Adds addition watch statements that are run on a remote target and have their values returned to the client.
Requires `EnableTargetDebug = 1; `in description.ext

Author:
PabstMirror (based heavily on BIS's RscDebugConsole.sqf)
(based on BIS's RscDebugConsole.sqf)
PabstMirror
commy2
---------------------------------------------------------------------------- */

//#define DEBUG_MODE_FULL
#include "\a3\ui_f\hpp\defineResinclDesign.inc"
#include "script_component.hpp"

#define COUNT_WATCH_BOXES 4
#define COUNT_WATCH_BOXES 8

if (!((getMissionConfigValue ["enableServerDebug", 0]) isEqualTo 1)) exitWith {};
if (!((getMissionConfigValue ["EnableTargetDebug", 0]) isEqualTo 1)) exitWith {};

params ["_display"];
TRACE_1("adding server watch debug",_display);
Expand All @@ -27,31 +29,58 @@ _debugConsolePos set [2, (_debugConsolePos select 2) + 22.5 * GUI_GRID_W];
_debugConsole ctrlSetPosition _debugConsolePos;
_debugConsole ctrlCommit 0;

// Add background and "Server Watch" text:
private _serverWatchBackground = _display ctrlCreate ["RscText", -1, _debugConsole];
_serverWatchBackground ctrlSetBackgroundColor [0,0,0,0.7];
private _ctrlPos = ctrlPosition (_display displayCtrl IDC_RSCDEBUGCONSOLE_WATCHBACKGROUND);
private _basePosition = ctrlPosition (_display displayCtrl IDC_RSCDEBUGCONSOLE_WATCHINPUT1);
_basePosition set [0, (_basePosition select 0) + 22.5 * GUI_GRID_W];
_basePosition set [1, (_basePosition select 1) - (1.5 + 2 * (COUNT_WATCH_BOXES - 4)) * GUI_GRID_H];


// Add background and "Target Watch" text:
private _targetWatchBackground = _display ctrlCreate ["RscText", -1, _debugConsole];
_targetWatchBackground ctrlSetBackgroundColor [0,0,0,0.7];
_ctrlPos = ctrlPosition (_display displayCtrl IDC_RSCDEBUGCONSOLE_WATCHBACKGROUND);
_ctrlPos set [0, (_ctrlPos select 0) + 22.5 * GUI_GRID_W];
_ctrlPos set [1, (_ctrlPos select 1) - 2 * (COUNT_WATCH_BOXES - 4) * GUI_GRID_H];
_ctrlPos set [3, (_ctrlPos select 3) + 2 * (COUNT_WATCH_BOXES - 4) * GUI_GRID_H];
_serverWatchBackground ctrlSetPosition _ctrlPos;
_serverWatchBackground ctrlCommit 0;
private _serverWatchText = _display ctrlCreate ["RscText", -1, _debugConsole];
_serverWatchText ctrlSetText format ["Server %1", localize "STR_A3_RscDebugConsole_WatchText"];
_serverWatchText ctrlSetFontHeight (0.8 * GUI_GRID_H);
_ctrlPos set [1, (_ctrlPos select 1) - (1.5 + 2 * (COUNT_WATCH_BOXES - 4)) * GUI_GRID_H];
_ctrlPos set [3, (_ctrlPos select 3) + (1.5 + 2 * (COUNT_WATCH_BOXES - 4)) * GUI_GRID_H];
_targetWatchBackground ctrlSetPosition _ctrlPos;
_targetWatchBackground ctrlCommit 0;
private _targetWatchText = _display ctrlCreate ["RscText", -1, _debugConsole];
_targetWatchText ctrlSetText format ["%1 %2", localize "str_watch_target", localize "STR_A3_RscDebugConsole_WatchText"];
_targetWatchText ctrlSetFontHeight (0.7 * GUI_GRID_H);
_ctrlPos set [0, (_ctrlPos select 0) + 0.2 * GUI_GRID_W];
_ctrlPos set [3, 0.5 * GUI_GRID_W];
_serverWatchText ctrlSetPosition _ctrlPos;
_serverWatchText ctrlCommit 0;
_targetWatchText ctrlSetPosition _ctrlPos;
_targetWatchText ctrlCommit 0;



// Add target selector list
private _clientList = _display ctrlCreate ["RscCombo", -1, _debugConsole];
_clientList ctrlSetPosition _basePosition;
_clientList ctrlCommit 0;
_basePosition set [1, (_basePosition select 1) + 1.5 * GUI_GRID_H];

// - add available targets to list
private _lastSelected = 0;
{
_x params ["_clientID", "_profileName"];
_clientList lbSetValue [_clientList lbAdd format ["%1 - %2", _clientID, _profileName], _clientID];
if (_clientID == GVAR(selectedClientID)) then {_lastSelected = _forEachIndex};
} forEach GVAR(clientIDs);

_clientList lbSetCurSel _lastSelected;
GVAR(selectedClientID) = _clientList lbValue lbCurSel _clientList;

_clientList ctrlAddEventHandler ["LBSelChanged", {
params ["_clientList", "_index"];

GVAR(selectedClientID) = _clientList lbValue _index;
}];


private _watchVars = [];
private _basePosition = ctrlPosition (_display displayCtrl IDC_RSCDEBUGCONSOLE_WATCHINPUT1);
_basePosition set [0, (_basePosition select 0) + 22.5 * GUI_GRID_W];
_basePosition set [1, (_basePosition select 1) - 2 * (COUNT_WATCH_BOXES - 4) * GUI_GRID_H];
for "_varIndex" from 0 to (COUNT_WATCH_BOXES - 1) do {
// Create the controls for each row and fill input with last saved value from profile
private _profileVarName = format ["CBA_serverWatch_%1", _varIndex];
private _profileVarName = format ["CBA_targetWatch_%1", _varIndex];
private _savedStatement = profileNamespace getVariable [_profileVarName, ""];
if (!(_savedStatement isEqualType "")) then {_savedStatement = ""};

Expand All @@ -77,14 +106,14 @@ for "_varIndex" from 0 to (COUNT_WATCH_BOXES - 1) do {
_display setVariable [QGVAR(watchVars), _watchVars];


// Runs constantly, sends statement to server and parses the result back in the output window
// Runs constantly, sends statement to target and parses the result back in the output window
private _fnc_updateWatchInfo = {
params ["_display"];

private _watchVars = _display getVariable [QGVAR(watchVars), []];
{
private _varIndex = _forEachIndex;
private _varName = format ["CBA_serverWatchVar_%1_%2", CBA_clientID, _varIndex];
private _varName = format ["CBA_targetWatchVar_%1_%2", CBA_clientID, _varIndex];
_x params ["_inputEditbox", "_outputBackground", "_outputEditBox", "_lastSent"];
private _editText = ctrlText _inputEditbox;
(missionNamespace getVariable [_varName, []]) params [["_responseStatement", "", [""]], ["_responseReturn", "", [""]], ["_duration", 0, [0]]];
Expand All @@ -95,7 +124,7 @@ private _fnc_updateWatchInfo = {
if ((_editText isEqualTo _responseStatement) && {_duration > 0.1}) exitWith {}; // don't re-run if statement that took a long time
if ((diag_tickTime - _lastSent) > random [0.1, 0.2, 0.3]) then {
_x set [3, diag_tickTime]; // set last run to now
[QGVAR(serverWatchVariable), [CBA_clientID, _varIndex, _editText]] call CBA_fnc_serverEvent; // send statement to server
[QGVAR(watchVariable), [CBA_clientID, _varIndex, _editText], GVAR(selectedClientID)] call CBA_fnc_ownerEvent; // send statement to target
};
};

Expand All @@ -121,12 +150,12 @@ private _fnc_onUnload = {
{
_x params ["_inputEditbox", "_outputBackground", "_outputEditBox", "_lastSent"];
private _varIndex = _forEachIndex;
private _varName = format ["CBA_serverWatchVar_%1_%2", CBA_clientID, _varIndex];
private _varName = format ["CBA_targetWatchVar_%1_%2", CBA_clientID, _varIndex];
private _editText = ctrlText _inputEditbox;
(missionNamespace getVariable [_varName, []]) params [["_responseStatement", "", [""]], ["_responseReturn", "", [""]], ["_duration", 0, [0]]];

if ((_editText isEqualTo _responseStatement) && {_duration < 0.1}) then {
private _profileVarName = format ["CBA_serverWatch_%1", _varIndex];
private _profileVarName = format ["CBA_targetWatch_%1", _varIndex];
profileNamespace setVariable [_profileVarName, _responseStatement];
};
} forEach _watchVars;
Expand Down
8 changes: 4 additions & 4 deletions addons/diagnostic/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<German>Nächster Ausdruck</German>
</Key>

<Key ID="STR_CBA_Diagnostic_EnableServerDebug">
<English>Enable Server Debug</English>
<Key ID="STR_CBA_Diagnostic_EnableTargetDebug">
<English>Enable Target Debuging</English>
</Key>
<Key ID="STR_CBA_Diagnostic_EnableServerDebug_tooltip">
<English>Determines server watch field availability. Requires Debug Console.</English>
<Key ID="STR_CBA_Diagnostic_EnableTargetDebug_tooltip">
<English>[CBA] Allows remote target debugging. Requires Debug Console.</English>
</Key>
</Package>
</Project>