From 7b6f1eb9ad764b6dec2c0d6601a734fa3926d3bc Mon Sep 17 00:00:00 2001 From: clodanSPT Date: Sat, 19 Jul 2025 18:48:48 +0100 Subject: [PATCH] Added OnWebAppBuild load step (#489) * Fingers crossed this will fix the mod loading issue for configs * Renamed classes and documentation for clarity * Remove some extra traces of the old PreSptLoader * Renamed interface for clarity and updated docs * Re-introduced PreSptModLoad for now --------- Co-authored-by: Alex --- .../SPTarkov.Server.Core/DI/OnLoadOrder.cs | 11 ++++---- .../Loaders/OnWebAppBuildModLoader.cs | 27 +++++++++++++++++++ .../{PreSptModLoader.cs => PreSptModLoad.cs} | 5 +--- .../Models/External/IOnWebAppBuildModAsync.cs | 9 +++++++ .../Models/External/IPreSptLoadModAsync.cs | 18 ++----------- SPTarkov.Server/Program.cs | 6 ++--- 6 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 Libraries/SPTarkov.Server.Core/Loaders/OnWebAppBuildModLoader.cs rename Libraries/SPTarkov.Server.Core/Loaders/{PreSptModLoader.cs => PreSptModLoad.cs} (81%) create mode 100644 Libraries/SPTarkov.Server.Core/Models/External/IOnWebAppBuildModAsync.cs diff --git a/Libraries/SPTarkov.Server.Core/DI/OnLoadOrder.cs b/Libraries/SPTarkov.Server.Core/DI/OnLoadOrder.cs index c8b8f5e3..a35429dd 100644 --- a/Libraries/SPTarkov.Server.Core/DI/OnLoadOrder.cs +++ b/Libraries/SPTarkov.Server.Core/DI/OnLoadOrder.cs @@ -9,10 +9,9 @@ public static class OnLoadOrder public const int PostDBModLoader = 4000; public const int TraderRegistration = 5000; public const int HandbookCallbacks = 6000; - public const int HttpCallbacks = 7000; - public const int SaveCallbacks = 8000; - public const int TraderCallbacks = 9000; - public const int PresetCallbacks = 10000; - public const int RagfairCallbacks = 11000; - public const int PostSptModLoader = 12000; + public const int SaveCallbacks = 7000; + public const int TraderCallbacks = 8000; + public const int PresetCallbacks = 9000; + public const int RagfairCallbacks = 10000; + public const int PostSptModLoader = 11000; } diff --git a/Libraries/SPTarkov.Server.Core/Loaders/OnWebAppBuildModLoader.cs b/Libraries/SPTarkov.Server.Core/Loaders/OnWebAppBuildModLoader.cs new file mode 100644 index 00000000..9395761a --- /dev/null +++ b/Libraries/SPTarkov.Server.Core/Loaders/OnWebAppBuildModLoader.cs @@ -0,0 +1,27 @@ +using SPTarkov.DI.Annotations; +using SPTarkov.Server.Core.Models.External; +using SPTarkov.Server.Core.Models.Utils; +using SPTarkov.Server.Core.Utils; + +namespace SPTarkov.Server.Core.Loaders; + +[Injectable(InjectionType.Singleton)] +public class OnWebAppBuildModLoader( + ISptLogger _logger, + IEnumerable _onWebAppBuildMods +) +{ + public async Task OnLoad() + { + if (ProgramStatics.MODS()) + { + _logger.Info("Loading OnWebAppBuildMods..."); + foreach (var onWebAppBuildMod in _onWebAppBuildMods) + { + await onWebAppBuildMod.OnWebAppBuildAsync(); + } + + _logger.Info("Finished loading OnWebAppBuildMods..."); + } + } +} diff --git a/Libraries/SPTarkov.Server.Core/Loaders/PreSptModLoader.cs b/Libraries/SPTarkov.Server.Core/Loaders/PreSptModLoad.cs similarity index 81% rename from Libraries/SPTarkov.Server.Core/Loaders/PreSptModLoader.cs rename to Libraries/SPTarkov.Server.Core/Loaders/PreSptModLoad.cs index 2fda877f..59da33f2 100644 --- a/Libraries/SPTarkov.Server.Core/Loaders/PreSptModLoader.cs +++ b/Libraries/SPTarkov.Server.Core/Loaders/PreSptModLoad.cs @@ -1,4 +1,4 @@ -using SPTarkov.DI.Annotations; +using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.DI; using SPTarkov.Server.Core.Models.External; using SPTarkov.Server.Core.Models.Utils; @@ -6,9 +6,6 @@ using SPTarkov.Server.Core.Utils; namespace SPTarkov.Server.Core.Loaders; -[Obsolete( - "This mod loader is obsolete and will be removed in 4.1.0. See documentation in IPreSptLoadModAsync for more information." -)] [Injectable(InjectionType.Singleton, TypePriority = OnLoadOrder.PreSptModLoader)] public class PreSptModLoader( ISptLogger _logger, diff --git a/Libraries/SPTarkov.Server.Core/Models/External/IOnWebAppBuildModAsync.cs b/Libraries/SPTarkov.Server.Core/Models/External/IOnWebAppBuildModAsync.cs new file mode 100644 index 00000000..5605c460 --- /dev/null +++ b/Libraries/SPTarkov.Server.Core/Models/External/IOnWebAppBuildModAsync.cs @@ -0,0 +1,9 @@ +namespace SPTarkov.Server.Core.Models.External; + +/// +/// This class now runs the Kestrel server is being configured/built, making it the perfect spot to change server configurations. +/// +public interface IOnWebAppBuildModAsync +{ + Task OnWebAppBuildAsync(); +} diff --git a/Libraries/SPTarkov.Server.Core/Models/External/IPreSptLoadModAsync.cs b/Libraries/SPTarkov.Server.Core/Models/External/IPreSptLoadModAsync.cs index 3db35e77..183f5c96 100644 --- a/Libraries/SPTarkov.Server.Core/Models/External/IPreSptLoadModAsync.cs +++ b/Libraries/SPTarkov.Server.Core/Models/External/IPreSptLoadModAsync.cs @@ -1,22 +1,8 @@ -namespace SPTarkov.Server.Core.Models.External; +namespace SPTarkov.Server.Core.Models.External; /// -/// This interface used to be used in TS to load mods before SPT components loading. -/// This class is now deprecated and should not be used, see code example below for replacement. +/// Interface used to make changes before any of the SPT server logic runs. After the Watermark print, but before the Database loads /// -/// -/// [Injectable(TypePriority = OnLoadOrder.Watermark + 1)] -/// public class MyMod : IOnLoad -/// { -/// // ... implementation -/// } -/// -/// -/// DEPRECATED, see code example above for replacement! -/// -[Obsolete( - "This interface is obsolete and will be removed in 4.1.0, please use IOnLoad instead with the desired Injectable(TypePriority). See class documentation for examples." -)] public interface IPreSptLoadModAsync { Task PreSptLoadAsync(); diff --git a/SPTarkov.Server/Program.cs b/SPTarkov.Server/Program.cs index 3b9d4f4a..f66c7f99 100644 --- a/SPTarkov.Server/Program.cs +++ b/SPTarkov.Server/Program.cs @@ -121,9 +121,9 @@ public static class Program builder.WebHost.ConfigureKestrel( (_, options) => { - var httpConfig = options - .ApplicationServices.GetService() - ?.GetConfig()!; + // This method is not expected to be async so we need to wait for the Task instead of using await keyword + options.ApplicationServices.GetService()!.OnLoad().Wait(); + var httpConfig = options.ApplicationServices.GetService()?.GetConfig()!; var certHelper = options.ApplicationServices.GetService()!; options.Listen( IPAddress.Parse(httpConfig.Ip),