Cleanup AppContext
This commit is contained in:
@@ -4,14 +4,12 @@ using SPTarkov.Server.Core.DI;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
|
||||
namespace SPTarkov.Server.Core.Callbacks;
|
||||
|
||||
[Injectable(InjectionType.Singleton, TypePriority = OnLoadOrder.HttpCallbacks)]
|
||||
public class HttpCallbacks(HttpServer _httpServer, ApplicationContext _applicationContext) : IOnLoad
|
||||
public class HttpCallbacks(HttpServer _httpServer) : IOnLoad
|
||||
{
|
||||
public Task OnLoad()
|
||||
{
|
||||
_httpServer.Load(_applicationContext.GetLatestValue(ContextVariableType.APP_BUILDER)?.GetValue<WebApplicationBuilder>());
|
||||
_applicationContext.ClearValues(ContextVariableType.APP_BUILDER);
|
||||
_httpServer.Load();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,5 @@ public enum ContextVariableType
|
||||
|
||||
// Data returned from client request object from endLocalRaid()
|
||||
TRANSIT_INFO = 5,
|
||||
APP_BUILDER = 6,
|
||||
LOADED_MOD_ASSEMBLIES = 7,
|
||||
WEB_APPLICATION = 8,
|
||||
SERVICE_PROVIDER = 9
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace SPTarkov.Server.Core.Controllers;
|
||||
[Injectable]
|
||||
public class GameController(
|
||||
ISptLogger<GameController> _logger,
|
||||
IReadOnlyList<SptMod> _loadedMods,
|
||||
ConfigServer _configServer,
|
||||
DatabaseService _databaseService,
|
||||
TimeUtil _timeUtil,
|
||||
@@ -472,13 +473,8 @@ public class GameController(
|
||||
protected void SaveActiveModsToProfile(SptProfile fullProfile)
|
||||
{
|
||||
fullProfile.SptData!.Mods ??= [];
|
||||
var mods = _applicationContext?.GetLatestValue(ContextVariableType.LOADED_MOD_ASSEMBLIES)?.GetValue<List<SptMod>>();
|
||||
if (mods == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var mod in mods)
|
||||
foreach (var mod in _loadedMods)
|
||||
{
|
||||
if (
|
||||
fullProfile.SptData.Mods.Any(m =>
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace SPTarkov.Server.Core.Controllers;
|
||||
[Injectable]
|
||||
public class LauncherController(
|
||||
ISptLogger<LauncherController> _logger,
|
||||
IReadOnlyList<SptMod> _loadedMods,
|
||||
HashUtil _hashUtil,
|
||||
TimeUtil _timeUtil,
|
||||
RandomUtil _randomUtil,
|
||||
@@ -242,13 +243,7 @@ public class LauncherController(
|
||||
/// <returns>Dictionary of mod name and mod details</returns>
|
||||
public Dictionary<string, AbstractModMetadata> GetLoadedServerMods()
|
||||
{
|
||||
var mods = _applicationContext?.GetLatestValue(ContextVariableType.LOADED_MOD_ASSEMBLIES)?.GetValue<List<SptMod>>();
|
||||
if (mods == null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return mods.ToDictionary(sptMod => sptMod.ModMetadata?.Name ?? "UNKNOWN MOD", sptMod => sptMod.ModMetadata);
|
||||
return _loadedMods.ToDictionary(sptMod => sptMod.ModMetadata?.Name ?? "UNKNOWN MOD", sptMod => sptMod.ModMetadata);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace SPTarkov.Server.Core.Controllers;
|
||||
[Injectable]
|
||||
public class LauncherV2Controller(
|
||||
ISptLogger<LauncherV2Controller> _logger,
|
||||
IReadOnlyList<SptMod> _loadedMods,
|
||||
HashUtil _hashUtil,
|
||||
TimeUtil _timeUtil,
|
||||
RandomUtil _randomUtil,
|
||||
@@ -158,10 +159,9 @@ public class LauncherV2Controller(
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, AbstractModMetadata> LoadedMods()
|
||||
{
|
||||
var mods = _applicationContext?.GetLatestValue(ContextVariableType.LOADED_MOD_ASSEMBLIES).GetValue<List<SptMod>>();
|
||||
var result = new Dictionary<string, AbstractModMetadata>();
|
||||
|
||||
foreach (var sptMod in mods)
|
||||
foreach (var sptMod in _loadedMods)
|
||||
{
|
||||
result.Add(sptMod.ModMetadata.Name, sptMod.ModMetadata);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,11 @@ public class BackupService
|
||||
protected JsonUtil _jsonUtil;
|
||||
protected ISptLogger<BackupService> _logger;
|
||||
protected TimeUtil _timeUtil;
|
||||
protected IReadOnlyList<SptMod> _loadedMods;
|
||||
|
||||
public BackupService(
|
||||
ISptLogger<BackupService> logger,
|
||||
IReadOnlyList<SptMod> loadedMods,
|
||||
JsonUtil jsonUtil,
|
||||
TimeUtil timeUtil,
|
||||
ConfigServer configServer,
|
||||
@@ -39,6 +41,7 @@ public class BackupService
|
||||
_timeUtil = timeUtil;
|
||||
_fileUtil = fileUtil;
|
||||
_applicationContext = applicationContext;
|
||||
_loadedMods = loadedMods;
|
||||
|
||||
_activeServerMods = GetActiveServerMods();
|
||||
_backupConfig = configServer.GetConfig<BackupConfig>();
|
||||
@@ -306,15 +309,9 @@ public class BackupService
|
||||
/// <returns> A List of mod names. </returns>
|
||||
protected List<string> GetActiveServerMods()
|
||||
{
|
||||
var mods = _applicationContext?.GetLatestValue(ContextVariableType.LOADED_MOD_ASSEMBLIES)?.GetValue<List<SptMod>>();
|
||||
if (mods == null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
List<string> result = [];
|
||||
|
||||
foreach (var mod in mods)
|
||||
foreach (var mod in _loadedMods)
|
||||
{
|
||||
result.Add($"{mod.ModMetadata.Author} - {mod.ModMetadata.Version ?? ""}");
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ public static class Program
|
||||
}
|
||||
diHandler.InjectAll();
|
||||
|
||||
builder.Services.AddSingleton(builder);
|
||||
builder.Services.AddSingleton<IReadOnlyList<SptMod>>(loadedMods);
|
||||
var serviceProvider = builder.Services.BuildServiceProvider();
|
||||
var logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger("Server");
|
||||
|
||||
@@ -66,12 +68,6 @@ public static class Program
|
||||
}
|
||||
}
|
||||
|
||||
// Add the Loaded Mod Assemblies for later
|
||||
appContext?.AddValue(ContextVariableType.LOADED_MOD_ASSEMBLIES, loadedMods);
|
||||
|
||||
// This is the builder that will get use by the HttpServer to start up the web application
|
||||
appContext?.AddValue(ContextVariableType.APP_BUILDER, builder);
|
||||
|
||||
// Get the Built app and run it
|
||||
var app = serviceProvider.GetService<App>();
|
||||
app?.Run().Wait();
|
||||
|
||||
Reference in New Issue
Block a user