Skip to content
Merged
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
7 changes: 6 additions & 1 deletion SS14.Launcher/Assets/Locale/en-US/text.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ login-login-username-watermark = Username or email
login-login-password-watermark = Password
login-login-show-password = Show Password
login-login-auth-server = Account Provider
login-login-auth-Space-Wizards-Federation = Space Wizards
login-login-auth-Space-Wizards = Space Wizards (Legacy)
login-login-auth-SimpleStation = SimpleStation
login-login-auth-guest = Guest
login-login-auth-Custom = Custom
login-login-button-log-in = Log in
login-login-button-forgot = Forgot your password?
login-login-button-resend = Resend email confirmation
Expand Down Expand Up @@ -258,7 +263,7 @@ tab-servers-byond-error-msg = BYOND not installed or found
tab-servers-byond-error-desc = To connect to BYOND servers, please install BYOND from https://www.byond.com/download/ and ensure it is set as the default program for handling byond:// links.
tab-servers-byond-error-link-text = Download BYOND
tab-servers-byond-exception-msg = Failed to connect to BYOND server
tab-servers-byond-exception-desc = An error occurred while trying to launch BYOND:
tab-servers-byond-exception-desc = An error occurred while trying to launch BYOND:

tab-servers-refresh = Refresh
filters = Filters ({ $filteredServers } / { $totalServers })
Expand Down
6 changes: 5 additions & 1 deletion SS14.Launcher/ConfigConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ 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 FallbackAuthServer = "Space-Wizards-Federation";
public const string GuestAuthServer = "guest";
public const string CustomAuthServer = "Custom";
public static readonly AuthServer TemplateAuthServer = new(new("https://example.com/"), new("https://example.com/"));
public static readonly Dictionary<string, AuthServer> AuthUrls = new()
{
{
FallbackAuthServer,
new(new("https://auth.playss14.com/"), new("https://account.playss14.com/"), false)
},
{
"Space-Wizards",
new(new("https://auth.spacestation14.com/"), new("https://account.spacestation14.com/"), false)
},
{
Expand Down
20 changes: 19 additions & 1 deletion SS14.Launcher/Models/Logins/LoginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,15 @@ public static ConfigConstants.AuthServer GetAuthServerById(string serverId, stri

customAccountSite ??= TryGetAccountUrl(serverId, customAuthUrl);
if (customAccountSite == null)
{
#if DEBUG
// You fool
throw new ArgumentException("Failed to get account URL for custom server.");
#else
Log.Warning("Failed to get account URL for custom server, using template info.");
customAccountSite = ConfigConstants.TemplateAuthServer.AccountSite.ToString();
#endif
}

return new ConfigConstants.AuthServer(new(customAuthUrl), new(customAccountSite));
}
Expand All @@ -218,8 +226,18 @@ public static ConfigConstants.AuthServer GetAuthServerById(string serverId, stri

// Make an http request to the custom URL to get the account URL
var http = HappyEyeballsHttp.CreateHttpClient();
var response = http.GetAsync(new Uri(customAuthUrl) + ConfigConstants.TemplateAuthServer.AuthAccountSitePath).Result;
HttpResponseMessage response;
try
{
response = http.GetAsync(new Uri(customAuthUrl) + ConfigConstants.TemplateAuthServer.AuthAccountSitePath).Result;
}
catch (Exception e)
{
Log.Error($"Failed to contact custom auth server at {customAuthUrl} to get account URL: {e}");
return null;
}
http.Dispose();

if (!response.IsSuccessStatusCode)
{
Log.Error("Failed to get account URL from custom auth server with status {status}", response.StatusCode);
Expand Down
8 changes: 8 additions & 0 deletions SS14.Launcher/ViewModels/Login/BaseLoginViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using ReactiveUI.Fody.Helpers;
using SS14.Launcher.Localization;

namespace SS14.Launcher.ViewModels.Login;

Expand All @@ -9,6 +12,11 @@ public abstract class BaseLoginViewModel : ViewModelBase, IErrorOverlayOwner
[Reactive] public ViewModelBase? OverlayControl { get; set; }
public MainWindowLoginViewModel ParentVM { get; }

[Reactive] public string Server { get; set; } = ConfigConstants.AuthUrls.Keys.Select(k => LocalizationManager.Instance.GetString($"login-login-auth-{k}")).First();
public string? ServerID => Delocalizer.TryGetValue(Server, out var id) ? id : null;
[Reactive] public List<string> Servers { get; set; } = ConfigConstants.AuthUrls.Keys.Select(k => LocalizationManager.Instance.GetString($"login-login-auth-{k}")).ToList();
public Dictionary<string, string> Delocalizer = ConfigConstants.AuthUrls.ToDictionary(kv => LocalizationManager.Instance.GetString($"login-login-auth-{kv.Key}"), kv => kv.Key);

protected BaseLoginViewModel(MainWindowLoginViewModel parentVM)
{
ParentVM = parentVM;
Expand Down
14 changes: 8 additions & 6 deletions SS14.Launcher/ViewModels/Login/ForgotPasswordViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ public sealed class ForgotPasswordViewModel : BaseLoginViewModel
private readonly AuthApi _authApi;
private readonly LocalizationManager _loc = LocalizationManager.Instance;

[Reactive] public string Server { get; set; } = ConfigConstants.AuthUrls.First().Key;
[Reactive] public List<string> Servers { get; set; } = ConfigConstants.AuthUrls.Keys.ToList();
[Reactive] public string? ServerUrl { get; set; }
[Reactive] public string ServerUrlPlaceholder { get; set; } = ConfigConstants.AuthUrls.First().Value.AuthUrl.ToString();
[Reactive] public bool IsCustom { get; private set; }
[Reactive] public bool IsServerPotentiallyValid { get; private set; }

[Reactive] public string EditingEmail { get; set; } = "";
[Reactive] public bool IsInputValid { get; private set; }

private bool _errored;

Expand All @@ -32,12 +31,15 @@ public ForgotPasswordViewModel(
{
_authApi = authApi;

this.WhenAnyValue(x => x.Server, x => x.ServerUrl)
this.WhenAnyValue(x => x.Server, x => x.ServerUrl, x => x.EditingEmail)
.Subscribe(s =>
{
IsCustom = Server == ConfigConstants.CustomAuthServer;
ServerUrlPlaceholder = IsCustom ? ServerUrl : LoginManager.GetAuthServerById(Server).AuthUrl.ToString();
IsServerPotentiallyValid = !IsCustom || !Busy && !string.IsNullOrEmpty(EditingEmail) && Uri.TryCreate(ServerUrl, UriKind.Absolute, out _);
IsCustom = ServerID == ConfigConstants.CustomAuthServer;
IsInputValid = IsCustom
? !string.IsNullOrEmpty(s.Item2) && !string.IsNullOrEmpty(s.Item3)
: !string.IsNullOrEmpty(ServerID) && !string.IsNullOrEmpty(s.Item3);
ServerUrlPlaceholder = IsCustom ? ServerUrl : LoginManager.GetAuthServerById(ServerID).AuthUrl.ToString();
IsServerPotentiallyValid = !IsCustom || !Busy && Uri.TryCreate(ServerUrl, UriKind.Absolute, out _);
});
}

Expand Down
18 changes: 8 additions & 10 deletions SS14.Launcher/ViewModels/Login/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class LoginViewModel : BaseLoginViewModel
private readonly DataManager _dataManager;
private readonly LocalizationManager _loc = LocalizationManager.Instance;

[Reactive] public string Server { get; set; } = ConfigConstants.AuthUrls.First().Key;
[Reactive] public List<string> Servers { get; set; } = ConfigConstants.AuthUrls.Keys.ToList();
[Reactive] public string? ServerUrl { get; set; }
[Reactive] public string ServerUrlPlaceholder { get; set; } = ConfigConstants.AuthUrls.First().Value.AuthUrl.ToString();
[Reactive] public bool IsCustom { get; private set; }
Expand All @@ -44,11 +42,11 @@ public LoginViewModel(MainWindowLoginViewModel parentVm, AuthApi authApi,
this.WhenAnyValue(x => x.Server, x => x.ServerUrl, x => x.EditingUsername, x => x.EditingPassword)
.Subscribe(s =>
{
IsInputValid = s.Item1 == ConfigConstants.CustomAuthServer
? !string.IsNullOrEmpty(s.Item2) && !string.IsNullOrEmpty(s.Item2) && !string.IsNullOrEmpty(s.Item3)
: !string.IsNullOrEmpty(s.Item1) && !string.IsNullOrEmpty(s.Item3);
IsCustom = Server == ConfigConstants.CustomAuthServer;
ServerUrlPlaceholder = IsCustom ? ServerUrl : LoginManager.GetAuthServerById(Server).AuthUrl.ToString();
IsCustom = ServerID == ConfigConstants.CustomAuthServer;
IsInputValid = IsCustom
? !string.IsNullOrEmpty(s.Item2) && !string.IsNullOrEmpty(s.Item3)
: !string.IsNullOrEmpty(ServerID) && !string.IsNullOrEmpty(s.Item3);
ServerUrlPlaceholder = IsCustom ? ServerUrl : LoginManager.GetAuthServerById(ServerID).AuthUrl.ToString();
IsServerPotentiallyValid = !IsCustom || !Busy && Uri.TryCreate(ServerUrl, UriKind.Absolute, out _);
RegisterButtonContent = _loc.GetString("login-login-button-register", ("server", Server));
});
Expand All @@ -64,7 +62,7 @@ public async void OnLogInButtonPressed()
Busy = true;
try
{
var request = new AuthApi.AuthenticateRequest(Server, ServerUrl, EditingUsername, null, EditingPassword);
var request = new AuthApi.AuthenticateRequest(ServerID, ServerUrl, EditingUsername, null, EditingPassword);
var resp = await _authApi.AuthenticateAsync(request);

await DoLogin(this, request, resp, _loginMgr, _authApi);
Expand Down Expand Up @@ -127,7 +125,7 @@ public static async Task<bool> DoLogin<T>(

// Registration is purely via website for now
public void RegisterPressed() =>
Helpers.OpenUri(LoginManager.GetAuthServerById(Server, ServerUrl).AccountRegUrl);
Helpers.OpenUri(LoginManager.GetAuthServerById(ServerID, ServerUrl).AccountRegUrl);
public void ResendConfirmationPressed() =>
Helpers.OpenUri(LoginManager.GetAuthServerById(Server, ServerUrl).AccountResendUrl);
Helpers.OpenUri(LoginManager.GetAuthServerById(ServerID, ServerUrl).AccountResendUrl);
}
12 changes: 7 additions & 5 deletions SS14.Launcher/ViewModels/Login/RegisterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using ReactiveUI.Fody.Helpers;
using Robust.Shared.AuthLib;
using SS14.Launcher.Api;
using SS14.Launcher.Localization;
using SS14.Launcher.Models.Data;
using SS14.Launcher.Models.Logins;

Expand All @@ -18,8 +19,6 @@
private readonly AuthApi _authApi;
private readonly LoginManager _loginMgr;

[Reactive] public string Server { get; set; } = ConfigConstants.AuthUrls.First().Key;
[Reactive] public List<string> Servers { get; set; } = ConfigConstants.AuthUrls.Keys.ToList();
[Reactive] public string? ServerUrl { get; set; }
[Reactive] public string ServerUrlPlaceholder { get; set; } = ConfigConstants.AuthUrls.First().Value.AuthUrl.ToString();
[Reactive] public bool IsCustom { get; private set; }
Expand Down Expand Up @@ -50,9 +49,12 @@
this.WhenAnyValue(x => x.Server, x => x.ServerUrl, x => x.EditingUsername, x => x.EditingPassword)
.Subscribe(s =>
{
IsCustom = Server == ConfigConstants.CustomAuthServer;
ServerUrlPlaceholder = IsCustom ? ServerUrl : LoginManager.GetAuthServerById(Server).AuthUrl.ToString();
IsServerPotentiallyValid = !IsCustom || !Busy && !string.IsNullOrEmpty(EditingEmail) && Uri.TryCreate(ServerUrl, UriKind.Absolute, out _);
IsCustom = ServerID == ConfigConstants.CustomAuthServer;
IsInputValid = IsCustom
? !string.IsNullOrEmpty(s.Item2) && !string.IsNullOrEmpty(s.Item3) && !string.IsNullOrEmpty(s.Item4)
: !string.IsNullOrEmpty(ServerID) && !string.IsNullOrEmpty(s.Item3) && !string.IsNullOrEmpty(s.Item4);
ServerUrlPlaceholder = IsCustom ? ServerUrl : LoginManager.GetAuthServerById(ServerID).AuthUrl.ToString();

Check warning on line 56 in SS14.Launcher/ViewModels/Login/RegisterViewModel.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 56 in SS14.Launcher/ViewModels/Login/RegisterViewModel.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'serverId' in 'AuthServer LoginManager.GetAuthServerById(string serverId, string? customAuthUrl = null, string? customAccountSite = null)'.
IsServerPotentiallyValid = !IsCustom || !Busy && Uri.TryCreate(ServerUrl, UriKind.Absolute, out _);
});
}

Expand Down
2 changes: 0 additions & 2 deletions SS14.Launcher/ViewModels/Login/ResendConfirmationViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
Expand All @@ -12,8 +11,7 @@
{
private readonly AuthApi _authApi;

[Reactive] public string Server { get; set; } = ConfigConstants.AuthUrls.First().Key;

Check warning on line 14 in SS14.Launcher/ViewModels/Login/ResendConfirmationViewModel.cs

View workflow job for this annotation

GitHub Actions / build

'ResendConfirmationViewModel.Server' hides inherited member 'BaseLoginViewModel.Server'. Use the new keyword if hiding was intended.
[Reactive] public List<string> Servers { get; set; } = ConfigConstants.AuthUrls.Keys.ToList();
[Reactive] public string? ServerUrl { get; set; }
[Reactive] public string ServerUrlPlaceholder { get; set; } = ConfigConstants.AuthUrls.First().Value.AuthUrl.ToString();
[Reactive] public bool IsCustom { get; private set; }
Expand All @@ -31,7 +29,7 @@
.Subscribe(s =>
{
IsCustom = Server == ConfigConstants.CustomAuthServer;
ServerUrlPlaceholder = IsCustom ? ServerUrl : LoginManager.GetAuthServerById(Server).AuthUrl.ToString();

Check warning on line 32 in SS14.Launcher/ViewModels/Login/ResendConfirmationViewModel.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
IsServerPotentiallyValid = !IsCustom || !Busy && !string.IsNullOrEmpty(EditingEmail) && Uri.TryCreate(ServerUrl, UriKind.Absolute, out _);
});
}
Expand Down
2 changes: 1 addition & 1 deletion SS14.Launcher/Views/Login/LoginView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Text="{loc:Loc login-login-auth-server}" />


<!-- Dropdown button that lets you pick between auth servers, with a Custom option that makes 2 editable text boxes appear -->
<!-- Dropdown button that lets you pick between auth servers plus a Custom option -->
<ComboBox DockPanel.Dock="Top" MaxWidth="500" Margin="0, 0, 0, 0"
ItemsSource="{Binding Servers}"
SelectedItem="{Binding Server}"
Expand Down
Loading