From 329c147419cabc717a03796f68b9da5bb5e04720 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Fri, 8 Sep 2023 22:26:28 -0500 Subject: [PATCH] Added built-in IPX relay for DOSBox --- LANCommander/LANCommander.csproj | 1 + LANCommander/Models/Settings.cs | 8 +++ LANCommander/Pages/Settings/IPXRelay.razor | 53 +++++++++++++++++++ .../Pages/Settings/SettingsLayout.razor | 1 + LANCommander/Services/IPXRelayService.cs | 42 +++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 LANCommander/Pages/Settings/IPXRelay.razor create mode 100644 LANCommander/Services/IPXRelayService.cs diff --git a/LANCommander/LANCommander.csproj b/LANCommander/LANCommander.csproj index c5571b6..c001d95 100644 --- a/LANCommander/LANCommander.csproj +++ b/LANCommander/LANCommander.csproj @@ -32,6 +32,7 @@ + diff --git a/LANCommander/Models/Settings.cs b/LANCommander/Models/Settings.cs index 3554537..b0cd55c 100644 --- a/LANCommander/Models/Settings.cs +++ b/LANCommander/Models/Settings.cs @@ -16,6 +16,7 @@ public LANCommanderTheme Theme { get; set; } = LANCommanderTheme.Light; public LANCommanderAuthenticationSettings Authentication { get; set; } = new LANCommanderAuthenticationSettings(); + public LANCommanderIPXRelaySettings IPXRelay { get; set; } = new LANCommanderIPXRelaySettings(); } public class LANCommanderAuthenticationSettings @@ -29,4 +30,11 @@ public bool PasswordRequireDigit { get; set; } = true; public int PasswordRequiredLength { get; set; } = 8; } + + public class LANCommanderIPXRelaySettings + { + public bool Enabled { get; set; } = false; + public int Port { get; set; } = 213; + public bool Logging { get; set; } = false; + } } diff --git a/LANCommander/Pages/Settings/IPXRelay.razor b/LANCommander/Pages/Settings/IPXRelay.razor new file mode 100644 index 0000000..e3380ed --- /dev/null +++ b/LANCommander/Pages/Settings/IPXRelay.razor @@ -0,0 +1,53 @@ +@page "/Settings/IPXRelay" +@using LANCommander.Models; +@layout SettingsLayout +@inject SettingService SettingService +@inject IPXRelayService IPXRelayService +@inject IMessageService MessageService +@attribute [Authorize(Roles = "Administrator")] + + + +
+
+ + + + + + + + + + + + + + + +
+
+ +@code { + LANCommanderSettings Settings; + + protected override async Task OnInitializedAsync() + { + Settings = SettingService.GetSettings(); + } + + private void Save() + { + try + { + SettingService.SaveSettings(Settings); + MessageService.Success("Settings saved!"); + + IPXRelayService.Init(); + } + catch + { + MessageService.Error("An unknown error occurred."); + } + } +} diff --git a/LANCommander/Pages/Settings/SettingsLayout.razor b/LANCommander/Pages/Settings/SettingsLayout.razor index 728eaf5..179367a 100644 --- a/LANCommander/Pages/Settings/SettingsLayout.razor +++ b/LANCommander/Pages/Settings/SettingsLayout.razor @@ -8,6 +8,7 @@ General Users Authentication + IPX Relay Tools diff --git a/LANCommander/Services/IPXRelayService.cs b/LANCommander/Services/IPXRelayService.cs new file mode 100644 index 0000000..80aee18 --- /dev/null +++ b/LANCommander/Services/IPXRelayService.cs @@ -0,0 +1,42 @@ +using IPXRelayDotNet; + +namespace LANCommander.Services +{ + public class IPXRelayService : BaseService + { + private IPXRelay Relay; + + public IPXRelayService() + { + if (Relay == null) + Relay = new IPXRelay(); + + Init(); + } + + public void Init() + { + var settings = SettingService.GetSettings(); + + if (Relay != null) + Stop(); + + if (Relay == null) + Relay = new IPXRelay(settings.IPXRelay.Port); + + if (!settings.IPXRelay.Logging) + Relay.DisableLogging(); + + if (settings.IPXRelay.Enabled) + Relay.StartAsync(); + } + + public void Stop() + { + if (Relay != null) + Relay.Dispose(); + + Relay = null; + } + } +}