diff --git a/Nebula.Launcher/Assets/lang/en-US.ftl b/Nebula.Launcher/Assets/lang/en-US.ftl index 4ffbfd0..0fff2f6 100644 --- a/Nebula.Launcher/Assets/lang/en-US.ftl +++ b/Nebula.Launcher/Assets/lang/en-US.ftl @@ -24,8 +24,9 @@ account-auth-server = Authentication Server account-auth-button = Authenticate account-auth-save = Save Profile account-auth-hello = Hello, +account-auth-current-server = Current server auth: account-auth-logout = Log out -auth-current-login-name = Current login: {$login} +auth-current-login-name = Current login {$auth_server}: {$login} auth-current-login-no-name = Profile not selected auth-processing = Processing authentication request... @@ -37,6 +38,7 @@ auth-name-resolution-error = Failed to resolve server address. Check your networ auth-secure-error = Failed to cinnect to the server using SSL auth-config-read = Reading authentication configuration... auth-try-auth-config = Attempting to authenticate using saved configuration. +auth-try-auth-profile = Attempting to authenticate using profile config-export-logs = Export logs config-open-data = Open data path diff --git a/Nebula.Launcher/Assets/lang/ru-RU.ftl b/Nebula.Launcher/Assets/lang/ru-RU.ftl index 2e47578..fa08c58 100644 --- a/Nebula.Launcher/Assets/lang/ru-RU.ftl +++ b/Nebula.Launcher/Assets/lang/ru-RU.ftl @@ -24,8 +24,9 @@ account-auth-server = Сервер аутентификации account-auth-button = Аутентифицировать account-auth-save = Сохранить профиль account-auth-hello = Привет, +account-auth-current-server = Текущий сервер авторизации: account-auth-logout = Выйти -auth-current-login-name = Текущий профиль: {$login} +auth-current-login-name = Текущий профиль {$auth_server}: {$login} auth-current-login-no-name = Профиль не выбран auth-processing = Обработка запроса аутентификации... @@ -37,6 +38,7 @@ auth-name-resolution-error = Не удалось разрешить адрес auth-secure-error = Не удалось подключиться к серверу по SSL. Проверьте сетевые настройки. auth-config-read = Чтение конфигурации аутентификации... auth-try-auth-config = Попытка аутентификации с использованием сохраненной конфигурации. +auth-try-auth-profile = Попытка аутентификации с использованием профиля config-export-logs = Экспортировать логи config-open-data = Открыть путь данных diff --git a/Nebula.Launcher/LauncherConVar.cs b/Nebula.Launcher/LauncherConVar.cs index 3137dec..f2174d9 100644 --- a/Nebula.Launcher/LauncherConVar.cs +++ b/Nebula.Launcher/LauncherConVar.cs @@ -34,7 +34,13 @@ public static class LauncherConVar "WizDen", [ "https://harpy.durenko.tatar/auth-api/", + "https://auth.spacestation14.com/", "https://auth.fallback.spacestation14.com/", + ]), + new AuthServerCredentials( + "SimpleStation", + [ + "https://auth.simplestation.org/", ]) ]); diff --git a/Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs b/Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs index e7fe7cb..9512ad7 100644 --- a/Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs +++ b/Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs @@ -1,10 +1,13 @@ using System.Text.Json.Serialization; using System.Windows.Input; +using Avalonia.Media; using Nebula.Shared.Services; namespace Nebula.Launcher.Models.Auth; public sealed record ProfileAuthCredentials( - AuthTokenCredentials Credentials, + AuthTokenCredentials Credentials, + string AuthName, + Color Color, [property: JsonIgnore] ICommand OnSelect = default!, [property: JsonIgnore] ICommand OnDelete = default!); \ No newline at end of file diff --git a/Nebula.Launcher/ViewModels/MainViewModel.cs b/Nebula.Launcher/ViewModels/MainViewModel.cs index d9a80de..098b3b9 100644 --- a/Nebula.Launcher/ViewModels/MainViewModel.cs +++ b/Nebula.Launcher/ViewModels/MainViewModel.cs @@ -42,12 +42,12 @@ public partial class MainViewModel : ViewModelBase [ObservableProperty] private ListItemTemplate? _selectedListItem; public bool IsLoggedIn => AccountInfoViewModel.Credentials is not null; - public string LoginName => AccountInfoViewModel.Credentials?.Login ?? string.Empty; public string LoginText => LocalisationService.GetString("auth-current-login-name", new Dictionary { - { "login", LoginName } + { "login", AccountInfoViewModel.Credentials?.Login ?? "" }, + { "auth_server", AccountInfoViewModel.CurrentAuthServerName} }); [GenerateProperty] private LocalisationService LocalisationService { get; } // Не убирать! Без этой хуйни вся локализация идет в пизду! diff --git a/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs b/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs index e69145f..b6c3c6d 100644 --- a/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs +++ b/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs @@ -3,7 +3,10 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Net.Http; +using System.Security.Cryptography; +using System.Text; using System.Threading.Tasks; +using Avalonia.Media; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Nebula.Launcher.Models.Auth; @@ -23,20 +26,15 @@ namespace Nebula.Launcher.ViewModels.Pages; public partial class AccountInfoViewModel : ViewModelBase { [ObservableProperty] private bool _authMenuExpand; - [ObservableProperty] private bool _authUrlConfigExpand; - [ObservableProperty] private int _authViewSpan = 1; - [ObservableProperty] private string _currentAuthServer = string.Empty; - [ObservableProperty] private string _currentLogin = string.Empty; - [ObservableProperty] private string _currentPassword = string.Empty; - [ObservableProperty] private bool _isLogged; [ObservableProperty] private bool _doRetryAuth; [ObservableProperty] private AuthTokenCredentials? _credentials; + [ObservableProperty] private AuthServerCredentials _authItemSelect; private bool _isProfilesEmpty; [GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!; @@ -47,18 +45,22 @@ public partial class AccountInfoViewModel : ViewModelBase public ObservableCollection Accounts { get; } = new(); public ObservableCollection AuthUrls { get; } = new(); - - [ObservableProperty] private AuthServerCredentials _authItemSelect; + public string CurrentAuthServerName => GetServerAuthName(Credentials); private ILogger _logger; + + partial void OnCredentialsChanged(AuthTokenCredentials? value) + { + OnPropertyChanged(nameof(CurrentAuthServerName)); + } //Design think protected override void InitialiseInDesignMode() { - AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", "")); - AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", "")); - AuthUrls.Add(new AuthServerCredentials("Test",["example.com"])); + + AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", "example.com")); + AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", "")); } //Real think @@ -225,6 +227,13 @@ public partial class AccountInfoViewModel : ViewModelBase { IsLogged = false; Credentials = null; + CurrentAuthServer = ""; + } + + public string GetServerAuthName(AuthTokenCredentials? credentials) + { + if (credentials is null) return ""; + return AuthUrls.FirstOrDefault(p => p.Servers.Contains(credentials.AuthServer))?.Name ?? "CustomAuth"; } private void UpdateAuthMenu() @@ -239,9 +248,13 @@ public partial class AccountInfoViewModel : ViewModelBase { var onDelete = new DelegateCommand(OnDeleteProfile); var onSelect = new DelegateCommand(AuthByProfile); + + var serverName = GetServerAuthName(credentials); var alpm = new ProfileAuthCredentials( credentials, + serverName, + ColorUtils.GetColorFromString(credentials.AuthServer), onSelect, onDelete); @@ -257,16 +270,18 @@ public partial class AccountInfoViewModel : ViewModelBase message.InfoText = LocalisationService.GetString("auth-config-read"); message.IsInfoClosable = false; PopupMessageService.Popup(message); + + AuthUrls.Clear(); + var authUrls = ConfigurationService.GetConfigValue(LauncherConVar.AuthServers)!; + foreach (var url in authUrls) AuthUrls.Add(url); + if(authUrls.Length > 0) AuthItemSelect = authUrls[0]; + foreach (var profile in ConfigurationService.GetConfigValue(LauncherConVar.AuthProfiles)!) AddAccount(profile); if (Accounts.Count == 0) UpdateAuthMenu(); - - AuthUrls.Clear(); - var authUrls = ConfigurationService.GetConfigValue(LauncherConVar.AuthServers)!; - foreach (var url in authUrls) AuthUrls.Add(url); - if(authUrls.Length > 0) AuthItemSelect = authUrls[0]; + message.Dispose(); DoCurrentAuth(); @@ -347,4 +362,18 @@ public partial class AccountInfoViewModel : ViewModelBase ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles, Accounts.Select(a => a.Credentials).ToArray()); } +} + +public static class ColorUtils +{ + public static Color GetColorFromString(string input) + { + var hash = MD5.HashData(Encoding.UTF8.GetBytes(input)); + + var r = byte.Clamp(hash[0], 10, 200); + var g = byte.Clamp(hash[1], 10, 100); + var b = byte.Clamp(hash[2], 10, 100); + + return Color.FromArgb(Byte.MaxValue, r, g, b); + } } \ No newline at end of file diff --git a/Nebula.Launcher/Views/Pages/AccountInfoView.axaml b/Nebula.Launcher/Views/Pages/AccountInfoView.axaml index f708cb9..2ce936b 100644 --- a/Nebula.Launcher/Views/Pages/AccountInfoView.axaml +++ b/Nebula.Launcher/Views/Pages/AccountInfoView.axaml @@ -1,6 +1,6 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + @@ -169,9 +186,15 @@ Margin="0,0,0,20" Path="/Assets/svg/user.svg" />