- tweak: Big refactoring of hub and file content overview
This commit is contained in:
@@ -24,13 +24,6 @@ public static class CurrentConVar
|
||||
public static readonly ConVar<string> RobustAssemblyName =
|
||||
ConVarBuilder.Build("engine.robustAssemblyName", "Robust.Client");
|
||||
|
||||
public static readonly ConVar<string[][]> Hub = ConVarBuilder.Build<string[][]>("launcher.hub", [
|
||||
[
|
||||
"https://hub.spacestation14.com/api/servers",
|
||||
"https://auth.fallback.spacestation14.com/"
|
||||
]
|
||||
]);
|
||||
|
||||
public static readonly ConVar<Dictionary<string, EngineVersionInfo>> EngineManifestBackup =
|
||||
ConVarBuilder.Build<Dictionary<string, EngineVersionInfo>>("engine.manifest.backup");
|
||||
public static readonly ConVar<ModulesInfo> ModuleManifestBackup =
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace Nebula.Shared.Models;
|
||||
|
||||
public record ListItemTemplate(Type ModelType, string IconKey, string Label, object? args);
|
||||
@@ -12,22 +12,32 @@ public static class ServiceExt
|
||||
|
||||
public static void AddServices(this IServiceCollection services, Assembly assembly)
|
||||
{
|
||||
foreach (var (type, inference) in GetServicesWithHelpAttribute(assembly))
|
||||
foreach (var (type, inference, isSingleton) in GetServicesWithHelpAttribute(assembly))
|
||||
{
|
||||
Console.WriteLine("[ServiceMng] ADD SERVICE " + type);
|
||||
if (inference is null)
|
||||
services.AddSingleton(type);
|
||||
if (isSingleton)
|
||||
{
|
||||
if (inference is null)
|
||||
services.AddSingleton(type);
|
||||
else
|
||||
services.AddSingleton(inference, type);
|
||||
}
|
||||
else
|
||||
services.AddSingleton(inference, type);
|
||||
{
|
||||
if (inference is null)
|
||||
services.AddTransient(type);
|
||||
else
|
||||
services.AddTransient(inference, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<(Type, Type?)> GetServicesWithHelpAttribute(Assembly assembly)
|
||||
private static IEnumerable<(Type, Type?, bool)> GetServicesWithHelpAttribute(Assembly assembly)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
var attr = type.GetCustomAttribute<ServiceRegisterAttribute>();
|
||||
if (attr is not null) yield return (type, attr.Inference);
|
||||
if (attr is not null) yield return (type, attr.Inference, attr.IsSingleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
|
||||
namespace Nebula.Shared.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public class HubService
|
||||
{
|
||||
private readonly ConfigurationService _configurationService;
|
||||
private readonly RestService _restService;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly List<ServerHubInfo> _serverList = new();
|
||||
|
||||
public Action<HubServerChangedEventArgs>? HubServerChangedEventArgs;
|
||||
public Action? HubServerLoaded;
|
||||
public Action<Exception>? HubServerLoadingError;
|
||||
|
||||
public HubService(ConfigurationService configurationService, RestService restService, DebugService debugService)
|
||||
{
|
||||
_configurationService = configurationService;
|
||||
_restService = restService;
|
||||
_logger = debugService.GetLogger(this);
|
||||
|
||||
UpdateHub();
|
||||
}
|
||||
|
||||
public IReadOnlyList<ServerHubInfo> ServerList => _serverList;
|
||||
public bool IsUpdating { get; private set; }
|
||||
|
||||
public async void UpdateHub()
|
||||
{
|
||||
if (IsUpdating) return;
|
||||
|
||||
_serverList.Clear();
|
||||
|
||||
IsUpdating = true;
|
||||
|
||||
HubServerChangedEventArgs?.Invoke(new HubServerChangedEventArgs([], HubServerChangeAction.Clear));
|
||||
|
||||
foreach (var urlStr in _configurationService.GetConfigValue(CurrentConVar.Hub)!)
|
||||
{
|
||||
var invoked = false;
|
||||
Exception? exception = null;
|
||||
foreach (var uri in urlStr)
|
||||
{
|
||||
try
|
||||
{
|
||||
var servers =
|
||||
await _restService.GetAsync<List<ServerHubInfo>>(new Uri(uri), CancellationToken.None);
|
||||
_serverList.AddRange(servers);
|
||||
HubServerChangedEventArgs?.Invoke(new HubServerChangedEventArgs(servers, HubServerChangeAction.Add));
|
||||
invoked = true;
|
||||
break;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error($"Failed to get servers for {uri}");
|
||||
_logger.Error(e);
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
if(exception is not null && !invoked)
|
||||
HubServerLoadingError?.Invoke(new Exception("No hub is available.", exception));
|
||||
}
|
||||
|
||||
IsUpdating = false;
|
||||
HubServerLoaded?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public class HubServerChangedEventArgs : EventArgs
|
||||
{
|
||||
public HubServerChangeAction Action;
|
||||
public List<ServerHubInfo> Items;
|
||||
|
||||
public HubServerChangedEventArgs(List<ServerHubInfo> items, HubServerChangeAction action)
|
||||
{
|
||||
Items = items;
|
||||
Action = action;
|
||||
}
|
||||
}
|
||||
|
||||
public enum HubServerChangeAction
|
||||
{
|
||||
Add,
|
||||
Remove,
|
||||
Clear
|
||||
}
|
||||
Reference in New Issue
Block a user