diff --git a/SS14.Launcher/Api/AuthApi.cs b/SS14.Launcher/Api/AuthApi.cs index efc4c15..41b71cb 100644 --- a/SS14.Launcher/Api/AuthApi.cs +++ b/SS14.Launcher/Api/AuthApi.cs @@ -16,18 +16,29 @@ namespace SS14.Launcher.Api; public sealed class AuthApi { + private readonly DataManager _cfg; private readonly HttpClient _httpClient; - public AuthApi(HttpClient http) + public AuthApi(DataManager cfg, + HttpClient http) { + _cfg = cfg; _httpClient = http; } + private UrlFallbackSet GetAuthUrl() + { + // TODO: testing purposes, do this better later + var authUrl = _cfg.GetCVar(CVars.CustomAuthUrl); + return new UrlFallbackSet([authUrl, authUrl]); + } + public async Task AuthenticateAsync(AuthenticateRequest request) { try { - var authUrl = ConfigConstants.AuthUrl + "api/auth/authenticate"; + var baseAuthUrl = GetAuthUrl(); + var authUrl = baseAuthUrl + "api/auth/authenticate"; using var resp = await _httpClient.PostAsJsonAsync(authUrl, request); @@ -80,7 +91,8 @@ public async Task RegisterAsync(string username, string email, s { var request = new RegisterRequest(username, email, password); - var authUrl = ConfigConstants.AuthUrl + "api/auth/register"; + var baseAuthUrl = GetAuthUrl(); + var authUrl = baseAuthUrl + "api/auth/register"; using var resp = await _httpClient.PostAsJsonAsync(authUrl, request); @@ -122,7 +134,8 @@ public async Task RegisterAsync(string username, string email, s { var request = new ResetPasswordRequest(email); - var authUrl = ConfigConstants.AuthUrl + "api/auth/resetPassword"; + var baseAuthUrl = GetAuthUrl(); + var authUrl = baseAuthUrl + "api/auth/resetPassword"; using var resp = await _httpClient.PostAsJsonAsync(authUrl, request); @@ -149,7 +162,8 @@ public async Task RegisterAsync(string username, string email, s { var request = new ResendConfirmationRequest(email); - var authUrl = ConfigConstants.AuthUrl + "api/auth/resendConfirmation"; + var baseAuthUrl = GetAuthUrl(); + var authUrl = baseAuthUrl + "api/auth/resendConfirmation"; using var resp = await _httpClient.PostAsJsonAsync(authUrl, request); @@ -181,7 +195,8 @@ public async Task RegisterAsync(string username, string email, s { var request = new RefreshRequest(token); - var authUrl = ConfigConstants.AuthUrl + "api/auth/refresh"; + var baseAuthUrl = GetAuthUrl(); + var authUrl = baseAuthUrl + "api/auth/refresh"; using var resp = await _httpClient.PostAsJsonAsync(authUrl, request); @@ -224,7 +239,8 @@ public async Task LogoutTokenAsync(string token) { var request = new LogoutRequest(token); - var authUrl = ConfigConstants.AuthUrl + "api/auth/logout"; + var baseAuthUrl = GetAuthUrl(); + var authUrl = baseAuthUrl + "api/auth/logout"; using var resp = await _httpClient.PostAsJsonAsync(authUrl, request); @@ -256,7 +272,8 @@ public async Task CheckTokenAsync(string token) { try { - var authUrl = ConfigConstants.AuthUrl + "api/auth/ping"; + var baseAuthUrl = GetAuthUrl(); + var authUrl = baseAuthUrl + "api/auth/ping"; using var resp = await authUrl.SendAsync(_httpClient, url => { diff --git a/SS14.Launcher/Assets/Locale/en-US/text.ftl b/SS14.Launcher/Assets/Locale/en-US/text.ftl index 24aafc2..a8c9d75 100644 --- a/SS14.Launcher/Assets/Locale/en-US/text.ftl +++ b/SS14.Launcher/Assets/Locale/en-US/text.ftl @@ -143,6 +143,7 @@ login-login-button-resend = Resend email confirmation login-login-button-register = Don't have an account? Register! login-login-busy-logging-in = Logging in… login-login-error-title = Unable to log in +login-login-auth-disclaimer = Current auth server: {$auth-server} ## Strings for the "register confirmation" view on login @@ -365,6 +366,11 @@ tab-options-disable-signing = Disable Engine Signature Checks tab-options-disable-signing-desc = { "[" }DEV ONLY] Disables verification of engine signatures. DO NOT ENABLE UNLESS YOU KNOW EXACTLY WHAT YOU'RE DOING. tab-options-hub-settings = Hub Settings tab-options-hub-settings-desc = Change what hub server or servers you would like to use to fetch the server list. +tab-options-auth-url = https://auth.playss14.com/ +tab-options-auth-url-button = Set Auth URL +tab-options-set-wizden = Set to WizDen Auth +tab-options-set-funky = Set to Funky Auth +tab-options-auth-url-desc = Change what auth server you're using. tab-options-desc-incompatible = This option is incompatible with your platform and has been disabled. ## For the language selection menu. diff --git a/SS14.Launcher/Models/Connector.cs b/SS14.Launcher/Models/Connector.cs index 20a0f37..96c1e4a 100644 --- a/SS14.Launcher/Models/Connector.cs +++ b/SS14.Launcher/Models/Connector.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Diagnostics; using System.IO; using System.IO.Compression; @@ -345,11 +346,12 @@ private async Task LaunchClientWrap( if (info != null && info.AuthInformation.Mode != AuthMode.Disabled && _loginManager.ActiveAccount != null) { var account = _loginManager.ActiveAccount; + var customAuthUrl = _cfg.GetCVar(CVars.CustomAuthUrl); cVars.Add(("ROBUST_AUTH_TOKEN", account.LoginInfo.Token.Token)); cVars.Add(("ROBUST_AUTH_USERID", account.LoginInfo.UserId.ToString())); cVars.Add(("ROBUST_AUTH_PUBKEY", info.AuthInformation.PublicKey)); - cVars.Add(("ROBUST_AUTH_SERVER", ConfigConstants.AuthUrl.GetMostSuccessfulUrl())); + cVars.Add(("ROBUST_AUTH_SERVER", customAuthUrl)); } try diff --git a/SS14.Launcher/Models/Data/CVars.cs b/SS14.Launcher/Models/Data/CVars.cs index b781836..aad30c4 100644 --- a/SS14.Launcher/Models/Data/CVars.cs +++ b/SS14.Launcher/Models/Data/CVars.cs @@ -103,6 +103,8 @@ public static readonly CVarDef HasDismissedRosettaWarning /// public static readonly CVarDef OverrideAssets = CVarDef.Create("OverrideAssets", true); + public static readonly CVarDef CustomAuthUrl = CVarDef.Create("CustomAuthUrl", "https://auth.playss14.com/"); + /// /// Stores the minimum player count value used by the "minimum player count" filter. /// diff --git a/SS14.Launcher/Program.cs b/SS14.Launcher/Program.cs index 0934225..e523536 100644 --- a/SS14.Launcher/Program.cs +++ b/SS14.Launcher/Program.cs @@ -219,7 +219,7 @@ private static AppBuilder BuildAvaloniaApp(DataManager cfg) Locator.CurrentMutable.RegisterConstant(http); var loc = new LocalizationManager(cfg); - var authApi = new AuthApi(http); + var authApi = new AuthApi(cfg, http); var hubApi = new HubApi(http); var launcherInfo = new LauncherInfoManager(http); var overrideAssets = new OverrideAssetsManager(cfg, http, launcherInfo); diff --git a/SS14.Launcher/ViewModels/Login/LoginViewModel.cs b/SS14.Launcher/ViewModels/Login/LoginViewModel.cs index a5e7ce6..7786f81 100644 --- a/SS14.Launcher/ViewModels/Login/LoginViewModel.cs +++ b/SS14.Launcher/ViewModels/Login/LoginViewModel.cs @@ -21,6 +21,7 @@ public class LoginViewModel : BaseLoginViewModel [Reactive] public bool IsInputValid { get; private set; } [Reactive] public bool IsPasswordVisible { get; set; } + public string AuthDisclaimer { get; private set; } public LoginViewModel(MainWindowLoginViewModel parentVm, AuthApi authApi, LoginManager loginMgr, DataManager dataManager) : base(parentVm) @@ -32,6 +33,9 @@ public LoginViewModel(MainWindowLoginViewModel parentVm, AuthApi authApi, this.WhenAnyValue(x => x.EditingUsername, x => x.EditingPassword) .Subscribe(s => { IsInputValid = !string.IsNullOrEmpty(s.Item1) && !string.IsNullOrEmpty(s.Item2); }); + + AuthDisclaimer = _loc.GetString("login-login-auth-disclaimer", + ("auth-server", _dataManager.GetCVar(CVars.CustomAuthUrl))); } public async void OnLogInButtonPressed() diff --git a/SS14.Launcher/ViewModels/MainWindowTabs/OptionsTabViewModel.cs b/SS14.Launcher/ViewModels/MainWindowTabs/OptionsTabViewModel.cs index d61a93a..7e41c14 100644 --- a/SS14.Launcher/ViewModels/MainWindowTabs/OptionsTabViewModel.cs +++ b/SS14.Launcher/ViewModels/MainWindowTabs/OptionsTabViewModel.cs @@ -6,6 +6,7 @@ using SS14.Launcher.Models.ContentManagement; using SS14.Launcher.Models.Data; using SS14.Launcher.Models.EngineManager; +using SS14.Launcher.Models.Logins; using SS14.Launcher.Utility; namespace SS14.Launcher.ViewModels.MainWindowTabs; @@ -13,8 +14,13 @@ namespace SS14.Launcher.ViewModels.MainWindowTabs; public class OptionsTabViewModel : MainWindowTabViewModel { public DataManager Cfg { get; } + private readonly IEngineManager _engineManager; private readonly ContentManager _contentManager; + private readonly LoginManager _loginManager; + + public string FunkyAuthUrl = "https://tempauth.funkystation.org/"; + public string WizDenAuthUrl = "https://auth.playss14.com/"; public LanguageSelectorViewModel Language { get; } = new(); @@ -23,9 +29,11 @@ public OptionsTabViewModel() Cfg = Locator.Current.GetRequiredService(); _engineManager = Locator.Current.GetRequiredService(); _contentManager = Locator.Current.GetRequiredService(); + _loginManager = Locator.Current.GetRequiredService(); DisableIncompatibleMacOS = OperatingSystem.IsMacOS(); } + public bool DisableIncompatibleMacOS { get; } public override string Name => LocalizationManager.Instance.GetString("tab-options-title"); @@ -60,6 +68,40 @@ public bool OverrideAssets } } + private string? _pendingAuthUrl; + + public string CustomAuthUrl + { + get => _pendingAuthUrl ?? Cfg.GetCVar(CVars.CustomAuthUrl); + set => _pendingAuthUrl = value; + } + + public void SetAuthUrl() + { + if (_pendingAuthUrl == null || _pendingAuthUrl == Cfg.GetCVar(CVars.CustomAuthUrl)) + return; + + if (!_pendingAuthUrl.EndsWith('/')) + _pendingAuthUrl += '/'; + + // TODO: validate auth URL + + Cfg.SetCVar(CVars.CustomAuthUrl, _pendingAuthUrl); + + if (_loginManager.ActiveAccount != null) + Cfg.RemoveLogin(_loginManager.ActiveAccount.LoginInfo); + + Cfg.CommitConfig(); + + _pendingAuthUrl = null; + } + + public void SetAuthUrl(string url) + { + _pendingAuthUrl = url; + SetAuthUrl(); + } + public void ClearEngines() { _engineManager.ClearAllEngines(); diff --git a/SS14.Launcher/Views/Login/LoginView.xaml b/SS14.Launcher/Views/Login/LoginView.xaml index 20f78a4..0b9f457 100644 --- a/SS14.Launcher/Views/Login/LoginView.xaml +++ b/SS14.Launcher/Views/Login/LoginView.xaml @@ -47,6 +47,9 @@ Command="{Binding ResendConfirmationPressed}"/> +