Search Unity

Third Party Get Custom room properties in Lobby (PUN2)

Discussion in 'Multiplayer' started by SebGM2019, Nov 29, 2018.

  1. SebGM2019

    SebGM2019

    Joined:
    Aug 3, 2018
    Posts:
    34
    I want to get the properties of a room when I'm in lobby. I'm sure that the properties are setted to show on lobby with adding a string to it. But, at the moment to get this properties instantiating with the RoomInfo class, it seems to be empty.
    This is the code I use to create a new room:
    Code (CSharp):
    1.  if (IF.text.Length > 0 && IF.text.Length <= 20)
    2.         {
    3.             int PlayerAmount = Int32.Parse(PlayerField.text);
    4.             RoomOptions roompos = new RoomOptions()
    5.              {
    6.                 IsVisible = true, IsOpen = true, MaxPlayers = (byte)PlayerAmount
    7.              };
    8.             roompos.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable();
    9.             roompos.CustomRoomProperties.Add("OnlineArray", BehaviourModel.OnlineArray);
    10.             roompos.CustomRoomProperties.Add("PlayerLock", ScoreScript.PlayerLock);
    11.             roompos.CustomRoomProperties.Add("PlayerDic", WinPanelS.PlayerDic);
    12.             if (!PrivacyB.Privacy)
    13.             {
    14.                 if (PI.text.Length > 5)
    15.                 {
    16.                     Password = PI.text;
    17.                     roompos.CustomRoomProperties.Add("Password", Password);
    18.                     HavePass = true;
    19.                 }
    20.                 else
    21.                 {
    22.                  
    23.                     A.Play();
    24.                 }
    25.             }
    26.             else
    27.             {
    28.                 roompos.CustomRoomProperties.Add("Password", null);
    29.             }
    30.             string[] Property = new string[] { "Password" };
    31.             roompos.CustomRoomPropertiesForLobby = Property;
    32.             PhotonNetwork.CreateRoom(IF.text, roompos);
    33.             PhotonNetwork.CurrentRoom.SetPropertiesListedInLobby(Property);
    And this is the code to get them:
    Code (CSharp):
    1.  
    2. RoomName = T.text;
    3.        Has.Add("Password", CreateRoomS.Password);
    4.        R = new RoomInfo(RoomName,);
    5.        if (R.CustomProperties["Password"] == null)
    6.        {
    7.           PhotonNetwork.JoinRoom(T.text);
    8.        }
    9.        else
    10.        {
    11.            Password = (string)R.CustomProperties["Password"];
    12.            Protector.GetComponent<Animator>().SetBool("Show", true);
    13.            LockPanel.GetComponent<Animator>().SetBool("Show", true);
    14.            IsByB = true;
    15.        }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Just noticed this a bit late.

    Be aware that the "Password" field will be "plain text" and not really secure. Much less, if you send it to the lobby as property. This is probably not what your players will be aware of.

    Overall, we would like to avoid using the room listing as much as possible. If a game has a password, it should maybe not even be listed. You can put rooms with password into their own lobby. Maybe players should know room name and password. If they may know the room name, then let users enter both and you won't have to fetch the room list in the first place.
     
  3. xrjguajardo

    xrjguajardo

    Joined:
    Jan 25, 2014
    Posts:
    3
    I have a similar problem.... I'm creating a room using the method:

    LoadBalancingClient.OpCreateRoom(EnterRoomParams params);


    this is my code:

    Code (CSharp):
    1.  public void CreateRoomWithOptions(string name, RoomOptions options)
    2.     {
    3.         EnterRoomParams enterRoomParams = new EnterRoomParams();
    4.  
    5.         RoomOptions roomOptions = options;
    6.         roomOptions.IsVisible = true;
    7.         roomOptions.IsOpen = true;
    8.         enterRoomParams.Lobby = typedLobby;
    9.         enterRoomParams.RoomName = name;
    10.         enterRoomParams.RoomOptions = roomOptions;
    11.      
    12.         OpCreateRoom(enterRoomParams);
    13.      
    14.  
    15.     }
    then I try to retrieve the information sent as part of RoomOptions:


    Code (CSharp):
    1. public void UpdateRoomList(List<RoomInfo> roomList, GameRoomMode mode)
    2.   {
    3.         int indexDataDisplayed = 0;
    4.         for (int x = 0; x < roomList.Count; x++)
    5.         {
    6.            string mGameMode= roomList[x].CustomProperties[NetworkManager.roomGameMode].ToString();
    7. //more code....
    8.          }
    9. }
    but CustomProperties is always null... I can confirm that the first room that I get in the list is in fact the one that I have created in another client (at least the name of the room is the same)

    Am I doing something wrong?

    Edit:

    If I access this property "networkManager.Client.CurrentRoom.CustomProperties" within the client that has created the room, the CustomProperties are displayed correctly.

    Regards
     
    Last edited: Dec 14, 2018
  4. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    429

    Hi,

    you need to elect custom properties to be visible in the lobby, else they are considered private ( and saves bandwidth at the same time)

    can you check this post: https://forum.photonengine.com/discussion/6987/how-to-use-setpropertieslistedinlobby-correctly

    and this doc: https://doc-api.photonengine.com/en...1_room.html#a13b57b1c202611850ca81bb504ee0843

    Bye,

    Jean
     
    BentelAnnR likes this.