Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions SS14.Launcher/Api/AuthApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ namespace SS14.Launcher.Api;
public sealed class AuthApi
{
private readonly HttpClient _httpClient;
private readonly LoginProviderManager _loginProviderManager;

public AuthApi(HttpClient http)
public AuthApi(HttpClient http, LoginProviderManager loginProviderManager)
{
_httpClient = http;
_loginProviderManager = loginProviderManager;
}

public async Task<AuthenticateResult> AuthenticateAsync(AuthenticateRequest request)
{
try
{
var authUrl = LoginManager.GetAuthServerById(request.Server ?? ConfigConstants.FallbackAuthServer, request.ServerUrl);
var authUrl = _loginProviderManager.GetAuthServerById(request.Server ?? ConfigConstants.FallbackAuthServer, request.ServerUrl);

using var resp = await _httpClient.PostAsJsonAsync(authUrl.AuthAuthUrl, request);

Expand Down Expand Up @@ -83,7 +85,7 @@ public async Task<RegisterResult> RegisterAsync(string server, string? serverUrl
{
var request = new RegisterRequest(username, email, password);

var authUrl = LoginManager.GetAuthServerById(server, serverUrl).AuthRegUrl;
var authUrl = _loginProviderManager.GetAuthServerById(server, serverUrl).AuthRegUrl;

using var resp = await _httpClient.PostAsJsonAsync(authUrl, request);

Expand Down Expand Up @@ -125,7 +127,7 @@ public async Task<RegisterResult> RegisterAsync(string server, string? serverUrl
{
var request = new ResetPasswordRequest(email);

var authUrl = LoginManager.GetAuthServerById(server, serverUrl).AuthPwResetUrl;
var authUrl = _loginProviderManager.GetAuthServerById(server, serverUrl).AuthPwResetUrl;

using var resp = await _httpClient.PostAsJsonAsync(authUrl, request);

Expand All @@ -152,7 +154,7 @@ public async Task<RegisterResult> RegisterAsync(string server, string? serverUrl
{
var request = new ResendConfirmationRequest(email);

var authUrl = LoginManager.GetAuthServerById(server, serverUrl).AuthResendUrl;
var authUrl = _loginProviderManager.GetAuthServerById(server, serverUrl).AuthResendUrl;

using var resp = await _httpClient.PostAsJsonAsync(authUrl, request);

Expand Down Expand Up @@ -184,7 +186,7 @@ public async Task<RegisterResult> RegisterAsync(string server, string? serverUrl
{
var request = new RefreshRequest(token);

var authUrl = LoginManager.GetAuthServerById(server, serverUrl).AuthRefreshUrl;
var authUrl = _loginProviderManager.GetAuthServerById(server, serverUrl).AuthRefreshUrl;

using var resp = await _httpClient.PostAsJsonAsync(authUrl, request);

Expand Down Expand Up @@ -227,7 +229,7 @@ public async Task LogoutTokenAsync(string server, string? serverUrl, string toke
{
var request = new LogoutRequest(token);

var authUrl = LoginManager.GetAuthServerById(server, serverUrl).AuthLogoutUrl;
var authUrl = _loginProviderManager.GetAuthServerById(server, serverUrl).AuthLogoutUrl;

using var resp = await _httpClient.PostAsJsonAsync(authUrl, request);

Expand Down Expand Up @@ -259,7 +261,7 @@ public async Task<bool> CheckTokenAsync(string server, string? serverUrl, string
{
try
{
var authUrl = LoginManager.GetAuthServerById(server, serverUrl).AuthPingUrl;
var authUrl = _loginProviderManager.GetAuthServerById(server, serverUrl).AuthPingUrl;

using var requestMessage = new HttpRequestMessage(HttpMethod.Get, authUrl);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("SS14Auth", token);
Expand Down
9 changes: 8 additions & 1 deletion SS14.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
using Splat;
using SS14.Launcher.Localization;
using SS14.Launcher.Models;
using SS14.Launcher.Models.CDN;
using SS14.Launcher.Models.ContentManagement;
using SS14.Launcher.Models.Data;
using SS14.Launcher.Models.OverrideAssets;
using SS14.Launcher.Utility;
using SS14.Launcher.ViewModels;
Expand Down Expand Up @@ -200,14 +202,19 @@ public override void OnFrameworkInitializationCompleted()
}
}

private void OnStartup(object? s, ControlledApplicationLifetimeStartupEventArgs e)
private async void OnStartup(object? s, ControlledApplicationLifetimeStartupEventArgs e)
{
var loc = Locator.Current.GetRequiredService<LocalizationManager>();
var msgr = Locator.Current.GetRequiredService<LauncherMessaging>();
var contentManager = Locator.Current.GetRequiredService<ContentManager>();
var overrideAssets = Locator.Current.GetRequiredService<OverrideAssetsManager>();
var launcherInfo = Locator.Current.GetRequiredService<LauncherInfoManager>();
var cdnManager = Locator.Current.GetRequiredService<CdnManager>();
var cfg = Locator.Current.GetRequiredService<DataManager>();

cdnManager.ShowPingWindow();
await Task.Run(cdnManager.SortFastestAndMap);
cfg.LoadHubs(cdnManager);
loc.Initialize();
launcherInfo.Initialize();
contentManager.Initialize();
Expand Down
72 changes: 27 additions & 45 deletions SS14.Launcher/ConfigConstants.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using SS14.Launcher.Models.CDN;
using SS14.Launcher.Utility;
using TerraFX.Interop.Windows;

namespace SS14.Launcher;

Expand Down Expand Up @@ -32,32 +32,33 @@ public static class ConfigConstants
// Amount of time to wait to let a redialling client properly die
public const int LauncherCommandsRedialWaitTimeout = 1000;

public const string FallbackAuthServer = "Space-Wizards";
public const string GuestAuthServer = "guest";
public const string CustomAuthServer = "Custom";
public static readonly UriCdnDefinition FallbackAuthServer = "Space-Wizards";
public static readonly UriCdnDefinition GuestAuthServer = "guest";
public static readonly UriCdnDefinition CustomAuthServer = "Custom";
public static readonly AuthServer TemplateAuthServer = new(new("https://example.com/"), new("https://example.com/"));
public static readonly Dictionary<string, AuthServer> AuthUrls = new()

public static readonly Dictionary<string, AuthServerDefinition> AuthUrls = new()
{
{
"SimpleStation",
new(new("https://auth.simplestation.org/"), new("https://account.simplestation.org/"), true)
new("SimpleStationAuth", "SimpleStationAccount", true)
},
{
FallbackAuthServer,
new(new("https://auth.spacestation14.com/"), new("https://account.spacestation14.com/"), false)
new("FallbackAuthServerAuth", "FallbackAuthServerAccount", false)
},
{
CustomAuthServer,
new (new("https://example.com/"), new("https://example.com/"))
new ("CustomAuthServerAuth", "CustomAuthServerAccount")
},
};

public static readonly Uri[] DefaultHubUrls =
public static readonly UriCdnDefinition[] DefaultHubUrls =
[
new("https://hub.simplestation.org/"),
new("https://hub.singularity14.co.uk/"),
new("https://cdn.spacestationmultiverse.com/hub/"),
new("https://hub.spacestation14.com/"),
"SimpleStationHub",
"SingularityHub",
"MultiverseHub",
"SpaceStationHub",
];

public const string DiscordUrl = "https://discord.gg/49KeKwXc8g";
Expand All @@ -66,61 +67,42 @@ public static class ConfigConstants
public const string NewsFeedUrl = "https://spacestation14.com/post/index.xml"; //TODO
public const string TranslateUrl = "https://docs.spacestation14.com/en/general-development/contributing-translations.html"; //TODO

public static readonly Dictionary<string, UrlFallbackSet> EngineBuildsUrl = new()
public static readonly Dictionary<string, UriCdnDefinition> EngineBuildsUrl = new()
{
{
"Robust",
new UrlFallbackSet([
"https://robust-builds.cdn.spacestation14.com/manifest.json",
"https://robust-builds.fallback.cdn.spacestation14.com/manifest.json",
])
"Robust", "RobustEngine"
},
{
"Multiverse",
new UrlFallbackSet([
"https://cdn.spacestationmultiverse.com/ssmv-engine-manifest",
])
"Multiverse", "MultiverseEngine"
},
{
"Supermatter",
new UrlFallbackSet([
"https://cdn.simplestation.org/supermatter/manifest.json",
])
"Supermatter", "SupermatterEngine"
},
};

public static readonly Dictionary<string, UrlFallbackSet> EngineModulesUrl = new()
public static readonly Dictionary<string, UriCdnDefinition> EngineModulesUrl = new()
{
{
"Robust",
new UrlFallbackSet([
"https://robust-builds.cdn.spacestation14.com/modules.json",
"https://robust-builds.fallback.cdn.spacestation14.com/modules.json",
])
"Robust", "RobustModules"
},
{
"Multiverse",
new UrlFallbackSet([
// Same as Robust for now
"https://robust-builds.cdn.spacestation14.com/modules.json",
"https://robust-builds.fallback.cdn.spacestation14.com/modules.json",
])
"Multiverse", "MultiverseModules"
},
};

private static readonly UrlFallbackSet LauncherDataBaseUrl = new([
"http://assets.simplestation.org/launcher/",
]);

// How long to keep cached copies of Robust manifests.
// TODO: Take this from Cache-Control header responses instead.
public static readonly TimeSpan RobustManifestCacheTime = TimeSpan.FromMinutes(15);

public static readonly UrlFallbackSet UrlLauncherInfo = LauncherDataBaseUrl + "info.json";
public static readonly UrlFallbackSet UrlAssetsBase = LauncherDataBaseUrl + "assets/";
public static readonly UriCdnDefinition UrlLauncherInfo = "LauncherInfo";
public static readonly UriCdnDefinition UrlAssetsBase = "LauncherAssetsBase";

public const string FallbackUsername = "JoeGenero";

public record struct AuthServerDefinition(
UriCdnDefinition AuthUrl,
UriCdnDefinition AccountSite,
bool? Recommended = null);

public class AuthServer(
Uri authUrl,
Expand Down
14 changes: 14 additions & 0 deletions SS14.Launcher/Controls/CDN/CdnPingEntry.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SS14.Launcher.Controls.CDN.CdnPingEntry">
<Border Background="Transparent" BorderBrush="White" BorderThickness="0,0,0,1">
<Panel>
<TextBlock x:Name="UrlName" Padding="5"/>
<TextBlock MinWidth="100" Foreground="#222222" Background="White" Padding="5" x:Name="Status" HorizontalAlignment="Right"/>
</Panel>
</Border>
</UserControl>

37 changes: 37 additions & 0 deletions SS14.Launcher/Controls/CDN/CdnPingEntry.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using SS14.Launcher.Models.CDN;

namespace SS14.Launcher.Controls.CDN;

public partial class CdnPingEntry : UserControl
{
public CdnPingEntry()
{
InitializeComponent();
}

public void SetData(CdnDataCompound cdnData)
{
UrlName.Text = cdnData.CdnData.Uri.ToString();
var result = cdnData.Ping;

if (result.TimeoutMs is not null)
{
Status.Text = $"{result.TimeoutMs}ms";
}
else
{
Status.Text = result.Reason;
}

if (result.Error)
{
Status.Foreground = Brushes.White;
Status.Background = Brushes.DarkRed;
}
}
}

14 changes: 14 additions & 0 deletions SS14.Launcher/Controls/CDN/CdnPingGroupControl.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Border xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SS14.Launcher.Controls.CDN.CdnPingGroupControl">
<StackPanel>
<Border Background="White">
<Label Foreground="#222222" Margin="5" Name="GroupLabel"></Label>
</Border>
<StackPanel Orientation="Vertical" Name="PingInfoContainer"/>
</StackPanel>
</Border>

28 changes: 28 additions & 0 deletions SS14.Launcher/Controls/CDN/CdnPingGroupControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace SS14.Launcher.Controls.CDN;

public partial class CdnPingGroupControl : Border
{
private Dictionary<string, CdnPingEntry> _entries = new();

public CdnPingGroupControl()
{
InitializeComponent();
}

public CdnPingEntry EnsureEntry(string key)
{
if (_entries.TryGetValue(key, out var entry))
return entry;

entry = new CdnPingEntry();
_entries.Add(key, entry);
PingInfoContainer.Children.Add(entry);
return entry;
}
}

19 changes: 19 additions & 0 deletions SS14.Launcher/Controls/CDN/CdnPingWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="350" Width="800" Height="600"
x:Class="SS14.Launcher.Controls.CDN.CdnPingWindow"
Title="CDN Ping resolver">
<StackPanel Orientation="Vertical">
<Border HorizontalAlignment="Stretch" Background="White">
<TextBlock Text="CDN Ping resolver" Padding="10" HorizontalAlignment="Center" Foreground="#222222"/>
</Border>
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<StackPanel Orientation="Vertical" Margin="0,5,0,0" Spacing="5" Name="CdnPanel">

</StackPanel>
</ScrollViewer>
</StackPanel>
</Window>

34 changes: 34 additions & 0 deletions SS14.Launcher/Controls/CDN/CdnPingWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Threading;
using DynamicData;
using SS14.Launcher.Models.CDN;

namespace SS14.Launcher.Controls.CDN;

public partial class CdnPingWindow : Window
{
public Dictionary<string, CdnPingGroupControl> ActiveCdnGroups = [];

public CdnPingWindow()
{
InitializeComponent();
}

public void ResolveItem(CdnDataCompound cdnDataCompound)
{
Dispatcher.UIThread.Post(() =>
{
if(!ActiveCdnGroups.TryGetValue(cdnDataCompound.CdnData.Id, out var group))
{
group = new CdnPingGroupControl();
group.GroupLabel.Content = cdnDataCompound.CdnData.Id.ToString();
ActiveCdnGroups.Add(cdnDataCompound.CdnData.Id, group);
CdnPanel.Children.Add(group);
}

var entry = group.EnsureEntry(cdnDataCompound.CdnData.Uri.AbsoluteUri);
entry.SetData(cdnDataCompound);
});
}
}
Loading
Loading