diff --git a/.idea/.idea.Nebula/.idea/avalonia.xml b/.idea/.idea.Nebula/.idea/avalonia.xml index 5a43723..3173589 100644 --- a/.idea/.idea.Nebula/.idea/avalonia.xml +++ b/.idea/.idea.Nebula/.idea/avalonia.xml @@ -33,6 +33,7 @@ + diff --git a/Nebula.Launcher/Assets/lang/en-US.ftl b/Nebula.Launcher/Assets/lang/en-US.ftl index 4384ab8..76704c8 100644 --- a/Nebula.Launcher/Assets/lang/en-US.ftl +++ b/Nebula.Launcher/Assets/lang/en-US.ftl @@ -25,6 +25,8 @@ account-auth-button = Authenticate account-auth-save = Save Profile account-auth-hello = Hello, account-auth-logout = Log out +auth-current-login-name = Current login: {$login} +auth-current-login-no-name = Profile not selected auth-processing = Processing authentication request... auth-error = An authentication error has occurred. @@ -45,6 +47,7 @@ config-remove-content-all = Remove all content filter-roleplay = Roleplay filter-language = Language favorite-add = Add to favorites +popup-add-favorite-invalid-ip = Please enter a valid IP servername-set = Set server name servername-clear = Clear server name twofa-enabled = You have two-factor authentication enabled. Please enter the code. @@ -56,4 +59,10 @@ serverentry-map = Map serverentry-preset = Preset content-view-server = Server url -content-view-path = Path \ No newline at end of file +content-view-path = Path + +popup-login-credentials-warning = Warning! No credentials provided! +popup-login-credentials-warning-label = Warning! No credentials provided! The servers will not be able to let you in due to lack of authorization. Please keep this in mind. +popup-login-credentials-warning-go-auth = Go to auth page +popup-login-credentials-warning-cancel = Cancel +popup-login-credentials-warning-proceed = Proceed diff --git a/Nebula.Launcher/Assets/lang/ru-RU.ftl b/Nebula.Launcher/Assets/lang/ru-RU.ftl index 1974406..2ce9f05 100644 --- a/Nebula.Launcher/Assets/lang/ru-RU.ftl +++ b/Nebula.Launcher/Assets/lang/ru-RU.ftl @@ -25,6 +25,8 @@ account-auth-button = Аутентифицировать account-auth-save = Сохранить профиль account-auth-hello = Привет, account-auth-logout = Выйти +auth-current-login-name = Текущий профиль: {$login} +auth-current-login-no-name = Профиль не выбран auth-processing = Обработка запроса аутентификации... auth-error = Произошла ошибка аутентификации. @@ -45,6 +47,7 @@ config-remove-content-all = Удалить весь контент filter-roleplay = Ролевая игра filter-language = Язык favorite-add = Добавить в избранное +popup-add-favorite-invalid-ip = Пожалуйста, введите валидный адрес servername-set = Установить имя сервера servername-clear = Очистить twofa-enabled = У вас включена двухфакторная аутентификация. Введите код. @@ -56,4 +59,10 @@ serverentry-map = Карта serverentry-preset = Режим content-view-server = Сервер -content-view-path = Путь \ No newline at end of file +content-view-path = Путь + +popup-login-credentials-warning = Предупреждение! Учетные данные не указаны! +popup-login-credentials-warning-label = Предупреждение! Учетные данные не указаны! Серверы не смогут пропустить вас из-за отсутствия авторизации. Пожалуйста, имейте это в виду. +popup-login-credentials-warning-go-auth = Перейти на страницу авторизации +popup-login-credentials-warning-cancel = Отмена +popup-login-credentials-warning-proceed = Продолжить \ No newline at end of file diff --git a/Nebula.Launcher/Services/LocalisationService.cs b/Nebula.Launcher/Services/LocalisationService.cs index b00f29f..2febf37 100644 --- a/Nebula.Launcher/Services/LocalisationService.cs +++ b/Nebula.Launcher/Services/LocalisationService.cs @@ -51,16 +51,15 @@ public partial class LocalisationService Initialise(); } - public static string GetString(string locale) + public static string GetString(string locale, Dictionary? options = null) { if (_currentMessageContext is null) { - Console.WriteLine("ERROR SHIT BITHC!"); return locale; } var message = _currentMessageContext.GetMessage(locale); if (message == null) return locale; - return _currentMessageContext.Format(message, new Dictionary()); + return _currentMessageContext.Format(message, options ?? []); } } diff --git a/Nebula.Launcher/ViewModels/MainViewModel.cs b/Nebula.Launcher/ViewModels/MainViewModel.cs index 3edc130..ac8d020 100644 --- a/Nebula.Launcher/ViewModels/MainViewModel.cs +++ b/Nebula.Launcher/ViewModels/MainViewModel.cs @@ -41,7 +41,17 @@ public partial class MainViewModel : ViewModelBase [ObservableProperty] private bool _popup; [ObservableProperty] private ListItemTemplate? _selectedListItem; + public bool IsLoggedIn => AuthService.SelectedAuth is not null; + public string LoginName => AuthService.SelectedAuth?.Login ?? string.Empty; + + public string LoginText => Services.LocalisationService.GetString("auth-current-login-name", + new Dictionary + { + { "login", LoginName } + }); + [GenerateProperty] private LocalisationService LocalisationService { get; } + [GenerateProperty] private AuthService AuthService { get; } [GenerateProperty] private DebugService DebugService { get; } = default!; [GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!; [GenerateProperty] private ContentService ContentService { get; } = default!; @@ -136,6 +146,12 @@ public partial class MainViewModel : ViewModelBase CurrentPage = obj; } + public void InvokeChangeAuth() + { + OnPropertyChanged(nameof(IsLoggedIn)); + OnPropertyChanged(nameof(LoginText)); + } + public void PopupMessage(PopupViewModelBase viewModelBase) { if (CurrentPopup == null) @@ -163,6 +179,11 @@ public partial class MainViewModel : ViewModelBase Popup = true; } + public void OpenAuthPage() + { + RequirePage(); + } + public void OpenLink() { Helper.OpenBrowser("https://durenko.tatar/nebula"); diff --git a/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs b/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs index 8d183c8..3885f26 100644 --- a/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs +++ b/Nebula.Launcher/ViewModels/Pages/AccountInfoViewModel.cs @@ -142,6 +142,7 @@ public partial class AccountInfoViewModel : ViewModelBase try { await a(); + ViewHelperService.GetViewModel().InvokeChangeAuth(); } catch (AuthException e) { @@ -200,6 +201,7 @@ public partial class AccountInfoViewModel : ViewModelBase { IsLogged = false; AuthService.ClearAuth(); + ViewHelperService.GetViewModel().InvokeChangeAuth(); } private void UpdateAuthMenu() diff --git a/Nebula.Launcher/ViewModels/Popup/AddFavoriteViewModel.cs b/Nebula.Launcher/ViewModels/Popup/AddFavoriteViewModel.cs index f7b1fc2..a895a71 100644 --- a/Nebula.Launcher/ViewModels/Popup/AddFavoriteViewModel.cs +++ b/Nebula.Launcher/ViewModels/Popup/AddFavoriteViewModel.cs @@ -42,6 +42,9 @@ public partial class AddFavoriteViewModel : PopupViewModelBase { try { + if(string.IsNullOrWhiteSpace(IpInput)) + throw new Exception(LocalisationService.GetString("popup-add-favorite-invalid-ip")); + var uri = IpInput.ToRobustUrl(); FavoriteServerListProvider.AddFavorite(uri); Dispose(); diff --git a/Nebula.Launcher/ViewModels/Popup/IsLoginCredentialsNullPopup.cs b/Nebula.Launcher/ViewModels/Popup/IsLoginCredentialsNullPopup.cs new file mode 100644 index 0000000..8dd429b --- /dev/null +++ b/Nebula.Launcher/ViewModels/Popup/IsLoginCredentialsNullPopup.cs @@ -0,0 +1,50 @@ +using Nebula.Launcher.Services; +using Nebula.Launcher.ViewModels.Pages; +using Nebula.Launcher.Views.Popup; +using Nebula.Shared.Services; +using Nebula.Shared.ViewHelper; + +namespace Nebula.Launcher.ViewModels.Popup; + +[ConstructGenerator, ViewModelRegister(typeof(IsLoginCredentialsNullPopupView))] +public partial class IsLoginCredentialsNullPopupViewModel : PopupViewModelBase +{ + private ServerEntryModelView _entry; + + [GenerateProperty] public override PopupMessageService PopupMessageService { get; } + [GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } + + protected override void InitialiseInDesignMode() + { + } + + protected override void Initialise() + { + } + + public IsLoginCredentialsNullPopupViewModel WithServerEntry(ServerEntryModelView entryModelView) + { + _entry = entryModelView; + return this; + } + + public void Proceed() + { + _entry.RunInstanceIgnoreAuth(); + Dispose(); + } + + public void Cancel() + { + Dispose(); + } + + public void GotoAuthPage() + { + ViewHelperService.GetViewModel().RequirePage(); + Dispose(); + } + + public override string Title => LocalisationService.GetString("popup-login-credentials-warning"); + public override bool IsClosable => true; +} \ No newline at end of file diff --git a/Nebula.Launcher/ViewModels/ServerEntryModelView.cs b/Nebula.Launcher/ViewModels/ServerEntryModelView.cs index 724d490..a713177 100644 --- a/Nebula.Launcher/ViewModels/ServerEntryModelView.cs +++ b/Nebula.Launcher/ViewModels/ServerEntryModelView.cs @@ -47,7 +47,7 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis public LogPopupModelView CurrLog; public RobustUrl Address { get; private set; } - [GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!; + [GenerateProperty] private AuthService AuthService { get; } [GenerateProperty] private CancellationService CancellationService { get; } = default!; [GenerateProperty] private DebugService DebugService { get; } = default!; [GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!; @@ -163,11 +163,26 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis public void RunInstance() { CurrLog.Clear(); - Task.Run(RunInstanceAsync); + Task.Run(async ()=> await RunInstanceAsync()); } - private async void RunInstanceAsync() + public void RunInstanceIgnoreAuth() { + CurrLog.Clear(); + Task.Run(async ()=> await RunInstanceAsync(true)); + } + + private async Task RunInstanceAsync(bool ignoreLoginCredentials = false) + { + if (!ignoreLoginCredentials && AuthService.SelectedAuth is null) + { + var warningContext = ViewHelperService.GetViewModel() + .WithServerEntry(this); + + PopupMessageService.Popup(warningContext); + return; + } + using var loadingContext = ViewHelperService.GetViewModel(); loadingContext.LoadingName = "Loading instance..."; ((ILoadingHandler)loadingContext).AppendJob(); diff --git a/Nebula.Launcher/Views/MainView.axaml b/Nebula.Launcher/Views/MainView.axaml index ce1c21f..36cfac3 100644 --- a/Nebula.Launcher/Views/MainView.axaml +++ b/Nebula.Launcher/Views/MainView.axaml @@ -10,7 +10,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:models1="clr-namespace:Nebula.Launcher.Models"> + xmlns:models1="clr-namespace:Nebula.Launcher.Models" + xmlns:services="clr-namespace:Nebula.Launcher.Services"> @@ -120,7 +121,20 @@ https://durenko.tatar/nebula/ - + + + | + + diff --git a/Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml b/Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml new file mode 100644 index 0000000..b3a5aa5 --- /dev/null +++ b/Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml.cs b/Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml.cs new file mode 100644 index 0000000..94641fc --- /dev/null +++ b/Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace Nebula.Launcher.Views.Popup; + +public partial class IsLoginCredentialsNullPopupView : UserControl +{ + public IsLoginCredentialsNullPopupView() + { + InitializeComponent(); + } +} \ No newline at end of file