Photon existing room joining and creating new if not existing room problem

Options
Hi
With using
"Photon Unity Networking
v1.64 Generated by Doxygen 1.8.7
Thu Nov 5 2015 15:48:10 "

Here facing a strange problem. There is already existing room and i am joining, 4 out of 5 works perfectly. But Some times it does not joins in available open room and also does not create new one when it gets fails.

1) Joining room using room properties : -
roomColor = "brown2";
roomLevel = "1";
JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable); 

public void JoinRandom(object color, object level, byte maxPlayers)
{
	PlayerIdLstInRoom.Clear ();
	Hashtable expectedCustomRoomProperties = new Hashtable()
	{
		{ "Color",color },
		{"Level", level }
	};
	PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, maxPlayers);
}	


2) Creating new One if existing room join Fails : -
void OnPhotonRandomJoinFailed()
{
room_Name = "Brown"; // Brown,yellow etc.
	room_Name +=Random.Range (0,999).ToString(); 
	CreateRoom (room_Name,(byte)MaxPlayerFromTable,roomColor,roomLevel); 
}
public void CreateRoom(string name, byte maxPlayers, object color, object level)
{
	Hashtable roomProps = new Hashtable() { { "Color", color }, { "Level", level } };
	string[] roomPropsInLobby = { "Color", "Level" };
	RoomOptions roomOptions = new RoomOptions();
	roomOptions.customRoomProperties = roomProps;
	roomOptions.customRoomPropertiesForLobby = roomPropsInLobby;
	roomOptions.maxPlayers = maxPlayers;
	PhotonNetwork.CreateRoom(name, roomOptions, TypedLobby.Default);
}

Please let me know where is i am wrong. I couldn't not trace error or bug for it.

Thank you

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Ajay_Bhojani,

    Could you please give us the error response (ReturnCode + DebugMessage) you're getting -if any- for the failed join and the failed create operations?
    It should be available from Unity console logs.
  • Ajay_Bhojani
    edited October 2016
    Options
    joinrandom failed, client stays on masterserver: OperationResponse 225: ReturnCode: 32760 (No match found). Parameters: {}.
    UnityEngine.Debug:LogError(Object)
    PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:125)
    NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:680)
    NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:876)
    ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:79)



    This is the last console log line when I am joining room and app getting hang. Is this PUN version Bug ? If yes then how to upgrade PUN with new one.

    Thank you
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    That NoRandomMatchFound error (32760) is "normal" and should be expected when there is no room found for the join operation you called. So you should decide if you want to automatically and implicitly create a new room or inform the user and ask for his manual intervention. It depends on how you want to do this but what I want to say that this is an error that you should handle in your code.

    However I don't see the error for the create room operation.
  • Ajay_Bhojani
    edited October 2016
    Options

    hi thanks for reply.
    when joining existing room, execution going on to the below code up to Debug.Log("7") and editor becomes irresponsible.


    roomColor = "brown2";
    roomLevel = "1";
    JoinRandom(roomColor,roomLevel,(byte)MaxPlayerFromTable);

    public void JoinRandom(object color, object level, byte maxPlayers)
    {
    Debug.Log ("5");
    Hashtable expectedCustomRoomProperties = new Hashtable()
    {
    { "Color",color },
    {"Level", level }
    };
    Debug.Log ("6");
    PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, maxPlayers);
    Debug.Log ("7");
    }

    - getting room property successfully.
    The console output of debug is displayed in screenshot:

    Hope this will help to understand.
  • Tobias
    Options
    What is your maxPlayers? Is it the same in all cases?

    If you say "even though a room is existing", it could be a problem if the client has been in the room before or if the room does not have space for another player.

    Can you send us a small repro case? Then we can have a look.
  • Yes Max player is always same right now.

    The flow is as Below :

    1) . Selecting room of two max player
    - It will Create room if room does not exist.
    - It will join an empty room using room properties which has max 2 player capacity.

    2) Same flow is for 4 player room :

    3) When Player leaves room I am also setting its room and player properties to null.

    4) It happen after 4 to 5 game player i.e : joining 2 player room successfully 4 to 5 times and attempting to join again.

    5) this case happens for 2,4 or 6 players as above.

    Here is code for joining, creating, creating room on failing :


    1# funtion to join or create room :
    public void JoinRoom() // Button event funtion to join or create room as per table
    {
    // loadingbarbox.SetActive (true);
    // preventscreen.SetActive (true);

    PlayerIdLstInRoom.Clear ();
    PlayerIdLst.Clear();
    Debug.Log ("1");
    if(Usercanplay == "ucanplay")
    {
    MaxPlayerFromTable = int.Parse(EventSystem.current.currentSelectedGameObject.transform.GetChild(0).GetComponent().text.ToString());
    room_Name = (EventSystem.current.currentSelectedGameObject.transform.name);
    int PlayerScore_ = PlayerPrefs.GetInt ("PlayerScore");
    Debug.Log ("2");

    switch(room_Name)
    {
    case "brown2":

    if(PlayerScore_ >= 0 )
    {
    roomColor = "brown2";
    roomLevel = "1";
    JoinRandom(roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "brown4":
    if(PlayerScore_ >= 0 )
    {
    roomColor = "brown4";
    roomLevel = "2";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "brown6":
    if(PlayerScore_ >= 0 )
    {
    roomColor = "brown6";
    roomLevel = "3";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Yellow2":
    if(PlayerScore_ >= 1700 )
    {
    roomColor = "Yellow2";
    roomLevel = "4";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Yellow4":
    if( PlayerScore_ >= 1700)
    {
    roomColor = "Yellow4";
    roomLevel = "5";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Yellow6":
    if( PlayerScore_ >= 1700)
    {
    roomColor = "Yellow6";
    roomLevel = "6";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Red2":
    if( PlayerScore_ >= 2000)
    {
    roomColor = "Red2";
    roomLevel = "7";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Red4":
    if( PlayerScore_ >= 2000)
    {
    roomColor = "Red4";
    roomLevel = "7";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Red6":
    if( PlayerScore_ >= 2000)
    {
    roomColor = "Red6";
    roomLevel = "9";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Blue2":
    if( PlayerScore_ >= 2500)
    {
    roomColor = "Blue2";
    roomLevel = "10";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Blue4":
    if( PlayerScore_ >= 2500)
    {
    roomColor = "Blue4";
    roomLevel = "11";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    case "Blue6":
    if( PlayerScore_ >= 2500)
    {
    roomColor = "Blue6";
    roomLevel = "12";
    JoinRandom (roomColor,roomLevel,(byte)MaxPlayerFromTable);
    }
    break;
    default:
    Debug.Log("Room Joining in Default case ");
    break;
    }
    }
    else
    {
    Debug.Log ("string value"+Usercanplay.ToString());
    // Usercanplay = "";
    PurchasePopUpObj.SetActive(true);
    Debug.Log ("you cant play game");
    loadingbarbox.SetActive (false);
    preventscreen.SetActive (false);
    }
    }


    2# Create Room

    public void CreateRoom(string name, byte maxPlayers, object color, object level)
    {
    Hashtable roomProps = new Hashtable() { { "Color", color }, { "Level", level } };
    string[] roomPropsInLobby = { "Color", "Level" };
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.customRoomProperties = roomProps;
    roomOptions.customRoomPropertiesForLobby = roomPropsInLobby;
    roomOptions.maxPlayers = maxPlayers;
    PhotonNetwork.CreateRoom(name, roomOptions, TypedLobby.Default);
    }

    3# Join Random room :
    public void JoinRandom(object color, object level, byte maxPlayers)
    {
    Hashtable expectedCustomRoomProperties = new Hashtable()
    {
    { "Color",color },
    {"Level", level }
    };
    PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, maxPlayers);
    Debug.Log ("7");
    }

    4# Onphotonroom join fail :

    void OnPhotonRandomJoinFailed()
    {
    Debug.Log ("8");
    room_Name += Random.Range (0,999).ToString();
    CreateRoom (room_Name,(byte)MaxPlayerFromTable,roomColor,roomLevel);
    }


  • Ajay_Bhojani
    edited October 2016
    Options
    Hi here is a main network manager script:

    it has joinrandom, joinroom, createroom function etc network related functions.

    http://s000.tinyupload.com/index.php?file_id=7610161194713574540

    I am unable to trace other log as unity editor or installed app in getting hang when i am trying to join.

    Is it memory related issue ? or some network issue ?

    Thank you


  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    this simple code using your methods works fine, I can't debug anything not Photon related