void login_after_register (){ LoginWithPlayFabRequest request = new LoginWithPlayFabRequest(); request.Username = username_text.text; request.Password = password_text.text; request.TitleId = PlayFabData.TitleId; PlayFabClientAPI.LoginWithPlayFab(request,login_after_register_successful,login_after_register_failed); }
private IEnumerator makeConnection() { PlayFabSettings.TitleId = "2071"; LoginWithPlayFabRequest request = new LoginWithPlayFabRequest() { TitleId = "2071", Username = "******", Password = "******" }; bool wait = true; Debug.Log("Tentando logar"); PlayFabClientAPI.LoginWithPlayFab(request, (result) => { wait = false; if (result.NewlyCreated) { Debug.Log("Merda criamos um novo usuario"); } else { Debug.Log("Login com sucesso"); } }, (error) => { wait = false; Debug.Log("Error logging in player"); Debug.Log(error.ErrorMessage); }); while (wait) { yield return null; } }
// if we are in "login" state, draw the login window on screen void OnGUI () { if (PlayFabGameBridge.gameState == 2) { if(PlayFabData.SkipLogin && PlayFabData.AuthKey != null){ PlayFabGameBridge.gameState = 3; } Time.timeScale = 0.0f; // pause everything while we show the UI Rect winRect = new Rect (0,0,playfabBackground.width, playfabBackground.height); winRect.x = (int) ( Screen.width * 0.5f - winRect.width * 0.5f ); winRect.y = (int) ( Screen.height * 0.5f - winRect.height * 0.5f ); yStart = winRect.y + 80; GUI.DrawTexture (winRect, playfabBackground); if (!isPassword) { errorLabel = invalidPassword; } else if (!returnedError) { errorLabel = ""; } GUI.Label (new Rect (winRect.x + 18, yStart -16, 120, 30), "<size=18>"+title+"</size>"); GUI.Label (new Rect (winRect.x + 18, yStart+25, 120, 20), userNameLabel); GUI.Label (new Rect (winRect.x + 18, yStart+50, 120, 20), passwordLabel); GUI.Label (new Rect (winRect.x + 18, yStart+73, 120, 20), errorLabel, errorLabelStyle); GUI.Label (new Rect (winRect.x +18, yStart +145, 120, 20), "OR"); userNameField = GUI.TextField (new Rect (winRect.x+130, yStart+25, 100, 20), userNameField); passwordField = GUI.PasswordField (new Rect (winRect.x+130, yStart+50, 100, 20), passwordField,"*"[0], 20); // if the player clicks "login" then initiate a login request to PlayFab if (GUI.Button (new Rect (winRect.x+18, yStart+100, 100, 30), "Login")||Event.current.Equals(Event.KeyboardEvent("[enter]"))) { if(userNameField.Length>0 && passwordField.Length>0) { returnedError = false; LoginWithPlayFabRequest request = new LoginWithPlayFabRequest(); request.Username = userNameField; request.Password = passwordField; request.TitleId = PlayFabData.TitleId; PlayFabClientAPI.LoginWithPlayFab(request,OnLoginResult,OnPlayFabError); } else { isPassword = false; } } // if the player wants to register a new account instead, flip to the "register" dialog if (GUI.Button(new Rect(winRect.x+18, yStart+175, 120, 20),"Register")) { PlayFabGameBridge.gameState = 1; } if (Input.mousePosition.x < winRect.x + winRect.width && Input.mousePosition.x > winRect.x && Screen.height - Input.mousePosition.y < winRect.y + winRect.height && Screen.height - Input.mousePosition.y > winRect.y){ Rect cursorRect = new Rect (Input.mousePosition.x,Screen.height-Input.mousePosition.y,cursor.width,cursor.height ); GUI.DrawTexture (cursorRect, cursor); } } }
/// <summary> /// Sends a loginrequest to playfab using username and password. /// </summary> /// <param name="username">The username of the account that is logging in.</param> /// <param name="password">The password of the account that is logging in.</param> public void LoginWithPlayfab(string username, string password) { LoginWithPlayFabRequest request = new LoginWithPlayFabRequest(); request.Username = username; request.Password = password; request.TitleId = PlayFabData.TitleId; PlayFabClientAPI.LoginWithPlayFab(request, OnLoginResult, OnPlayFabError); }
public void Login() { var loginRequest = new LoginWithPlayFabRequest() { TitleId = PlayFabSettings.TitleId, Username = LoginUsernameField.text, Password = LoginPasswordField.text }; PlayFabClientAPI.LoginWithPlayFab(loginRequest, (result) => { LoginRegisterSuccess(result.PlayFabId, result.SessionTicket); }, (error) => { LoginErrorText.text = error.ErrorMessage; LoginErrorText.gameObject.transform.parent.gameObject.SetActive(true); PlayFabErrorHandler.HandlePlayFabError(error); }); }
//Login to playfab/game public static void PlayFabLogin(string username, string password) { var loginRequest = new LoginWithPlayFabRequest() { TitleId = PlayFabSettings.TitleId, Username = username, Password = password }; PlayFabClientAPI.LoginWithPlayFab(loginRequest, (result) => { PlayFabDataStore.playFabId = result.PlayFabId; PlayFabDataStore.sessionTicket = result.SessionTicket; GetPhotonToken(); }, (error) => { PlayFabUserLogin.playfabUserLogin.Authentication(error.ErrorMessage.ToString().ToUpper(), 3); }); }
public IEnumerator makeLogin() { LoginWithPlayFabRequest request = new LoginWithPlayFabRequest() { TitleId = PlayFabSettings.TitleId, Username = username, Password = password }; wait = true; PlayFabClientAPI.LoginWithPlayFab(request, (result) => { if (result.NewlyCreated) { Debug.Log("Merda criamos um novo usuario"); Debug.Log("O que eu fazer agora ?"); } else { Debug.Log("Login com sucesso"); loginSuccesfull(result); } wait = false; }, (error) => { Debug.Log("Error logging in player"); loginFail(error); wait = false; }); while (wait) { yield return null; } }
/// <summary> /// Signs the user into the PlayFab account, returning a session identifier that can subsequently be used for API calls which require an authenticated user /// </summary> public static void LoginWithPlayFab(LoginWithPlayFabRequest request, LoginWithPlayFabCallback resultCallback, ErrorCallback errorCallback) { request.TitleId = PlayFabSettings.TitleId ?? request.TitleId; if(request.TitleId == null) throw new Exception ("Must be have PlayFabSettings.TitleId set to call this method"); string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings); Action<string,string> callback = delegate(string responseStr, string errorStr) { LoginResult result = null; PlayFabError error = null; ResultContainer<LoginResult>.HandleResults(responseStr, errorStr, out result, out error); if(error != null && errorCallback != null) { errorCallback(error); } if(result != null) { AuthKey = result.SessionTicket ?? AuthKey; if(resultCallback != null) { resultCallback(result); } } }; PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/LoginWithPlayFab", serializedJSON, null, null, callback); }
/// <summary> /// Signs the user into the PlayFab account, returning a session identifier that can subsequently be used for API calls which require an authenticated user /// </summary> public static void LoginWithPlayFab(LoginWithPlayFabRequest request, ProcessApiCallback<LoginResult> resultCallback, ErrorCallback errorCallback, object customData = null) { request.TitleId = request.TitleId ?? PlayFabSettings.TitleId; if (request.TitleId == null) throw new Exception("Must be have PlayFabSettings.TitleId set to call this method"); string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy); Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer) { ResultContainer<LoginResult>.HandleResults(requestContainer, resultCallback, errorCallback, LoginWithPlayFabResultAction); }; PlayFabHTTP.Post("/Client/LoginWithPlayFab", serializedJson, null, null, callback, request, customData); }
/// <summary> /// Signs the user into the PlayFab account, returning a session identifier that can subsequently be used for API calls which require an authenticated user /// </summary> public static async Task<PlayFabResult<LoginResult>> LoginWithPlayFabAsync(LoginWithPlayFabRequest request) { request.TitleId = PlayFabSettings.TitleId ?? request.TitleId; if(request.TitleId == null) throw new Exception ("Must be have PlayFabSettings.TitleId set to call this method"); object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/LoginWithPlayFab", request, null, null); if(httpResult is PlayFabError) { PlayFabError error = (PlayFabError)httpResult; if (PlayFabSettings.GlobalErrorHandler != null) PlayFabSettings.GlobalErrorHandler(error); return new PlayFabResult<LoginResult> { Error = error, }; } string resultRawJson = (string)httpResult; var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings); var resultData = serializer.Deserialize<PlayFabJsonSuccess<LoginResult>>(new JsonTextReader(new StringReader(resultRawJson))); LoginResult result = resultData.data; AuthKey = result.SessionTicket ?? AuthKey; return new PlayFabResult<LoginResult> { Result = result }; }
/// <summary> /// Function used to login an existing player with PlayFab. /// </summary> /// <param name="username">User's username</param> /// <param name="password">User's password</param> /// <param name="OnLoginCompletedCallback">Function to call after process ends</param> public void LoginWithPlayFab(string username, string password, ProjectDelegates.PlayFabLoginCallback OnLoginCompletedCallback) { this.OnLoginCompletedCallback = OnLoginCompletedCallback; PlayFabSettings.TitleId = playFabGameID; LoginWithPlayFabRequest request = new LoginWithPlayFabRequest(); request.Username = username; request.Password = password; request.TitleId = playFabGameID; PlayFabClientAPI.LoginWithPlayFab(request, OnLoginCompleted, OnLoginError); }
public void OnPlayFabRegisterSuccess (RegisterPlayFabUserResult result) { Debug.Log ("PlayFab Register Success"); Debug.Log (result.Username); LoginWithPlayFabRequest request = new LoginWithPlayFabRequest (); request.Username = username; request.Password = password; request.TitleId = PlayFabData.TitleId; PlayFabClientAPI.LoginWithPlayFab (request, OnPlayFabLoginSuccess, OnPlayFabError); }
private void OnGUI () { GUI.Label (ResizeGUI(new Rect (10, 10, 500, 30)), PhotonNetwork.connectionStateDetailed.ToString ()); if (!PhotonNetwork.connected) networkState = NetworkStates.NotLoggedIn; else if (PhotonNetwork.room == null) networkState = NetworkStates.InLobby; else if (PhotonNetwork.room != null) networkState = NetworkStates.InRoom; else networkState = NetworkStates.Unknown; // Network state machine switch (networkState) { case NetworkStates.NotLoggedIn: { /* if (GUI.Button (new Rect (10, 10, 150, 70), "Login to Facebook")) { FB.Login ("email", LoginCallback); } */ if (hasError) { StartCoroutine("waitForError"); GUIStyle myStyle = new GUIStyle (); myStyle.fontSize = 36; GUI.Label (ResizeGUI(new Rect (10, 50, 200, 20)), myErrorMessage, myStyle); } username = GUI.TextField (ResizeGUI(new Rect (10, 100, 200, 20)), username); email = GUI.TextField (ResizeGUI(new Rect (10, 130, 200, 20)), email); password = GUI.PasswordField (ResizeGUI(new Rect (10, 160, 200, 20)), password, '*'); if (GUI.Button (ResizeGUI(new Rect (10, 210, 150, 30)), "Create Account")) { audioManager.playClick(); RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest (); request.TitleId = PlayFabSettings.TitleId; request.Username = username; request.Email = email; request.Password = password; PlayFabClientAPI.RegisterPlayFabUser (request, OnPlayFabRegisterSuccess, OnPlayFabError); } if (GUI.Button (ResizeGUI(new Rect (10, 250, 150, 30)), "Login with Username")) { audioManager.playClick(); LoginWithPlayFabRequest request = new LoginWithPlayFabRequest (); request.Username = username; request.Password = password; request.TitleId = PlayFabData.TitleId; PlayFabClientAPI.LoginWithPlayFab (request, OnPlayFabLoginSuccess, OnPlayFabError); } if (GUI.Button (ResizeGUI(new Rect (10, 290, 150, 30)), "Login with Email")) { audioManager.playClick(); LoginWithEmailAddressRequest request = new LoginWithEmailAddressRequest(); request.Email = email; request.Password = password; request.TitleId = PlayFabData.TitleId; PlayFabClientAPI.LoginWithEmailAddress(request, OnPlayFabLoginSuccess, OnPlayFabError); } break; } case NetworkStates.InLobby: { if (joinedRoom) { GameObject board = GameObject.Find("Board"); Destroy(board); audioManager.source.Stop(); audioManager.loopMenuMusic(); background.SetActive(true); title.SetActive(true); turnManager.currentPlayer = 0; // resets game when you leave turnManager.gameOver = false; turnManager.gameStarted = false; turnManager.movesPerTurn = 2; GameObject go = GameObject.FindGameObjectWithTag ("Canvas"); ActionMenu actionMenu = (ActionMenu)go.transform.FindChild ("ActionMenu(Clone)").GetComponent<ActionMenu>(); actionMenu.DestroyActionMenu(); joinedRoom = false; } inRoom = false; createRoomName = GUI.TextField (ResizeGUI(new Rect (10, 110, 150, 30)), createRoomName); // Create game button if (GUI.Button (ResizeGUI(new Rect (10, 50, 150, 50)), "Create Game")) { audioManager.playClick(); Debug.Log ("room name = " + createRoomName); PhotonNetwork.CreateRoom (createRoomName, true, true, 5); } // Join existing game button if (roomsList != null) { for (int i = 0; i < roomsList.Length; i++) { if (GUI.Button (ResizeGUI(new Rect (10, 180 + (80 * i), 150, 70)), "Join " + roomsList [i].name)) { audioManager.playClick(); PhotonNetwork.JoinRoom (roomsList [i].name); } } } break; } case NetworkStates.InRoom: // in room so instantiate player { inRoom = true; GUILayout.Label ("Your name: " + PhotonNetwork.playerName + " - " + playfabUserID ); GUILayout.Label (PhotonNetwork.playerList.Length + " players in this room."); GUILayout.Label ("The others are:"); foreach (PhotonPlayer player in PhotonNetwork.otherPlayers) { GUILayout.Label (player.ToString ()); } if (GUI.Button (ResizeGUI(new Rect (10, 70, 150, 30)), "Leave")) { audioManager.playClick(); PhotonNetwork.LeaveRoom (); } break; } case NetworkStates.Unknown: { GUILayout.Label ("Unknown network state!"); break; } } if (PhotonNetwork.connected && !inRoom) { if (GUI.Button (ResizeGUI(new Rect (10, Screen.height - 70, 150, 30)), "Logout")) { audioManager.playClick(); if (FB.IsLoggedIn) FB.Logout (); PhotonNetwork.Disconnect (); } } }