Skip to content

Commit

Permalink
Identify lua console based on id everywhere (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom authored Jan 30, 2024
1 parent b16dce8 commit 51dbc7e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/client/DCSInsight/Misc/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
internal static class Constants
{
internal const string ListEnvironmentSnippet = "local keys = {}\r\nfor k, v in pairs(_G) do\r\n\tkeys[#keys+1] = k \r\nend\r\nreturn keys";
internal const string LuaConsole = "Lua Console";
internal const int LuaConsole = 1;
}
}
10 changes: 5 additions & 5 deletions src/client/DCSInsight/UserControls/UserControlAPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract partial class UserControlAPIBase : UserControl, IDisposable, IAs
protected bool IsConnected;
private readonly Timer _pollingTimer;
protected bool CanSend;
private bool KeepResults;
private bool _keepResults;
protected Button ButtonSend;
protected Label LabelKeepResults;
protected CheckBox CheckBoxKeepResults;
Expand All @@ -46,7 +46,7 @@ public abstract partial class UserControlAPIBase : UserControl, IDisposable, IAs
protected UserControlAPIBase(DCSAPI dcsAPI, bool isConnected)
{
DCSAPI = dcsAPI;
IsLuaConsole = DCSAPI.Syntax == Constants.LuaConsole;
IsLuaConsole = DCSAPI.Id == Constants.LuaConsole;
Id = DCSAPI.Id;
IsConnected = isConnected;
_pollingTimer = new Timer(PollingTimerCallback);
Expand Down Expand Up @@ -129,7 +129,7 @@ internal void SetResult(DCSAPI dcsApi)

DCSAPI.Result = result;

if (KeepResults)
if (_keepResults)
{
Dispatcher?.BeginInvoke((Action)(() => TextBoxResultBase.Text = TextBoxResultBase.Text.Insert(0, result + "\n")));
return;
Expand Down Expand Up @@ -291,7 +291,7 @@ protected void CheckBoxKeepResults_OnUnchecked(object sender, RoutedEventArgs e)
{
try
{
KeepResults = false;
_keepResults = false;
SetFormState();
}
catch (Exception ex)
Expand All @@ -304,7 +304,7 @@ protected void CheckBoxKeepResults_OnChecked(object sender, RoutedEventArgs e)
{
try
{
KeepResults = true;
_keepResults = true;
SetFormState();
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion src/client/DCSInsight/Windows/WindowRangeTest.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public WindowRangeTest(List<DCSAPI> dcsAPIList)
{
InitializeComponent();
_dcsAPIList = dcsAPIList;
_dcsAPIList.RemoveAll(o => o.Syntax == Constants.LuaConsole);
_dcsAPIList.RemoveAll(o => o.Id == Constants.LuaConsole);
ICEventHandler.AttachErrorListener(this);
ICEventHandler.AttachConnectionListener(this);
ICEventHandler.AttachDataListener(this);
Expand Down
19 changes: 19 additions & 0 deletions src/server/Scripts/DCS-INSIGHT/_ServerSettingsDevelopment.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module("ServerSettingsDevelopment", package.seeall)

--- @class ServerSettingsDevelopment : APIBase
--- @field TCP_address string
--- @field TCP_port integer
local ServerSettingsDevelopment = {}

ServerSettingsDevelopment.TCP_address = "*"
ServerSettingsDevelopment.TCP_port = 7790

-- Log incoming and outgoing JSON
ServerSettingsDevelopment.Log_JSON = false

-- WARNING! This function enables arbitrary lua code to be
-- executed on your computer, including calls to package os (Operating System).
-- Do NOT enable unless your are firewalled.
ServerSettingsDevelopment.EnableLuaConsole = true

return ServerSettingsDevelopment
2 changes: 2 additions & 0 deletions src/server/Scripts/DCS-INSIGHT/lib/APIHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ function APIHandler:addLuaConsole()
if ServerSettings.EnableLuaConsole then
self.commandsTable[#self.commandsTable + 1] = LoadStringAPI:new(nil, counter())
self.apiTable[#self.apiTable + 1] = self.commandsTable[#self.commandsTable].apiInfo
else
counter() -- increase counter as 1 is reserved for lua console
end
end

Expand Down

0 comments on commit 51dbc7e

Please sign in to comment.