From a895db1b3fc6346ce77da5a3bc21aae2ccebb0fd Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 18 May 2020 10:14:44 -0400 Subject: [PATCH 1/7] Minor comment --- src/Tgstation.Server.Host/Database/DatabaseContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tgstation.Server.Host/Database/DatabaseContext.cs b/src/Tgstation.Server.Host/Database/DatabaseContext.cs index 0fbf07f722..09da5968ef 100644 --- a/src/Tgstation.Server.Host/Database/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Database/DatabaseContext.cs @@ -247,6 +247,7 @@ namespace Tgstation.Server.Host.Database /// protected override void OnModelCreating(ModelBuilder modelBuilder) { + // Setup our more complex database relations Logger.LogTrace("Building entity framework context..."); base.OnModelCreating(modelBuilder); From a55782d33a7e15901e05d23bfd0c18d19cca15e7 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 18 May 2020 10:15:47 -0400 Subject: [PATCH 2/7] Remove changes detection from codecov --- .codecov.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index c82fe4fb61..9c2f3f328a 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -14,10 +14,5 @@ coverage: default: target: 100 only_pulls: true - changes: - default: - if_no_uploads: failure - if_ci_failed: failure - only_pulls: yes comment: layout: "header, diff, changes" From 0b147582ba3cb9bae0122986e7d4a52407bd7de9 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 18 May 2020 10:26:10 -0400 Subject: [PATCH 3/7] Move a bunch of Bridge classes to the namespace --- src/Tgstation.Server.Host/Components/IInstanceFactory.cs | 2 +- src/Tgstation.Server.Host/Components/IInstanceManager.cs | 2 +- src/Tgstation.Server.Host/Components/InstanceFactory.cs | 2 +- .../Components/Interop/{ => Bridge}/BridgeRegistration.cs | 2 +- .../Components/Interop/{ => Bridge}/IBridgeDispatcher.cs | 3 +-- .../Components/Interop/{ => Bridge}/IBridgeHandler.cs | 2 +- .../Components/Interop/{ => Bridge}/IBridgeRegistrar.cs | 2 +- .../Components/Interop/{ => Bridge}/IBridgeRegistration.cs | 2 +- src/Tgstation.Server.Host/Core/Application.cs | 2 +- 9 files changed, 9 insertions(+), 10 deletions(-) rename src/Tgstation.Server.Host/Components/Interop/{ => Bridge}/BridgeRegistration.cs (93%) rename src/Tgstation.Server.Host/Components/Interop/{ => Bridge}/IBridgeDispatcher.cs (87%) rename src/Tgstation.Server.Host/Components/Interop/{ => Bridge}/IBridgeHandler.cs (92%) rename src/Tgstation.Server.Host/Components/Interop/{ => Bridge}/IBridgeRegistrar.cs (87%) rename src/Tgstation.Server.Host/Components/Interop/{ => Bridge}/IBridgeRegistration.cs (72%) diff --git a/src/Tgstation.Server.Host/Components/IInstanceFactory.cs b/src/Tgstation.Server.Host/Components/IInstanceFactory.cs index b6f08c05d9..ce13cdf11e 100644 --- a/src/Tgstation.Server.Host/Components/IInstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/IInstanceFactory.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.Hosting; -using Tgstation.Server.Host.Components.Interop; +using Tgstation.Server.Host.Components.Interop.Bridge; namespace Tgstation.Server.Host.Components { diff --git a/src/Tgstation.Server.Host/Components/IInstanceManager.cs b/src/Tgstation.Server.Host/Components/IInstanceManager.cs index 0b4ff87a9c..8e2f9b8f2b 100644 --- a/src/Tgstation.Server.Host/Components/IInstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/IInstanceManager.cs @@ -1,6 +1,6 @@ using System.Threading; using System.Threading.Tasks; -using Tgstation.Server.Host.Components.Interop; +using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Models; namespace Tgstation.Server.Host.Components diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 7b841e1270..36164a020b 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -7,7 +7,7 @@ using Tgstation.Server.Host.Components.Byond; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Components.Deployment; -using Tgstation.Server.Host.Components.Interop; +using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Components.Repository; using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Components.Watchdog; diff --git a/src/Tgstation.Server.Host/Components/Interop/BridgeRegistration.cs b/src/Tgstation.Server.Host/Components/Interop/Bridge/BridgeRegistration.cs similarity index 93% rename from src/Tgstation.Server.Host/Components/Interop/BridgeRegistration.cs rename to src/Tgstation.Server.Host/Components/Interop/Bridge/BridgeRegistration.cs index 54037a40f8..99c94047cc 100644 --- a/src/Tgstation.Server.Host/Components/Interop/BridgeRegistration.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Bridge/BridgeRegistration.cs @@ -1,6 +1,6 @@ using System; -namespace Tgstation.Server.Host.Components.Interop +namespace Tgstation.Server.Host.Components.Interop.Bridge { /// sealed class BridgeRegistration : IBridgeRegistration diff --git a/src/Tgstation.Server.Host/Components/Interop/IBridgeDispatcher.cs b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeDispatcher.cs similarity index 87% rename from src/Tgstation.Server.Host/Components/Interop/IBridgeDispatcher.cs rename to src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeDispatcher.cs index 7e9b8c9a8b..218830576f 100644 --- a/src/Tgstation.Server.Host/Components/Interop/IBridgeDispatcher.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeDispatcher.cs @@ -1,8 +1,7 @@ using System.Threading; using System.Threading.Tasks; -using Tgstation.Server.Host.Components.Interop.Bridge; -namespace Tgstation.Server.Host.Components.Interop +namespace Tgstation.Server.Host.Components.Interop.Bridge { /// /// Handler for . diff --git a/src/Tgstation.Server.Host/Components/Interop/IBridgeHandler.cs b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeHandler.cs similarity index 92% rename from src/Tgstation.Server.Host/Components/Interop/IBridgeHandler.cs rename to src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeHandler.cs index dc1278fe60..5ca5347e3d 100644 --- a/src/Tgstation.Server.Host/Components/Interop/IBridgeHandler.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeHandler.cs @@ -1,7 +1,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Components.Interop +namespace Tgstation.Server.Host.Components.Interop.Bridge { /// interface IBridgeHandler : IBridgeDispatcher diff --git a/src/Tgstation.Server.Host/Components/Interop/IBridgeRegistrar.cs b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeRegistrar.cs similarity index 87% rename from src/Tgstation.Server.Host/Components/Interop/IBridgeRegistrar.cs rename to src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeRegistrar.cs index 23a98465ba..c1e071d84f 100644 --- a/src/Tgstation.Server.Host/Components/Interop/IBridgeRegistrar.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeRegistrar.cs @@ -1,4 +1,4 @@ -namespace Tgstation.Server.Host.Components.Interop +namespace Tgstation.Server.Host.Components.Interop.Bridge { /// /// Registers s. diff --git a/src/Tgstation.Server.Host/Components/Interop/IBridgeRegistration.cs b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeRegistration.cs similarity index 72% rename from src/Tgstation.Server.Host/Components/Interop/IBridgeRegistration.cs rename to src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeRegistration.cs index 2d211214e5..12c6611e82 100644 --- a/src/Tgstation.Server.Host/Components/Interop/IBridgeRegistration.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Bridge/IBridgeRegistration.cs @@ -1,6 +1,6 @@ using System; -namespace Tgstation.Server.Host.Components.Interop +namespace Tgstation.Server.Host.Components.Interop.Bridge { /// /// Represents a registration of an interop session. diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 9332353c0b..bc51e04c77 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -25,7 +25,7 @@ using Tgstation.Server.Host.Components; using Tgstation.Server.Host.Components.Byond; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Chat.Providers; -using Tgstation.Server.Host.Components.Interop; +using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Components.Interop.Converters; using Tgstation.Server.Host.Components.Repository; using Tgstation.Server.Host.Components.Watchdog; From c0750271500a8e320101ec0c5c4fec9e8f78ea2c Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 18 May 2020 10:53:30 -0400 Subject: [PATCH 4/7] Send new server version and port in one topic message - Move reattach SendCommand call out of Watchdog into existing SessionController call. - DMAPI 5.2.0, send back custom commands on reattach and accept NewPort - Remove IAssemblyInformationProvider from watchdogs AGAIN - Deprecate TopicCommandType 6 --- src/DMAPI/tgs.dm | 2 +- src/DMAPI/tgs/v5/_defines.dm | 3 +- src/DMAPI/tgs/v5/api.dm | 28 +++++++++++++------ src/DMAPI/tgs/v5/undef.dm | 3 +- .../Components/Interop/DMApiConstants.cs | 2 +- .../Interop/Topic/TopicCommandType.cs | 5 +++- .../Interop/Topic/TopicParameters.cs | 9 +++--- .../Components/Interop/Topic/TopicResponse.cs | 6 ++++ .../Components/Session/SessionController.cs | 18 +++++++++--- .../Session/SessionControllerFactory.cs | 2 ++ .../Components/Watchdog/BasicWatchdog.cs | 4 --- .../Watchdog/ExperimentalWatchdog.cs | 4 --- .../Components/Watchdog/WatchdogBase.cs | 17 ----------- .../Components/Watchdog/WatchdogFactory.cs | 11 -------- .../Components/Watchdog/WindowsWatchdog.cs | 4 --- .../Watchdog/WindowsWatchdogFactory.cs | 5 ---- 16 files changed, 56 insertions(+), 67 deletions(-) diff --git a/src/DMAPI/tgs.dm b/src/DMAPI/tgs.dm index e164a4ec96..0dd4f81cf0 100644 --- a/src/DMAPI/tgs.dm +++ b/src/DMAPI/tgs.dm @@ -1,6 +1,6 @@ //tgstation-server DMAPI -#define TGS_DMAPI_VERSION "5.1.1" +#define TGS_DMAPI_VERSION "5.2.0" //All functions and datums outside this document are subject to change with any version and should not be relied on diff --git a/src/DMAPI/tgs/v5/_defines.dm b/src/DMAPI/tgs/v5/_defines.dm index 2baf3e12d7..d35818661a 100644 --- a/src/DMAPI/tgs/v5/_defines.dm +++ b/src/DMAPI/tgs/v5/_defines.dm @@ -12,13 +12,14 @@ #define DMAPI5_BRIDGE_COMMAND_CHAT_SEND 5 #define DMAPI5_PARAMETER_ACCESS_IDENTIFIER "accessIdentifier" +#define DMAPI5_PARAMETER_CUSTOM_COMMANDS "customCommands" + #define DMAPI5_RESPONSE_ERROR_MESSAGE "errorMessage" #define DMAPI5_BRIDGE_PARAMETER_COMMAND_TYPE "commandType" #define DMAPI5_BRIDGE_PARAMETER_CURRENT_PORT "currentPort" #define DMAPI5_BRIDGE_PARAMETER_VERSION "version" #define DMAPI5_BRIDGE_PARAMETER_CHAT_MESSAGE "chatMessage" -#define DMAPI5_BRIDGE_PARAMETER_CUSTOM_COMMANDS "customCommands" #define DMAPI5_BRIDGE_PARAMETER_MINIMUM_SECURITY_LEVEL "minimumSecurityLevel" #define DMAPI5_BRIDGE_RESPONSE_NEW_PORT "newPort" diff --git a/src/DMAPI/tgs/v5/api.dm b/src/DMAPI/tgs/v5/api.dm index eedefb2877..6ec26fde5b 100644 --- a/src/DMAPI/tgs/v5/api.dm +++ b/src/DMAPI/tgs/v5/api.dm @@ -16,7 +16,7 @@ var/list/chat_channels /datum/tgs_api/v5/ApiVersion() - return new /datum/tgs_version("5.1.1") + return new /datum/tgs_version("5.2.0") /datum/tgs_api/v5/OnWorldNew(minimum_required_security_level) server_port = world.params[DMAPI5_PARAM_SERVER_PORT] @@ -24,7 +24,7 @@ var/datum/tgs_version/api_version = ApiVersion() version = null - var/list/bridge_response = Bridge(DMAPI5_BRIDGE_COMMAND_STARTUP, list(DMAPI5_BRIDGE_PARAMETER_MINIMUM_SECURITY_LEVEL = minimum_required_security_level, DMAPI5_BRIDGE_PARAMETER_VERSION = api_version.raw_parameter, DMAPI5_BRIDGE_PARAMETER_CUSTOM_COMMANDS = ListCustomCommands())) + var/list/bridge_response = Bridge(DMAPI5_BRIDGE_COMMAND_STARTUP, list(DMAPI5_BRIDGE_PARAMETER_MINIMUM_SECURITY_LEVEL = minimum_required_security_level, DMAPI5_BRIDGE_PARAMETER_VERSION = api_version.raw_parameter, DMAPI5_PARAMETER_CUSTOM_COMMANDS = ListCustomCommands())) if(!istype(bridge_response)) TGS_ERROR_LOG("Failed initial bridge request!") return FALSE @@ -201,17 +201,27 @@ if(DMAPI5_TOPIC_COMMAND_HEARTBEAT) return TopicResponse() if(DMAPI5_TOPIC_COMMAND_WATCHDOG_REATTACH) + var/new_port = topic_parameters[DMAPI5_TOPIC_PARAMETER_NEW_PORT] + var/error_message = null + if (new_port != null) + if (!isnum(new_port) || !(new_port > 0)) + error_message = "Invalid [DMAPI5_TOPIC_PARAMETER_NEW_PORT]]" + else + server_port = new_port + var/new_version_string = topic_parameters[DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION] if (!istext(new_version_string)) - return TopicResponse("Invalid or missing [DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION]]") + if(error_message != null) + error_message += ", " + error_message += "Invalid or missing [DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION]]" + else + var/datum/tgs_version/new_version = new(new_version_string) + if (event_handler) + event_handler.HandleEvent(TGS_EVENT_WATCHDOG_REATTACH, new_version) - var/datum/tgs_version/new_version = new(new_version_string) - if (event_handler) - event_handler.HandleEvent(TGS_EVENT_WATCHDOG_REATTACH, new_version) + version = new_version - version = new_version - - return TopicResponse() + return json_encode(list(DMAPI5_RESPONSE_ERROR_MESSAGE = error_message, DMAPI5_PARAMETER_CUSTOM_COMMANDS = ListCustomCommands())) return TopicResponse("Unknown command: [command]") diff --git a/src/DMAPI/tgs/v5/undef.dm b/src/DMAPI/tgs/v5/undef.dm index b27e3abe95..74404cd495 100644 --- a/src/DMAPI/tgs/v5/undef.dm +++ b/src/DMAPI/tgs/v5/undef.dm @@ -12,13 +12,14 @@ #undef DMAPI5_BRIDGE_COMMAND_CHAT_SEND #undef DMAPI5_PARAMETER_ACCESS_IDENTIFIER +#undef DMAPI5_PARAMETER_CUSTOM_COMMANDS + #undef DMAPI5_RESPONSE_ERROR_MESSAGE #undef DMAPI5_BRIDGE_PARAMETER_COMMAND_TYPE #undef DMAPI5_BRIDGE_PARAMETER_CURRENT_PORT #undef DMAPI5_BRIDGE_PARAMETER_VERSION #undef DMAPI5_BRIDGE_PARAMETER_CHAT_MESSAGE -#undef DMAPI5_BRIDGE_PARAMETER_CUSTOM_COMMANDS #undef DMAPI5_BRIDGE_PARAMETER_MINIMUM_SECURITY_LEVEL #undef DMAPI5_BRIDGE_RESPONSE_NEW_PORT diff --git a/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs b/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs index f7f4820dc7..69b8ca7fec 100644 --- a/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs +++ b/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs @@ -33,7 +33,7 @@ namespace Tgstation.Server.Host.Components.Interop /// /// The DMAPI being used. /// - public static readonly Version Version = new Version(5, 1, 1); + public static readonly Version Version = new Version(5, 2, 0); /// /// for use when communicating with the DMAPI. diff --git a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicCommandType.cs b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicCommandType.cs index aa465f98ac..ca8a5e603e 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicCommandType.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicCommandType.cs @@ -1,4 +1,6 @@ -namespace Tgstation.Server.Host.Components.Interop.Topic +using System; + +namespace Tgstation.Server.Host.Components.Interop.Topic { /// /// The type of topic command being sent. @@ -38,6 +40,7 @@ /// /// The server's port was possibly changed. /// + [Obsolete("Deprecated", true)] ServerPortUpdate, /// diff --git a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs index 241c85615c..cab487c410 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs @@ -82,9 +82,8 @@ namespace Tgstation.Server.Host.Components.Interop.Topic /// Initializes a new instance of the . /// /// The value of . - /// If this is for a . - public TopicParameters(ushort newPort, bool forServer) - : this(forServer ? TopicCommandType.ServerPortUpdate : TopicCommandType.ChangePort) + public TopicParameters(ushort newPort) + : this(TopicCommandType.ChangePort) { NewPort = newPort; } @@ -123,10 +122,12 @@ namespace Tgstation.Server.Host.Components.Interop.Topic /// Initializes a new instance of the . /// /// The value of . - public TopicParameters(Version newServerVersion) + /// TGS's new API port. + public TopicParameters(Version newServerVersion, ushort serverPort) : this(TopicCommandType.ServerRestarted) { NewServerVersion = newServerVersion ?? throw new ArgumentNullException(nameof(newServerVersion)); + NewPort = serverPort; } /// diff --git a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicResponse.cs b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicResponse.cs index e0a397fae3..2a689698f7 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicResponse.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicResponse.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Tgstation.Server.Host.Components.Chat.Commands; namespace Tgstation.Server.Host.Components.Interop.Topic { @@ -16,5 +17,10 @@ namespace Tgstation.Server.Host.Components.Interop.Topic /// The s to send as the result of a request, if any. /// public ICollection ChatResponses { get; set; } + + /// + /// The DMAPI s for requests. + /// + public ICollection CustomCommands { get; set; } } } diff --git a/src/Tgstation.Server.Host/Components/Session/SessionController.cs b/src/Tgstation.Server.Host/Components/Session/SessionController.cs index 0e8e1736bf..414280cb11 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionController.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; +using Tgstation.Server.Api; using Tgstation.Server.Api.Models; using Tgstation.Server.Host.Components.Byond; using Tgstation.Server.Host.Components.Chat; @@ -194,6 +195,7 @@ namespace Tgstation.Server.Host.Components.Session /// The used to populate . /// The value of /// The value of + /// The for the . /// The value of /// The optional time to wait before failing the /// If this is a reattached session. @@ -205,6 +207,7 @@ namespace Tgstation.Server.Host.Components.Session IChatTrackingContext chatTrackingContext, IBridgeRegistrar bridgeRegistrar, IChatManager chat, + IAssemblyInformationProvider assemblyInformationProvider, ILogger logger, uint? startupTimeout, bool reattached) @@ -263,12 +266,19 @@ namespace Tgstation.Server.Host.Components.Session using (cts = new CancellationTokenSource()) try { - await SendCommand( + var reattachResponse = await SendCommand( new TopicParameters( - reattachInformation.RuntimeInformation.ServerPort, - true), + assemblyInformationProvider.Version, + reattachInformation.RuntimeInformation.ServerPort), cts.Token) .ConfigureAwait(false); + + if (reattachResponse.InteropResponse?.CustomCommands != null) + this.chatTrackingContext.CustomCommands = reattachResponse.InteropResponse.CustomCommands.ToList(); + else if (reattachResponse.InteropResponse != null) + logger.LogWarning( + "DMAPI v{0} isn't returning the TGS custom commands list. Functionality added in v5.2.0.", + Dmb.CompileJob.DMApiVersion.Semver()); } finally { @@ -585,7 +595,7 @@ namespace Tgstation.Server.Host.Components.Session async Task ImmediateTopicPortChange() { var commandResult = await SendCommand( - new TopicParameters(port, false), + new TopicParameters(port), cancellationToken) .ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs index be732f40f8..e5d61c60d1 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs @@ -289,6 +289,7 @@ namespace Tgstation.Server.Host.Components.Session chatTrackingContext, bridgeRegistrar, chat, + assemblyInformationProvider, loggerFactory.CreateLogger(), launchParameters.StartupTimeout, false); @@ -353,6 +354,7 @@ namespace Tgstation.Server.Host.Components.Session chatTrackingContext, bridgeRegistrar, chat, + assemblyInformationProvider, loggerFactory.CreateLogger(), null, true); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs index 2f7bd8980a..543800cc5d 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/BasicWatchdog.cs @@ -11,7 +11,6 @@ using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Jobs; -using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Components.Watchdog { @@ -50,7 +49,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the . /// The for the . /// The for the . - /// The for the . /// The for the . /// The for the . /// The for the . @@ -64,7 +62,6 @@ namespace Tgstation.Server.Host.Components.Watchdog IJobManager jobManager, IServerControl serverControl, IAsyncDelayer asyncDelayer, - IAssemblyInformationProvider assemblyInformationProvider, ILogger logger, DreamDaemonLaunchParameters initialLaunchParameters, Api.Models.Instance instance, @@ -78,7 +75,6 @@ namespace Tgstation.Server.Host.Components.Watchdog jobManager, serverControl, asyncDelayer, - assemblyInformationProvider, logger, initialLaunchParameters, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs index 047b069b7b..02daf7d157 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ExperimentalWatchdog.cs @@ -12,7 +12,6 @@ using Tgstation.Server.Host.Components.Session; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Jobs; -using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Components.Watchdog { @@ -61,7 +60,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the . /// The for the . /// The for the . - /// The for the . /// The for the . /// The for the . /// The for the . @@ -75,7 +73,6 @@ namespace Tgstation.Server.Host.Components.Watchdog IJobManager jobManager, IServerControl serverControl, IAsyncDelayer asyncDelayer, - IAssemblyInformationProvider assemblyInformationProvider, ILogger logger, DreamDaemonLaunchParameters initialLaunchParameters, Api.Models.Instance instance, bool autoStart) @@ -88,7 +85,6 @@ namespace Tgstation.Server.Host.Components.Watchdog jobManager, serverControl, asyncDelayer, - assemblyInformationProvider, logger, initialLaunchParameters, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs index 3f026305ce..ecfd994cd4 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs @@ -17,7 +17,6 @@ using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Extensions; using Tgstation.Server.Host.Jobs; -using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Components.Watchdog { @@ -113,11 +112,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// readonly IRestartRegistration restartRegistration; - /// - /// The for the . - /// - readonly IAssemblyInformationProvider assemblyInformationProvider; - /// /// If the should in /// @@ -164,7 +158,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The value of /// The to populate with /// The value of . - /// The value of /// The value of /// The initial value of . May be modified /// The value of @@ -178,7 +171,6 @@ namespace Tgstation.Server.Host.Components.Watchdog IJobManager jobManager, IServerControl serverControl, IAsyncDelayer asyncDelayer, - IAssemblyInformationProvider assemblyInformationProvider, ILogger logger, DreamDaemonLaunchParameters initialLaunchParameters, Api.Models.Instance instance, @@ -191,7 +183,6 @@ namespace Tgstation.Server.Host.Components.Watchdog this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory)); this.jobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager)); AsyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); - this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); ActiveLaunchParameters = initialLaunchParameters ?? throw new ArgumentNullException(nameof(initialLaunchParameters)); this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); @@ -870,14 +861,6 @@ namespace Tgstation.Server.Host.Components.Watchdog { using (await SemaphoreSlimContext.Lock(Semaphore, ct).ConfigureAwait(false)) await LaunchImplNoLock(true, true, reattachInfo, ct).ConfigureAwait(false); - - if (!Running) - return; - var server = GetActiveController(); - if (server == null) - return; - - await server.SendCommand(new TopicParameters(assemblyInformationProvider.Version), cancellationToken).ConfigureAwait(false); }, cancellationToken).ConfigureAwait(false); } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs index a312c958de..7f5f08e88e 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogFactory.cs @@ -10,7 +10,6 @@ using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; -using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Components.Watchdog { @@ -42,11 +41,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// protected IAsyncDelayer AsyncDelayer { get; } - /// - /// The for the - /// - protected IAssemblyInformationProvider AssemblyInformationProvider { get; } - /// /// The for the /// @@ -60,7 +54,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The value of /// The value of /// The value of - /// The value of . /// The containing the value of public WatchdogFactory( IServerControl serverControl, @@ -68,7 +61,6 @@ namespace Tgstation.Server.Host.Components.Watchdog IDatabaseContextFactory databaseContextFactory, IJobManager jobManager, IAsyncDelayer asyncDelayer, - IAssemblyInformationProvider assemblyInformationProvider, IOptions generalConfigurationOptions) { ServerControl = serverControl ?? throw new ArgumentNullException(nameof(serverControl)); @@ -76,7 +68,6 @@ namespace Tgstation.Server.Host.Components.Watchdog DatabaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory)); JobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager)); AsyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); - AssemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider)); GeneralConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); } @@ -100,7 +91,6 @@ namespace Tgstation.Server.Host.Components.Watchdog JobManager, ServerControl, AsyncDelayer, - AssemblyInformationProvider, LoggerFactory.CreateLogger(), settings, instance, @@ -137,7 +127,6 @@ namespace Tgstation.Server.Host.Components.Watchdog JobManager, ServerControl, AsyncDelayer, - AssemblyInformationProvider, LoggerFactory.CreateLogger(), settings, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs index dd7e9908f0..895347f4a6 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdog.cs @@ -10,7 +10,6 @@ using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; -using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Components.Watchdog { @@ -54,7 +53,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the . /// The for the . /// The for the . - /// The for the . /// The for the . /// The value of . /// The value of . @@ -71,7 +69,6 @@ namespace Tgstation.Server.Host.Components.Watchdog IJobManager jobManager, IServerControl serverControl, IAsyncDelayer asyncDelayer, - IAssemblyInformationProvider assemblyInformationProvider, IIOManager ioManager, ISymlinkFactory symlinkFactory, ILogger logger, @@ -86,7 +83,6 @@ namespace Tgstation.Server.Host.Components.Watchdog jobManager, serverControl, asyncDelayer, - assemblyInformationProvider, logger, initialLaunchParameters, instance, diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs index e253eb5bd6..2d8273386d 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WindowsWatchdogFactory.cs @@ -10,7 +10,6 @@ using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; -using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Components.Watchdog { @@ -32,7 +31,6 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the . /// The for the . /// The for the . - /// The for the . /// The value of . /// The for for the . public WindowsWatchdogFactory( @@ -41,7 +39,6 @@ namespace Tgstation.Server.Host.Components.Watchdog IDatabaseContextFactory databaseContextFactory, IJobManager jobManager, IAsyncDelayer asyncDelayer, - IAssemblyInformationProvider assemblyInformationProvider, ISymlinkFactory symlinkFactory, IOptions generalConfigurationOptions) : base( @@ -50,7 +47,6 @@ namespace Tgstation.Server.Host.Components.Watchdog databaseContextFactory, jobManager, asyncDelayer, - assemblyInformationProvider, generalConfigurationOptions) { this.symlinkFactory = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory)); @@ -74,7 +70,6 @@ namespace Tgstation.Server.Host.Components.Watchdog JobManager, ServerControl, AsyncDelayer, - AssemblyInformationProvider, ioManager, symlinkFactory, LoggerFactory.CreateLogger(), From a37dae4fc3fb815b330657a4ad1556a970ef964a Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 18 May 2020 10:58:50 -0400 Subject: [PATCH 5/7] Minor log line --- .../Components/Chat/ChatTrackingContext.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs b/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs index 4663724586..6845e84a87 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs @@ -29,13 +29,17 @@ namespace Tgstation.Server.Host.Components.Chat public IEnumerable CustomCommands { get => customCommands; - set => customCommands = (value ?? throw new InvalidOperationException("value cannot be null!")) + set + { + customCommands = (value ?? throw new InvalidOperationException("value cannot be null!")) .Select(customCommand => { customCommand.SetHandler(customCommandHandler); return customCommand; }) .ToList(); + logger.LogTrace("Custom commands set."); + } } /// From 8fb3d8e8a6ccc9e6ad50a9d905deaf31faedbba5 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 18 May 2020 12:22:40 -0400 Subject: [PATCH 6/7] Fix warnings --- .../Components/Session/SessionController.cs | 106 +++++++++--------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Session/SessionController.cs b/src/Tgstation.Server.Host/Components/Session/SessionController.cs index 414280cb11..19b5b7b06c 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionController.cs @@ -234,62 +234,21 @@ namespace Tgstation.Server.Host.Components.Session synchronizationLock = new object(); CancellationTokenSource cts = null; - Task lifetimeContinuation = null; - lifetimeContinuation = process.Lifetime.ContinueWith( + _ = process.Lifetime.ContinueWith( x => { - lock (lifetimeContinuation) - cts?.Cancel(); + cts?.Cancel(); chatTrackingContext.Active = false; }, TaskScheduler.Current); - async Task GetLaunchResult() - { - var startTime = DateTimeOffset.Now; - Task toAwait = process.Startup; - - if (startupTimeout.HasValue) - toAwait = Task.WhenAny(process.Startup, Task.Delay(startTime.AddSeconds(startupTimeout.Value) - startTime)); - - await toAwait.ConfigureAwait(false); - - var result = new LaunchResult - { - ExitCode = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null, - StartupTime = process.Startup.IsCompleted ? (TimeSpan?)(DateTimeOffset.Now - startTime) : null - }; - - logger.LogTrace("Launch result: {0}", result); - - if (!result.ExitCode.HasValue && reattached) - using (cts = new CancellationTokenSource()) - try - { - var reattachResponse = await SendCommand( - new TopicParameters( - assemblyInformationProvider.Version, - reattachInformation.RuntimeInformation.ServerPort), - cts.Token) - .ConfigureAwait(false); - - if (reattachResponse.InteropResponse?.CustomCommands != null) - this.chatTrackingContext.CustomCommands = reattachResponse.InteropResponse.CustomCommands.ToList(); - else if (reattachResponse.InteropResponse != null) - logger.LogWarning( - "DMAPI v{0} isn't returning the TGS custom commands list. Functionality added in v5.2.0.", - Dmb.CompileJob.DMApiVersion.Semver()); - } - finally - { - lock (lifetimeContinuation) - cts = null; - } - - return result; - } - - LaunchResult = GetLaunchResult(); + LaunchResult = GetLaunchResult( + assemblyInformationProvider, +#pragma warning disable CA2000 // Dispose objects before losing scope + cts = new CancellationTokenSource(), +#pragma warning restore CA2000 // Dispose objects before losing scope + startupTimeout, + reattached); logger.LogDebug("Created session controller. Primary: {0}, CommsKey: {1}, Port: {2}", IsPrimary, reattachInformation.AccessIdentifier, Port); } @@ -346,6 +305,51 @@ namespace Tgstation.Server.Host.Components.Session } } + async Task GetLaunchResult( + IAssemblyInformationProvider assemblyInformationProvider, + CancellationTokenSource cancellationTokenSource, + uint? startupTimeout, + bool reattached) + { + using (cancellationTokenSource) + { + var startTime = DateTimeOffset.Now; + Task toAwait = process.Startup; + + if (startupTimeout.HasValue) + toAwait = Task.WhenAny(process.Startup, Task.Delay(startTime.AddSeconds(startupTimeout.Value) - startTime)); + + await toAwait.ConfigureAwait(false); + + var result = new LaunchResult + { + ExitCode = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null, + StartupTime = process.Startup.IsCompleted ? (TimeSpan?)(DateTimeOffset.Now - startTime) : null + }; + + logger.LogTrace("Launch result: {0}", result); + + if (!result.ExitCode.HasValue && reattached) + { + var reattachResponse = await SendCommand( + new TopicParameters( + assemblyInformationProvider.Version, + reattachInformation.RuntimeInformation.ServerPort), + cancellationTokenSource.Token) + .ConfigureAwait(false); + + if (reattachResponse.InteropResponse?.CustomCommands != null) + chatTrackingContext.CustomCommands = reattachResponse.InteropResponse.CustomCommands; + else if (reattachResponse.InteropResponse != null) + logger.LogWarning( + "DMAPI v{0} isn't returning the TGS custom commands list. Functionality added in v5.2.0.", + Dmb.CompileJob.DMApiVersion.Semver()); + } + + return result; + } + } + /// public async Task ProcessBridgeRequest(BridgeParameters parameters, CancellationToken cancellationToken) { @@ -464,7 +468,7 @@ namespace Tgstation.Server.Host.Components.Session response.RuntimeInformation = reattachInformation.RuntimeInformation; // Load custom commands - chatTrackingContext.CustomCommands = parameters.CustomCommands.ToList(); + chatTrackingContext.CustomCommands = parameters.CustomCommands; break; case BridgeCommandType.Reboot: if (ClosePortOnReboot) From 3d70c346d2885b5560d2eb2fbfcebcf222377c80 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 18 May 2020 12:33:20 -0400 Subject: [PATCH 7/7] Return DMAPI version in ServerInformation, version bumps across the board --- build/Version.props | 8 ++++---- src/Tgstation.Server.Api/Models/ServerInformation.cs | 5 +++++ src/Tgstation.Server.Host/Controllers/HomeController.cs | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/build/Version.props b/build/Version.props index 11f29c9ea4..7454b8fd14 100644 --- a/build/Version.props +++ b/build/Version.props @@ -2,10 +2,10 @@ - 4.2.2 - 6.3.0 - 6.2.0 - 5.1.1 + 4.2.3 + 6.4.0 + 6.3.0 + 5.2.0 0.4.0 1.1.0 diff --git a/src/Tgstation.Server.Api/Models/ServerInformation.cs b/src/Tgstation.Server.Api/Models/ServerInformation.cs index 869b8d0889..081671e850 100644 --- a/src/Tgstation.Server.Api/Models/ServerInformation.cs +++ b/src/Tgstation.Server.Api/Models/ServerInformation.cs @@ -16,5 +16,10 @@ namespace Tgstation.Server.Api.Models /// The version of the host /// public Version ApiVersion { get; set; } + + /// + /// The DMAPI version of the host. + /// + public Version DMApiVersion { get; set; } } } diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index 4f08acb9d0..eff10e36d1 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -12,6 +12,7 @@ using System.Net.Mime; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api; +using Tgstation.Server.Host.Components.Interop; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; @@ -124,6 +125,7 @@ namespace Tgstation.Server.Host.Controllers { Version = assemblyInformationProvider.Version, ApiVersion = ApiHeaders.Version, + DMApiVersion = DMApiConstants.Version, MinimumPasswordLength = generalConfiguration.MinimumPasswordLength, InstanceLimit = generalConfiguration.InstanceLimit, UserLimit = generalConfiguration.UserLimit,