2023-03-15 19:34:29 -04:00
|
|
|
|
using Aki.Launcher.Models.Aki;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
using Aki.Launcher.Helpers;
|
|
|
|
|
using Aki.Launcher.Models.Launcher;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using Splat;
|
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Aki.Launcher.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class ConnectServerViewModel : ViewModelBase
|
|
|
|
|
{
|
|
|
|
|
private bool noAutoLogin = false;
|
|
|
|
|
|
|
|
|
|
public ConnectServerModel connectModel { get; set; } = new ConnectServerModel()
|
|
|
|
|
{
|
|
|
|
|
InfoText = LocalizationProvider.Instance.server_connecting
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public ConnectServerViewModel(IScreen Host, bool NoAutoLogin = false) : base(Host)
|
|
|
|
|
{
|
|
|
|
|
noAutoLogin = NoAutoLogin;
|
|
|
|
|
|
|
|
|
|
this.WhenActivated((CompositeDisposable disposables) =>
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await ConnectServer();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ConnectServer()
|
|
|
|
|
{
|
2023-12-05 10:00:37 -05:00
|
|
|
|
if (!await ServerManager.LoadDefaultServerAsync(LauncherSettingsProvider.Instance.Server.Url))
|
|
|
|
|
{
|
|
|
|
|
connectModel.ConnectionFailed = true;
|
|
|
|
|
connectModel.InfoText = string.Format(LocalizationProvider.Instance.server_unavailable_format_1,
|
|
|
|
|
LauncherSettingsProvider.Instance.Server.Name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 19:25:33 +00:00
|
|
|
|
bool connected = ServerManager.PingServer();
|
|
|
|
|
|
|
|
|
|
connectModel.ConnectionFailed = !connected;
|
|
|
|
|
|
|
|
|
|
connectModel.InfoText = connected ? LocalizationProvider.Instance.ok : string.Format(LocalizationProvider.Instance.server_unavailable_format_1, LauncherSettingsProvider.Instance.Server.Name);
|
|
|
|
|
|
|
|
|
|
if (connected)
|
|
|
|
|
{
|
|
|
|
|
AkiVersion version = Locator.Current.GetService<AkiVersion>("akiversion");
|
|
|
|
|
|
|
|
|
|
version.ParseVersionInfo(ServerManager.GetVersion());
|
|
|
|
|
|
|
|
|
|
NavigateTo(new LoginViewModel(HostScreen, noAutoLogin));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RetryCommand()
|
|
|
|
|
{
|
|
|
|
|
connectModel.InfoText = LocalizationProvider.Instance.server_connecting;
|
|
|
|
|
|
|
|
|
|
connectModel.ConnectionFailed = false;
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await ConnectServer();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|