/// <summary> /// Restores session or tries to establish a new one. /// Invokes <see cref="ConnectionSucceed"/> or <see cref="ConnectionFailed"/>. /// </summary> /// <returns></returns> public async Task <(bool success, string message)> ConnectAsync(string email, string password, bool create = false, string ip = "localhost", int p = 7350) { ipAddress = ip; port = p; try { session = await client.AuthenticateEmailAsync(email, password, create : create); account = await GetAccountAsync(); } catch (ApiResponseException ex) { ConnectionFailed?.Invoke(); return(false, ex.Message); } Debug.LogFormat("New user: {0}, {1}", session.Created, session); ConnectionSucceed?.Invoke(); if (session.Created) { NewAccountCreated?.Invoke(); } return(true, session.Created ? "Account created, connecting ..." : "Connecting"); }
/// <summary> /// Restores session or tries to establish a new one. /// Invokes <see cref="ConnectionSucceed"/> or <see cref="ConnectionFailed"/>. /// </summary> /// <returns></returns> public async Task <AuthenticationResponse> ConnectAsync(string username = null) { var response = await RestoreTokenAsync(username); switch (response) { case AuthenticationResponse.Authenticated: case AuthenticationResponse.UserInfoUpdated: ConnectionSucceed?.Invoke(); break; case AuthenticationResponse.NewAccountCreated: NewAccountCreated?.Invoke(); ConnectionSucceed?.Invoke(); break; case AuthenticationResponse.ErrorUsernameAlreadyExists: case AuthenticationResponse.ErrorInternal: ConnectionFailed?.Invoke(); break; default: Debug.LogError("Unhandled response received: " + response); break; } return(response); }
private void NewAccount_Add() { _commonSettings.Humans2.Add(NewAccount.Model); UpdateHumanPlayers(); HumanPlayer = NewAccount.Model; NewAccount = null; NewAccountCreated?.Invoke(); }
private void NewAccount_Edit() { var currentAccount = NewAccount.CurrentAccount; var newAccount = this.newAccount.Model; currentAccount.Name = newAccount.Name; currentAccount.IsMale = newAccount.IsMale; currentAccount.BirthDate = newAccount.BirthDate; currentAccount.Picture = newAccount.Picture; NewAccount = null; NewAccountCreated?.Invoke(); }