fixed load order

This commit is contained in:
Alex
2025-01-12 11:43:22 +00:00
parent 9d982459ac
commit 50d744e9d7
5 changed files with 28 additions and 15 deletions
+2 -1
View File
@@ -18,5 +18,6 @@ public enum ContextVariableType
/** Data returned from client request object from endLocalRaid() */
TRANSIT_INFO = 5,
APP_BUILDER = 6,
LOADED_MOD_ASSEMBLIES = 6
LOADED_MOD_ASSEMBLIES = 7,
WEB_APPLICATION = 8
}
+8 -8
View File
@@ -5,12 +5,12 @@ public static class OnLoadOrder
public const int Database = 0;
public const int PostDBModLoader = 1;
public const int HandbookCallbacks = 2;
public const int PresetCallbacks = 3;
public const int SaveCallbacks = 4;
public const int TraderCallbacks = 5;
public const int RagfairPriceService = 6;
public const int RagfairCallbacks = 7;
public const int ModCallbacks = 8;
public const int GameCallbacks = 9;
public const int HttpCallbacks = 10;
public const int HttpCallbacks = 3;
public const int PresetCallbacks = 4;
public const int SaveCallbacks = 5;
public const int TraderCallbacks = 6;
public const int RagfairPriceService = 7;
public const int RagfairCallbacks = 8;
public const int ModCallbacks = 9;
public const int GameCallbacks = 10;
}
+1 -1
View File
@@ -59,7 +59,7 @@ public class HttpServer
});
// app.UseEndpoints(endpointBuilder => { endpointBuilder.MapFallback(HandleFallback); });
started = true;
app.Run($"http://{httpConfig.Ip}:{httpConfig.Port}");
_applicationContext.AddValue(ContextVariableType.WEB_APPLICATION, app);
}
private Task HandleFallback(HttpContext context)
+5 -4
View File
@@ -1,3 +1,4 @@
using System.Diagnostics;
using Core.Annotations;
using Core.DI;
using Core.Models.Enums;
@@ -49,7 +50,7 @@ public class App
_coreConfig = configServer.GetConfig<CoreConfig>(ConfigTypes.CORE);
}
public async Task Load()
public async Task Run()
{
// execute onLoad callbacks
_logger.Info(_localisationService.GetText("executing_startup_callbacks"));
@@ -86,10 +87,10 @@ public class App
Console.WriteLine($"finish Onload: {onLoad.GetRoute()}");
}
var timer = new Timer(_ =>
new Timer(_ =>
{
Console.WriteLine($"Start OnUpdate");
update(_onUpdate);
Update(_onUpdate);
Console.WriteLine($"Finish OnUpdate");
},
@@ -98,7 +99,7 @@ public class App
TimeSpan.FromMilliseconds(5000));
}
protected async Task update(IEnumerable<OnUpdate> onUpdateComponents)
protected async Task Update(IEnumerable<OnUpdate> onUpdateComponents)
{
// If the server has failed to start, skip any update calls
if (!_httpServer.IsStarted() || !_databaseService.IsDatabaseValid()) return;
+12 -1
View File
@@ -1,6 +1,10 @@
using System.Reflection;
using System.Security.Cryptography;
using Core.Annotations;
using Core.Context;
using Core.Models.Enums;
using Core.Models.Spt.Config;
using Core.Servers;
using Core.Utils;
namespace Server;
@@ -24,9 +28,16 @@ public static class Program
// TODO: var preSptModLoader = serviceProvider.GetService<PreSptModLoader>();
var app = serviceProvider.GetService<App>();
var appContext = serviceProvider.GetService<ApplicationContext>();
// These are the mod assemblies we are gonna use on the PreSpt, PostDb and PostSpt loaders
appContext.AddValue(ContextVariableType.LOADED_MOD_ASSEMBLIES, assemblies);
// This is the builder that will get use by the HttpServer to start up the web application
appContext.AddValue(ContextVariableType.APP_BUILDER, builder);
app.Load().Wait();
app.Run().Wait();
var httpConfig = serviceProvider.GetService<ConfigServer>().GetConfig<HttpConfig>(ConfigTypes.HTTP);
// When we application gets started by the HttpServer it will add into the AppContext the WebApplication
// object, which we can use here to start the webapp.
(appContext.GetLatestValue(ContextVariableType.WEB_APPLICATION).Value as WebApplication).Run($"http://{httpConfig.Ip}:{httpConfig.Port}");
}
catch (Exception ex)
{