/// <summary> /// Logs into the master server as a guest. /// </summary> /// <param name="onSuccess">The callback to execute when the login is successful.</param> /// <param name="onError">The callback to execute when the login is not successful.</param> public void LoginAsGuest(Action onSuccess, Action <LoginError> onError) { onPlayerLoginSuccess = onSuccess; onPlayerLoginError = onError; var msg = new RequestPlayerLoginMessage(); msg.isAnonymous = true; networkClient.client.Send(AuthenticationNetworkProtocol.RequestPlayerLogin, msg); }
/// <summary> /// Logs the specified user into the master server. /// </summary> /// <param name="username">The username to log in with.</param> /// <param name="password">The password to log in with.</param> /// <param name="onSuccess">The callback to execute when the login is successful.</param> /// <param name="onError">The callback to execute when the login is not successful.</param> public void Login(string username, string password, Action onSuccess, Action <LoginError> onError) { onPlayerLoginSuccess = onSuccess; onPlayerLoginError = onError; var msg = new RequestPlayerLoginMessage(); msg.isAnonymous = false; msg.username = username; msg.password = password; networkClient.client.Send(AuthenticationNetworkProtocol.RequestPlayerLogin, msg); }
/// <summary> /// Checks if a new login into the master server is allowed. /// </summary> /// <param name="msg">Login information to check.</param> /// <returns>The response to send to the player trying to join the master server.</returns> protected virtual ResponsePlayerLoginMessage IsJoinAllowed(RequestPlayerLoginMessage msg) { var masterServer = baseServer as MasterServer; var responseMsg = new ResponsePlayerLoginMessage(); if (!msg.isAnonymous && baseServer.players.Find(x => x.name == msg.username) != null) { responseMsg.success = false; responseMsg.error = LoginError.UserAlreadyLoggedIn; } else if (masterServer.playerLimit && baseServer.players.Count >= masterServer.maxPlayers) { responseMsg.success = false; responseMsg.error = LoginError.ServerFull; } else { if (msg.isAnonymous) { if (!masterServer.allowGuests) { responseMsg.success = false; responseMsg.error = LoginError.AuthenticationRequired; } else { responseMsg.success = true; } } else { responseMsg.success = true; } } return(responseMsg); }