- add: fallbacks

This commit is contained in:
2025-05-03 18:20:24 +03:00
parent 207084c332
commit f0d46ee28d
6 changed files with 111 additions and 68 deletions

View File

@@ -14,8 +14,8 @@ public static class LauncherConVar
public static readonly ConVar<string[]> Favorites =
ConVarBuilder.Build<string[]>("server.favorites", []);
public static readonly ConVar<string[]> AuthServers = ConVarBuilder.Build<string[]>("launcher.authServers", [
"https://auth.spacestation14.com/"
public static readonly ConVar<AuthServerCredentials[]> AuthServers = ConVarBuilder.Build<AuthServerCredentials[]>("launcher.authServers", [
new AuthServerCredentials("WizDen", ["https://auth.spacestation14.com/", "https://auth.fallback.spacestation14.com/"])
]);
public static readonly ConVar<string> CurrentLang = ConVarBuilder.Build<string>("launcher.language", "en-US");

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.Json.Serialization;
@@ -40,23 +41,9 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } = default!;
public ObservableCollection<ProfileAuthCredentials> Accounts { get; } = new();
public ObservableCollection<string> AuthUrls { get; } = new();
public ObservableCollection<AuthServerCredentials> AuthUrls { get; } = new();
private AuthLoginPassword CurrentAlp
{
get => new(CurrentLogin, CurrentPassword, CurrentAuthServer);
set
{
CurrentLogin = value.Login;
CurrentPassword = value.Password;
CurrentAuthServer = value.AuthServer;
}
}
public string AuthItemSelect
{
set => CurrentAuthServer = value;
}
[ObservableProperty] private AuthServerCredentials _authItemSelect;
//Design think
protected override void InitialiseInDesignMode()
@@ -64,8 +51,7 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
AddAccount(new AuthLoginPassword("Binka", "12341", ""));
AddAccount(new AuthLoginPassword("Binka", "12341", ""));
AuthUrls.Add("https://cinka.ru");
AuthUrls.Add("https://cinka.ru");
AuthUrls.Add(new AuthServerCredentials("Test",["example.com"]));
}
//Real think
@@ -76,7 +62,10 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
public void AuthByProfile(ProfileAuthCredentials credentials)
{
CurrentAlp = new AuthLoginPassword(credentials.Login, credentials.Password, credentials.AuthServer);
CurrentLogin = credentials.Login;
CurrentPassword = credentials.Password;
CurrentAuthServer = credentials.AuthServer;
DoAuth();
}
@@ -87,18 +76,51 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
message.IsInfoClosable = false;
PopupMessageService.Popup(message);
var serverCandidates = new List<string>();
if (string.IsNullOrWhiteSpace(CurrentAuthServer))
serverCandidates.AddRange(AuthItemSelect.Servers);
else
serverCandidates.Add(CurrentAuthServer);
Task.Run(async () =>
{
Exception? exception = null;
foreach (var server in serverCandidates)
{
try
{
await AuthService.Auth(CurrentAlp, code);
await TryAuth(CurrentLogin, CurrentPassword, server,code);
break;
}
catch (Exception e)
{
exception = e;
}
}
message.Dispose();
if (!IsLogged)
{
PopupMessageService.Popup(new Exception("No one of auth server is available.", exception));
}
});
}
private async Task TryAuth(string login, string password, string authServer,string? code)
{
try
{
await AuthService.Auth(new AuthLoginPassword(login, password, authServer), code);
CurrentLogin = login;
CurrentPassword = password;
CurrentAuthServer = authServer;
IsLogged = true;
ConfigurationService.SetConfigValue(LauncherConVar.AuthCurrent, AuthService.SelectedAuth);
}
catch (AuthException e)
{
message.Dispose();
switch (e.Error.Code)
{
@@ -115,13 +137,6 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
throw;
}
}
catch (Exception e)
{
message.Dispose();
Logout();
PopupMessageService.Popup(e);
}
});
}
private void OnTfaEntered(string code)
@@ -176,7 +191,7 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
AuthUrls.Clear();
var authUrls = ConfigurationService.GetConfigValue(LauncherConVar.AuthServers)!;
foreach (var url in authUrls) AuthUrls.Add(url);
if(authUrls.Length > 0) CurrentAuthServer = authUrls[0];
if(authUrls.Length > 0) AuthItemSelect = authUrls[0];
var currProfile = ConfigurationService.GetConfigValue(LauncherConVar.AuthCurrent);
@@ -184,7 +199,9 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
{
try
{
CurrentAlp = new AuthLoginPassword(currProfile.Login, string.Empty, currProfile.AuthServer);
CurrentLogin = currProfile.Login;
CurrentAuthServer = currProfile.AuthServer;
IsLogged = await AuthService.SetAuth(currProfile);
}
catch (Exception e)
@@ -200,7 +217,7 @@ public partial class AccountInfoViewModel : ViewModelBase, IViewModelPage
[RelayCommand]
private void OnSaveProfile()
{
AddAccount(CurrentAlp);
AddAccount(new AuthLoginPassword(CurrentLogin, CurrentPassword, CurrentAuthServer));
_isProfilesEmpty = Accounts.Count == 0;
UpdateAuthMenu();
DirtyProfile();
@@ -244,3 +261,8 @@ public sealed record ProfileAuthCredentials(
[property: JsonIgnore] ICommand OnSelect = default!,
[property: JsonIgnore] ICommand OnDelete = default!
);
public sealed record AuthServerCredentials(
string Name,
string[] Servers
);

View File

@@ -118,7 +118,6 @@
<Label VerticalAlignment="Center">
Auth server:
</Label>
<TextBox MinWidth="200" Text="{Binding CurrentAuthServer}" />
<Button Command="{Binding ExpandAuthUrlCommand}" VerticalAlignment="Stretch">
<Label>+</Label>
</Button>
@@ -139,7 +138,7 @@
<ListBox.ItemTemplate>
<DataTemplate>
<Label>
<TextBlock Text="{Binding}" />
<TextBlock Text="{Binding Name}" />
</Label>
</DataTemplate>
</ListBox.ItemTemplate>

View File

@@ -6,10 +6,16 @@ namespace Nebula.Shared;
public static class CurrentConVar
{
public static readonly ConVar<string[]> EngineManifestUrl =
ConVarBuilder.Build<string[]>("engine.manifestUrl", ["https://robust-builds.cdn.spacestation14.com/manifest.json"]);
ConVarBuilder.Build<string[]>("engine.manifestUrl", [
"https://robust-builds.cdn.spacestation14.com/manifest.json",
"https://robust-builds.fallback.cdn.spacestation14.com/manifest.json"
]);
public static readonly ConVar<string[]> EngineModuleManifestUrl =
ConVarBuilder.Build<string[]>("engine.moduleManifestUrl", ["https://robust-builds.cdn.spacestation14.com/modules.json"]);
ConVarBuilder.Build<string[]>("engine.moduleManifestUrl", [
"https://robust-builds.cdn.spacestation14.com/modules.json",
"https://robust-builds.fallback.cdn.spacestation14.com/modules.json"
]);
public static readonly ConVar<int> ManifestDownloadProtocolVersion =
ConVarBuilder.Build("engine.manifestDownloadProtocolVersion", 1);
@@ -17,8 +23,8 @@ 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"
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 =

View File

@@ -7,6 +7,7 @@ public class HubService
{
private readonly ConfigurationService _configurationService;
private readonly RestService _restService;
private readonly DebugService _debugService;
private readonly List<ServerHubInfo> _serverList = new();
@@ -14,10 +15,11 @@ public class HubService
public Action? HubServerLoaded;
public Action<Exception>? HubServerLoadingError;
public HubService(ConfigurationService configurationService, RestService restService)
public HubService(ConfigurationService configurationService, RestService restService, DebugService debugService)
{
_configurationService = configurationService;
_restService = restService;
_debugService = debugService;
UpdateHub();
}
@@ -36,20 +38,32 @@ public class HubService
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(urlStr), CancellationToken.None);
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)
{
HubServerLoadingError?.Invoke(e);
_debugService.Error($"Failed to get servers for {uri}");
_debugService.Error(e);
exception = e;
}
}
if(exception is not null && !invoked)
HubServerLoadingError?.Invoke(new Exception("No hub is available.", exception));
}
IsUpdating = false;
HubServerLoaded?.Invoke();
}

View File

@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AButton_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fcc84c38d8785b88e166e6741b6a4c0dfa09eaf6e41eb151b255817e11f27570_003FButton_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACancellationToken_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2565b9d99fdde488bc7801b84387b2cc864959cfb63212e1ff576fc9c6bb7e_003FCancellationToken_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACollection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F50341a469131fa51e5443b9bd96c4ca1c96bfa709f7f41fd15941ff6296a8dc_003FCollection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConsole_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Ffd57398b7dc3a8ce7da2786f2c67289c3d974658a9e90d0c1e84db3d965fbf1_003FConsole_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFrozenDictionary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F89dff9063ddb01ff8125b579122b88bf4de94526490d77bcbbef7d0ee662a_003FFrozenDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFuture_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fb3575a2f41d7c2dbfaa36e866b8a361e11dd7223ff82bc574c1d5d4b7522f735_003FFuture_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
@@ -11,4 +12,5 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParallel_002EForEachAsync_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc1d1ed6be2d5d4de542b4af5b36e82f6d1d1a389a35a4e4f9748d137d1c651_003FParallel_002EForEachAsync_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AServiceCollectionContainerBuilderExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa8ceca48b7b645dd875a40ee6d28725416d08_003F1b_003F6cd78dc8_003FServiceCollectionContainerBuilderExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002EManipulation_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe75a5575ba872c8ea754c015cb363850e6c661f39569712d5b74aaca67263c_003FString_002EManipulation_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUri_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6a1fb5a19c4883d19f63515be2d0cce5e0e9929bb30469a912a58ad2e1e6152_003FUri_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUri_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6a1fb5a19c4883d19f63515be2d0cce5e0e9929bb30469a912a58ad2e1e6152_003FUri_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String></wpf:ResourceDictionary>