From a14f91c4129c9a97f18708a990d686eea8b8d7ac Mon Sep 17 00:00:00 2001 From: Brett Hewitson Date: Wed, 22 Jun 2022 17:27:23 +1000 Subject: [PATCH] Server Availability Changes - moved a few things into the common project. --- src/ARKServerManager/ARKServerManager.csproj | 3 - .../Delegates/ServerStatusChangeDelegate.cs | 2 +- .../Enums/WatcherServerStatus.cs | 40 ---- src/ARKServerManager/Lib/ServerApp.cs | 1 + src/ARKServerManager/Lib/ServerRuntime.cs | 3 +- .../Lib/ServerStatusUpdate.cs | 4 +- .../Lib/ServerStatusUpdateRegistration.cs | 2 +- .../Lib/ServerStatusWatcher.cs | 30 +-- .../UserControls/ServerSettingsControl.xaml | 202 +++++++++--------- .../ServerSettingsControl.xaml.cs | 1 + .../Utils/DiscordBotHelper.cs | 15 +- src/ARKServerManager/Windows/MainWindow.xaml | 33 +-- .../Windows/MainWindow.xaml.cs | 3 +- .../Windows/ServerMonitorWindow.xaml | 99 ++++----- .../Windows/ServerMonitorWindow.xaml.cs | 1 + .../Windows/ShutdownWindow.xaml | 10 +- .../Windows/ShutdownWindow.xaml.cs | 1 + .../ConanServerManager.csproj | 3 - .../Delegates/ServerStatusChangeDelegate.cs | 2 +- .../Enums/AvailabilityStatus.cs | 11 - src/ConanServerManager/Enums/ServerStatus.cs | 13 -- src/ConanServerManager/Lib/ServerApp.cs | 1 + src/ConanServerManager/Lib/ServerRuntime.cs | 3 +- .../Lib/ServerStatusUpdate.cs | 4 +- .../Lib/ServerStatusUpdateRegistration.cs | 3 +- .../Lib/ServerStatusWatcher.cs | 35 ++- .../UserControls/ServerSettingsControl.xaml | 128 ++++++----- .../ServerSettingsControl.xaml.cs | 19 +- .../Utils/DiscordBotHelper.cs | 15 +- .../Windows/MainWindow.xaml | 33 +-- .../Windows/MainWindow.xaml.cs | 3 +- .../Windows/ServerMonitorWindow.xaml | 100 ++++----- .../Windows/ServerMonitorWindow.xaml.cs | 1 + .../Windows/ShutdownWindow.xaml | 10 +- .../Windows/ShutdownWindow.xaml.cs | 13 +- .../Enums/AvailabilityStatus.cs | 3 +- .../Enums/ServerStatus.cs | 2 +- .../Enums/WatcherServerStatus.cs | 2 +- 38 files changed, 393 insertions(+), 461 deletions(-) delete mode 100644 src/ARKServerManager/Enums/WatcherServerStatus.cs delete mode 100644 src/ConanServerManager/Enums/AvailabilityStatus.cs delete mode 100644 src/ConanServerManager/Enums/ServerStatus.cs rename src/{ARKServerManager => ServerManager.Common}/Enums/AvailabilityStatus.cs (68%) rename src/{ARKServerManager => ServerManager.Common}/Enums/ServerStatus.cs (79%) rename src/{ConanServerManager => ServerManager.Common}/Enums/WatcherServerStatus.cs (96%) diff --git a/src/ARKServerManager/ARKServerManager.csproj b/src/ARKServerManager/ARKServerManager.csproj index 8d2442af..5bc77930 100644 --- a/src/ARKServerManager/ARKServerManager.csproj +++ b/src/ARKServerManager/ARKServerManager.csproj @@ -187,11 +187,8 @@ - - - diff --git a/src/ARKServerManager/Delegates/ServerStatusChangeDelegate.cs b/src/ARKServerManager/Delegates/ServerStatusChangeDelegate.cs index c7ab834a..035bbc2f 100644 --- a/src/ARKServerManager/Delegates/ServerStatusChangeDelegate.cs +++ b/src/ARKServerManager/Delegates/ServerStatusChangeDelegate.cs @@ -1,4 +1,4 @@ -using ServerManagerTool.Enums; +using ServerManagerTool.Common.Enums; namespace ServerManagerTool.Delegates { diff --git a/src/ARKServerManager/Enums/WatcherServerStatus.cs b/src/ARKServerManager/Enums/WatcherServerStatus.cs deleted file mode 100644 index c89b4a0e..00000000 --- a/src/ARKServerManager/Enums/WatcherServerStatus.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace ServerManagerTool.Enums -{ - public enum WatcherServerStatus - { - /// - /// The server binary couldnot be found. - /// - NotInstalled, - - /// - /// The server binary was found, but the process was not - /// - Stopped, - - /// - /// The server binary was found, the process was found, but no permissions to access the process. - /// - Unknown, - - /// - /// The server process was found, but the server is not responding on its port - /// - Initializing, - - /// - /// The server is responding locally on its port, a local check was made - /// - RunningLocalCheck, - - /// - /// The server is responding locally on its port, a public check was made - /// - RunningExternalCheck, - - /// - /// The server is responding externally on its port - /// - Published, - } -} diff --git a/src/ARKServerManager/Lib/ServerApp.cs b/src/ARKServerManager/Lib/ServerApp.cs index 0bc05388..afdc1fd0 100644 --- a/src/ARKServerManager/Lib/ServerApp.cs +++ b/src/ARKServerManager/Lib/ServerApp.cs @@ -3,6 +3,7 @@ using NLog.Config; using NLog.Layouts; using NLog.Targets; using ServerManagerTool.Common; +using ServerManagerTool.Common.Enums; using ServerManagerTool.Common.Lib; using ServerManagerTool.Common.Model; using ServerManagerTool.Common.Utils; diff --git a/src/ARKServerManager/Lib/ServerRuntime.cs b/src/ARKServerManager/Lib/ServerRuntime.cs index 1b18a724..46f0ce75 100644 --- a/src/ARKServerManager/Lib/ServerRuntime.cs +++ b/src/ARKServerManager/Lib/ServerRuntime.cs @@ -1,10 +1,9 @@ using NLog; using ServerManagerTool.Common; -using ServerManagerTool.Common.Interfaces; +using ServerManagerTool.Common.Enums; using ServerManagerTool.Common.Lib; using ServerManagerTool.Common.Model; using ServerManagerTool.Common.Utils; -using ServerManagerTool.Enums; using ServerManagerTool.Lib.Model; using ServerManagerTool.Plugin.Common; using ServerManagerTool.Utils; diff --git a/src/ARKServerManager/Lib/ServerStatusUpdate.cs b/src/ARKServerManager/Lib/ServerStatusUpdate.cs index ae455874..c9d005a0 100644 --- a/src/ARKServerManager/Lib/ServerStatusUpdate.cs +++ b/src/ARKServerManager/Lib/ServerStatusUpdate.cs @@ -1,5 +1,5 @@ -using System.Diagnostics; -using ServerManagerTool.Enums; +using ServerManagerTool.Common.Enums; +using System.Diagnostics; namespace ServerManagerTool.Lib { diff --git a/src/ARKServerManager/Lib/ServerStatusUpdateRegistration.cs b/src/ARKServerManager/Lib/ServerStatusUpdateRegistration.cs index 162c0f39..c3e29735 100644 --- a/src/ARKServerManager/Lib/ServerStatusUpdateRegistration.cs +++ b/src/ARKServerManager/Lib/ServerStatusUpdateRegistration.cs @@ -8,7 +8,7 @@ namespace ServerManagerTool.Lib { public string InstallDirectory; public IPEndPoint LocalEndpoint; - public IPEndPoint SteamEndpoint; + public IPEndPoint PublicEndpoint; public Action UpdateCallback; public Func UnregisterAction; diff --git a/src/ARKServerManager/Lib/ServerStatusWatcher.cs b/src/ARKServerManager/Lib/ServerStatusWatcher.cs index 60a2cf36..057c8c80 100644 --- a/src/ARKServerManager/Lib/ServerStatusWatcher.cs +++ b/src/ARKServerManager/Lib/ServerStatusWatcher.cs @@ -1,4 +1,8 @@ -using System; +using NLog; +using ServerManagerTool.Common.Enums; +using ServerManagerTool.Common.Utils; +using ServerManagerTool.Enums; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -7,10 +11,6 @@ using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; -using NLog; -using ServerManagerTool.Common.Interfaces; -using ServerManagerTool.Common.Utils; -using ServerManagerTool.Enums; namespace ServerManagerTool.Lib { @@ -46,7 +46,7 @@ namespace ServerManagerTool.Lib InstallDirectory = installDirectory, ProfileId = profileId, LocalEndpoint = localEndpoint, - SteamEndpoint = steamEndpoint, + PublicEndpoint = steamEndpoint, UpdateCallback = updateCallback, }; @@ -57,7 +57,7 @@ namespace ServerManagerTool.Lib { if(_serverRegistrations.Contains(registration)) { - Logger.Debug($"{nameof(RegisterForUpdates)} Removing registration for L:{registration.LocalEndpoint} S:{registration.SteamEndpoint}"); + Logger.Debug($"{nameof(RegisterForUpdates)} Removing registration for L:{registration.LocalEndpoint} P:{registration.PublicEndpoint}"); _serverRegistrations.Remove(registration); } tcs.TrySetResult(true); @@ -71,10 +71,10 @@ namespace ServerManagerTool.Lib { if (!_serverRegistrations.Contains(registration)) { - Logger.Debug($"{nameof(RegisterForUpdates)} Adding registration for L:{registration.LocalEndpoint} S:{registration.SteamEndpoint}"); + Logger.Debug($"{nameof(RegisterForUpdates)} Adding registration for L:{registration.LocalEndpoint} P:{registration.PublicEndpoint}"); _serverRegistrations.Add(registration); - var registrationKey = registration.SteamEndpoint.ToString(); + var registrationKey = registration.PublicEndpoint.ToString(); _nextExternalStatusQuery[registrationKey] = DateTime.MinValue; } return Task.FromResult(true); @@ -204,7 +204,7 @@ namespace ServerManagerTool.Lib private async Task GenerateServerStatusUpdateAsync(ServerStatusUpdateRegistration registration) { - var registrationKey = registration.SteamEndpoint.ToString(); + var registrationKey = registration.PublicEndpoint.ToString(); // // First check the process status @@ -246,10 +246,10 @@ namespace ServerManagerTool.Lib // // Now that it's running, we can check the publication status. // - Logger.Info($"{nameof(GenerateServerStatusUpdateAsync)} Checking server public status direct at {registration.SteamEndpoint}"); + Logger.Info($"{nameof(GenerateServerStatusUpdateAsync)} Checking server public (directly) status at {registration.PublicEndpoint}"); // get the server information direct from the server using public connection. - var serverStatus = CheckServerStatusDirect(registration.SteamEndpoint); + var serverStatus = CheckServerStatusDirect(registration.PublicEndpoint); // check if the server returned the information. if (!serverStatus) { @@ -261,11 +261,11 @@ namespace ServerManagerTool.Lib if (!string.IsNullOrWhiteSpace(Config.Default.ServerStatusUrlFormat)) { - Logger.Info($"{nameof(GenerateServerStatusUpdateAsync)} Checking server public status via api at {registration.SteamEndpoint}"); + Logger.Info($"{nameof(GenerateServerStatusUpdateAsync)} Checking server public (via api) status at {registration.PublicEndpoint}"); // get the server information direct from the server using external connection. - var uri = new Uri(string.Format(Config.Default.ServerStatusUrlFormat, Config.Default.ServerManagerCode, App.Instance.Version, registration.SteamEndpoint.Address, registration.SteamEndpoint.Port)); - serverStatus = await NetworkUtils.CheckServerStatusViaAPI(uri, registration.SteamEndpoint); + var uri = new Uri(string.Format(Config.Default.ServerStatusUrlFormat, Config.Default.ServerManagerCode, App.Instance.Version, registration.PublicEndpoint.Address, registration.PublicEndpoint.Port)); + serverStatus = await NetworkUtils.CheckServerStatusViaAPI(uri, registration.PublicEndpoint); } _nextExternalStatusQuery[registrationKey] = DateTime.Now.AddMilliseconds(Config.Default.ServerStatusWatcher_RemoteStatusQueryDelay); diff --git a/src/ARKServerManager/UserControls/ServerSettingsControl.xaml b/src/ARKServerManager/UserControls/ServerSettingsControl.xaml index adfebbb1..941ea50e 100644 --- a/src/ARKServerManager/UserControls/ServerSettingsControl.xaml +++ b/src/ARKServerManager/UserControls/ServerSettingsControl.xaml @@ -6,6 +6,7 @@ xmlns:mts="clr-namespace:Microsoft.Win32.TaskScheduler;assembly=Microsoft.Win32.TaskScheduler" xmlns:cctl="clr-namespace:ServerManagerTool.Common.Controls;assembly=ServerManager.Common" xmlns:cc="clr-namespace:ServerManagerTool.Common.Converters;assembly=ServerManager.Common" + xmlns:ce="clr-namespace:ServerManagerTool.Common.Enums;assembly=ServerManager.Common" xmlns:clib="clr-namespace:ServerManagerTool.Common.Lib;assembly=ServerManager.Common" xmlns:cvr="clr-namespace:ServerManagerTool.Common.ValidationRules;assembly=ServerManager.Common" xmlns:com="clr-namespace:ServerManagerTool.Common;assembly=ServerManager.Common" @@ -314,32 +315,32 @@ - + - + - + - + - + - + - + @@ -371,26 +372,26 @@ - + - + - + - + - + - + - + @@ -419,19 +420,16 @@