question

jorichantzberg avatar image
jorichantzberg asked

Photon + playfab create room error,Photon + playfab can't create room

Hi,

I am actually develloping a video game and i try to implement the multplayer + save data

I decided to use photon to create room and it worked well until i tried to implement login system with play fab.

I followed some tutorials, forum and read docs but im actually stuck with an error that i can't resolve.

This is the error in unity : https://B1CBC.playfablogic.com/webhook/1/prod/{secretkey}/RoomCreated? : Error response ResultCode='2' Message='User not found'.

And this is my code :

using System.Collections;
using System.Collections.Generic;
using System.Net.Mime;
using Photon.Pun;
using Photon.Realtime;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.PfEditor.EditorModels;
using TMPro;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using UnityEngine.UI;
using LoginResult = PlayFab.ClientModels.LoginResult;
using PlayFabError = PlayFab.PlayFabError;
public class LoginRegister : MonoBehaviour
{
    public TextMeshProUGUI messagetext;
    public TextMeshProUGUI emailField;
    public TextMeshProUGUI passwordField;
    public TextMeshProUGUI usernameField;
    private string _playFabPlayerIdCache;

    public void RegisterButton()
    {
        if (passwordField.text.Length < 6)
        {
            messagetext.text = "Password too short !";
            return;
        }
        var request = new RegisterPlayFabUserRequest
        {
            //Username = usernameField.text,
            Email = emailField.text,
            Password = passwordField.text,
            RequireBothUsernameAndEmail = false
        };
        PlayFabClientAPI.RegisterPlayFabUser(request,OnRegisterSucces,OnError);
    }

    void OnRegisterSucces(RegisterPlayFabUserResult result)
    {
        messagetext.text = "Status : Registered !";
        LoginButton();
    }

    void OnError(PlayFabError result)
    {
        messagetext.text = "Status : " + result.ErrorMessage;
    }

    public void LoginButton()
    {
        var request = new LoginWithEmailAddressRequest
        {
            Email = emailField.text,
            Password = passwordField.text,
        };
        PlayFabClientAPI.LoginWithEmailAddress(request,RequestPhotonToken,OnError);
    }

    void RequestPhotonToken(LoginResult result)
    {
        
        messagetext.text = "Status : PlayFab authenticated. Requesting photon token...";
        _playFabPlayerIdCache = result.PlayFabId;
        PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest
        {
            PhotonApplicationId = "6f6b8d03-de23-4c5d-9099-de2e8f63fda7"
        }, AuthenticateWithPhoton, OnError);
    }

    void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult result)
    {
        messagetext.text = "Status : Photon token acquired! Authentication complete.";

        //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
        var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };
        //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
        customAuth.AddAuthParameter("username", _playFabPlayerIdCache);    // expected by PlayFab custom auth service

        //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
        customAuth.AddAuthParameter("token", result.PhotonCustomAuthenticationToken);

        //We finally tell Photon to use this authentication parameters throughout the entire application.
        PhotonNetwork.AuthValues = customAuth;
        Debug.Log(result);
    }

    public void ResetPassword()
    {
        var request = new SendAccountRecoveryEmailRequest
        {
            Email = emailField.text,
            TitleId = "B1CBC"
        };
        PlayFabClientAPI.SendAccountRecoveryEmail(request,OnPasswordReset,OnError);
    }

    void OnPasswordReset(SendAccountRecoveryEmailResult result)
    {
        messagetext.text = "Status : Recovery email sent !";
    }
    
}

If someone have an idea to resolve this, i would be interested. Thx

,

Hi,

I am actually creating a video game and implementing the multiplayer + save player state

I already use photon to create and join room and i waant to use playfab to save player's data.

I followed some tutorials and looked some forum / docs but i actually have an error and i dont find any solution

This is the error on unity : Failed to load state from https://B1CBC.playfablogic.com/webhook/1/prod/{secret key}/RoomCreated? : Error response ResultCode='2' Message='User not found'.

And the code :

using System.Collections;
using System.Collections.Generic;
using System.Net.Mime;
using Photon.Pun;
using Photon.Realtime;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.PfEditor.EditorModels;
using TMPro;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using UnityEngine.UI;
using LoginResult = PlayFab.ClientModels.LoginResult;
using PlayFabError = PlayFab.PlayFabError;
public class LoginRegister : MonoBehaviour
{
    public TextMeshProUGUI messagetext;
    public TextMeshProUGUI emailField;
    public TextMeshProUGUI passwordField;
    public TextMeshProUGUI usernameField;
    private string _playFabPlayerIdCache;

    public void RegisterButton()
    {
        if (passwordField.text.Length < 6)
        {
            messagetext.text = "Password too short !";
            return;
        }
        var request = new RegisterPlayFabUserRequest
        {
            //Username = usernameField.text,
            Email = emailField.text,
            Password = passwordField.text,
            RequireBothUsernameAndEmail = false
        };
        PlayFabClientAPI.RegisterPlayFabUser(request,OnRegisterSucces,OnError);
    }

    void OnRegisterSucces(RegisterPlayFabUserResult result)
    {
        messagetext.text = "Status : Registered !";
        LoginButton();
    }

    void OnError(PlayFabError result)
    {
        messagetext.text = "Status : " + result.ErrorMessage;
    }

    public void LoginButton()
    {
        var request = new LoginWithEmailAddressRequest
        {
            Email = emailField.text,
            Password = passwordField.text,
        };
        PlayFabClientAPI.LoginWithEmailAddress(request,RequestPhotonToken,OnError);
    }

    void RequestPhotonToken(LoginResult result)
    {
        
        messagetext.text = "Status : PlayFab authenticated. Requesting photon token...";
        _playFabPlayerIdCache = result.PlayFabId;
        PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest
        {
            PhotonApplicationId = "6f6b8d03-de23-4c5d-9099-de2e8f63fda7"
        }, AuthenticateWithPhoton, OnError);
    }

    void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult result)
    {
        messagetext.text = "Status : Photon token acquired! Authentication complete.";

        //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
        var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };
        //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
        customAuth.AddAuthParameter("username", _playFabPlayerIdCache);    // expected by PlayFab custom auth service

        //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
        customAuth.AddAuthParameter("token", result.PhotonCustomAuthenticationToken);

        //We finally tell Photon to use this authentication parameters throughout the entire application.
        PhotonNetwork.AuthValues = customAuth;
        Debug.Log(result);
    }

    public void ResetPassword()
    {
        var request = new SendAccountRecoveryEmailRequest
        {
            Email = emailField.text,
            TitleId = "B1CBC"
        };
        PlayFabClientAPI.SendAccountRecoveryEmail(request,OnPasswordReset,OnError);
    }

    void OnPasswordReset(SendAccountRecoveryEmailResult result)
    {
        messagetext.text = "Status : Recovery email sent !";
    }
    
}

If anyone have a solution , i'm interested thx

Authenticationphoton
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jorichantzberg avatar image
jorichantzberg answered

if someone have the same issue i just find the solution, i was connecting to the server before i authentificate so i had the error invalid user

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jorichantzberg avatar image
jorichantzberg answered

oops looks like i made a little misstake x)

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.