Problem with PUN and Playfab
Options
Hi Team,
I'm using playfab and PUN, I have loggedin, get playfab userid and playfab photon token, but after that, i have error when create room:
Operation 227 failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: Failed to create game on https://9257.playfablogic.com/webhook/1/prod/xxxxxxxxxxxx/RoomCreated? : Error response ResultCode='2' Message='User not found'.
Here is my code after get playfab id and token
public void Connect() {
isConnecting = true;
if (PhotonNetwork.connected) {
showLog("Joining room...");
PhotonNetwork.JoinRandomRoom();
PhotonNetwork.JoinRandomRoom(null, (byte)4);
}
else {
showLog("Connecting...");
PhotonNetwork.ConnectUsingSettings(gameVersion);
}
}
I'm using playfab and PUN, I have loggedin, get playfab userid and playfab photon token, but after that, i have error when create room:
Operation 227 failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: Failed to create game on https://9257.playfablogic.com/webhook/1/prod/xxxxxxxxxxxx/RoomCreated? : Error response ResultCode='2' Message='User not found'.
Here is my code after get playfab id and token
public void Connect() {
isConnecting = true;
if (PhotonNetwork.connected) {
showLog("Joining room...");
PhotonNetwork.JoinRandomRoom();
PhotonNetwork.JoinRandomRoom(null, (byte)4);
}
else {
showLog("Connecting...");
PhotonNetwork.ConnectUsingSettings(gameVersion);
}
}
0
Comments
-
Hi @JohnTube
I'm configure Authentication URL: https://9257.playfabapi.com/photon/authenticate
What else?
Thank you0 -
You need to get a token from PlayFab then set AuthValues before calling connect.
It seems you are connecting anonymously. You can disable this behavior by unticking that option.0 -
I have set auth values. THis is my full code
using System.Collections; using System.Collections.Generic; using System.Linq; using Photon; using PlayFab; using PlayFab.ClientModels; using UnityEngine; using UnityEngine.UI; public class PhotonLauncher : PunBehaviour { private bool isConnecting; private string gameVersion = "1"; public Text txtProcess; public InputField txtName; private static string playerPrefNameKey = "PlayerName"; //playfab example private string _playFabPlayerIdCache; [Tooltip("The maximum number of players per room")] public byte maxPlayersPerRoom = 4; void Awake() { PhotonNetwork.autoJoinLobby = false; PhotonNetwork.automaticallySyncScene = true; } public void Connect() { isConnecting = true; if (PhotonNetwork.connected) { showLog("Joining room..."); PhotonNetwork.JoinRandomRoom(); PhotonNetwork.JoinRandomRoom(null, (byte)4); } else { showLog("Connecting..."); PhotonNetwork.ConnectUsingSettings(gameVersion); } } public void Start() { string defaultName = ""; if (PlayerPrefs.HasKey(playerPrefNameKey)) { defaultName = PlayerPrefs.GetString(playerPrefNameKey); txtName.text = defaultName; } PhotonNetwork.playerName = defaultName; } public void OnBtnConnect() { string name = txtName.text; PhotonNetwork.playerName = name + " "; PlayerPrefs.SetString(playerPrefNameKey, name); AuthenticateWithPlayFab(name); Connect(); } public void showLog(string message) { txtProcess.text = message; } public override void OnConnectedToMaster() { showLog("Connected to region: " + PhotonNetwork.networkingPeer.CloudRegion); if (isConnecting) { showLog("OnConnectedToMaster: Next -> try to Join Random Room"); Debug.Log("DemoAnimator/Launcher: OnConnectedToMaster() was called by PUN. Now this client is connected and could join a room.\n Calling: PhotonNetwork.JoinRandomRoom(); Operation will fail if no room found"); PhotonNetwork.JoinRandomRoom(); } } public override void OnPhotonRandomJoinFailed(object[] codeAndMsg) { showLog("<Color=Red>OnPhotonRandomJoinFailed</Color>: Next -> Create a new Room"); Debug.Log("DemoAnimator/Launcher:OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one.\nCalling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);"); PhotonNetwork.CreateRoom(null, new RoomOptions() { MaxPlayers = this.maxPlayersPerRoom }, null); } public override void OnDisconnectedFromPhoton() { showLog("<Color=Red>OnDisconnectedFromPhoton</Color>"); Debug.LogError("DemoAnimator/Launcher:Disconnected"); isConnecting = false; } public override void OnJoinedRoom() { showLog("<Color=Green>OnJoinedRoom</Color> with " + PhotonNetwork.room.PlayerCount + " Player(s)"); Debug.Log("DemoAnimator/Launcher: OnJoinedRoom() called by PUN. Now this client is in a room.\nFrom here on, your game would be running. For reference, all callbacks are listed in enum: PhotonNetworkingMessage"); if (PhotonNetwork.room.playerCount > 1) { PhotonNetwork.LoadLevel("GamePlay1"); } } public override void OnPhotonPlayerConnected(PhotonPlayer other) { Debug.Log("OnPhotonPlayerConnected() " + other.NickName); // not seen if you're the player connecting if (PhotonNetwork.isMasterClient) { Debug.Log("OnPhotonPlayerConnected isMasterClient " + PhotonNetwork.isMasterClient); // called before OnPhotonPlayerDisconnected if (PhotonNetwork.room.PlayerCount > 1) LoadArena(); } } void LoadArena() { if (!PhotonNetwork.isMasterClient) { Debug.LogError("PhotonNetwork : Trying to Load a level but we are not the master Client"); } Debug.Log("PhotonNetwork : Loading Level : " + PhotonNetwork.room.PlayerCount); PhotonNetwork.LoadLevel("GamePlay1"); } #region Playfab private void AuthenticateWithPlayFab(string text) { LogMessage("PlayFab authenticating using Custom ID..." + text); PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest() { CreateAccount = true, CustomId = text }, RequestPhotonToken, OnPlayFabError); } private void RequestPhotonToken(LoginResult obj) { LogMessage("PlayFab authenticated. Requesting photon token..."); //We can player PlayFabId. This will come in handy during next step _playFabPlayerIdCache = obj.PlayFabId; PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest() { PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppID }, AuthenticateWithPhoton, OnPlayFabError); } private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj) { LogMessage("ID: " + _playFabPlayerIdCache + " Photon token acquired: " + obj.PhotonCustomAuthenticationToken + " Authentication complete."); var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom }; customAuth.AddAuthParameter("username", _playFabPlayerIdCache); // expected by PlayFab custom auth service customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken); PhotonNetwork.AuthValues = customAuth; } private void OnPlayFabError(PlayFabError obj) { LogMessage(obj.GenerateErrorReport()); } public void LogMessage(string message) { Debug.Log("PlayFab + Photon Example: " + message); } #endregion }
0 -
It looks like you are connecting before setting authentication values.
Try movingConnect()
call until after getting token.
Something like this:public void OnBtnConnect() { string name = txtName.text; PhotonNetwork.playerName = name + " "; PlayerPrefs.SetString(playerPrefNameKey, name); AuthenticateWithPlayFab(name); } private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj) { LogMessage("ID: " + _playFabPlayerIdCache + " Photon token acquired: " + obj.PhotonCustomAuthenticationToken + " Authentication complete."); var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom }; customAuth.AddAuthParameter("username", _playFabPlayerIdCache); // expected by PlayFab custom auth service customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken); PhotonNetwork.AuthValues = customAuth; Connect(); }
1 -
Thank you, I resolved this problem0