diff --git a/Libraries/Core/Controllers/LauncherController.cs b/Libraries/Core/Controllers/LauncherController.cs index 69de49bd..6a16a057 100644 --- a/Libraries/Core/Controllers/LauncherController.cs +++ b/Libraries/Core/Controllers/LauncherController.cs @@ -1,3 +1,4 @@ +using Core.Context; using Core.Helpers; using Core.Models.Eft.Common.Tables; using Core.Models.Eft.Launcher; @@ -25,7 +26,8 @@ public class LauncherController( ProfileHelper _profileHelper, DatabaseService _databaseService, LocalisationService _localisationService, - ConfigServer _configServer + ConfigServer _configServer, + ApplicationContext _applicationContext ) { protected CoreConfig _coreConfig = _configServer.GetConfig(); @@ -201,9 +203,15 @@ public class LauncherController( */ public Dictionary GetLoadedServerMods() { - _logger.Error("NOT IMPLEMENTED - _preSptModLoader GetLoadedServerMods()"); - return new Dictionary(); - // TODO => return this.preSptModLoader.getImportedModDetails(); + var mods = _applicationContext?.GetLatestValue(ContextVariableType.LOADED_MOD_ASSEMBLIES).GetValue>(); + var result = new Dictionary(); + + foreach (var sptMod in mods) + { + result.Add(sptMod.PackageJson.Name, sptMod.PackageJson); + } + + return result; } /** @@ -213,15 +221,42 @@ public class LauncherController( */ public List GetServerModsProfileUsed(string sessionId) { - // var profile = _profileHelper.GetFullProfile(sessionId); + var profile = _profileHelper.GetFullProfile(sessionId); - _logger.Error("NOT IMPLEMENTED - _preSptModLoader GetServerModsProfileUsed()"); - /* TODO => modding - if (profile?.spt?.mods) { - return this.preSptModLoader.GetProfileModsGroupedByModName(profile?.spt?.mods); + if (profile?.SptData?.Mods is not null) { + return getProfileModsGroupedByModName(profile?.SptData?.Mods); } - */ return []; } + + public List getProfileModsGroupedByModName(List profileMods) + { + // Group all mods used by profile by name + var modsGroupedByName = new Dictionary>(); + foreach (var mod in profileMods) { + if (!modsGroupedByName.ContainsKey(mod.Name)) { + modsGroupedByName[mod.Name] = []; + } + + modsGroupedByName[mod.Name].Add(mod); + } + + // Find the highest versioned mod and add to results array + var result = new List(); + foreach (var modName in modsGroupedByName) { + var modDatas = modsGroupedByName[modName.Key]; + var modVersions = modDatas.Select((x) => x.Version); + // var highestVersion = MaxSatisfying(modVersions, "*"); ?? TODO: Node used SemVer here + + var chosenVersion = modDatas.FirstOrDefault((x) => x.Name == modName.Key ); // && x.Version == highestVersion + if (chosenVersion is null) { + continue; + } + + result.Add(chosenVersion); + } + + return result; + } }