Room renaming, Unique room names and lobby room list sorting

I'm using PUN and it works out great but I have some dark areas of knowledge about all it's functionality and I didn't seem to find any answers to these questions anywhere. Sorry if they seem trivial but it's very important to my game's networking functionality. Here are the questions:

1. Can I (and how) change the name of the room if the masterClient leaves it ? I name my rooms by my player's name so when the one who created the room leaves, I want the new masterClient to put his name on the room so people in the lobby will see the new masterClient name of the room instead of the one who just left. This is also bad because the masterCLient that left cannot create another online game because there is a name conflict.

I did this but it does not work:

[code2=csharp]void OnPhotonPlayerDisconnected(PhotonPlayer aPlayer)
//if the master client left, rename the room

if (PhotonNetwork.isMasterClient)
Debug.Log("must set name of the room " + LobbyMenu.PlayerName); = PlayerName;
PhotonNetwork.SetPlayerCustomProperties(new Hashtable() { { "playerLevel", playerLevel } });
This is good introduction to the next related question

2. I want to make sure there are no duplicate room names. My idea was that if two players have the same name, the room names will be sufixed with the order of room creation. Ex: there are 3 players named "Ted" that each created a room. The lobby should list somethig like this:


I don't know how to implement this at all since there is no function in PhotonNetwork to call to see if the room name is already present (or is there ?).
Is there a better way to do this, assuring uniqueness of room names ?

3. And last, thank God Thank you for reading this far and sorry for the long post :)
What's the best way to sort the list of available rooms in the lobby ? I want rooms to appear in the order of level closeness to the local player - so players are displayed rooms where the level is as close as possible to their own

if PhotonNetwork.GetRoomList() returns thousands of rooms, then brute force sorting every second seems very unproductive. I was thinking of processing for example 20 rooms at a time and like a sieve, keeping the best ones in a list and update that list every second or something. Any better ideas for doing this are greatly appreciated.

Thank you again for reading this,
You're a lifesaver (in advance) for answering this :)


  • carmine
    You can set properties for a room (that are broadcasted to the lobby) so you can make changes to the properties while in the room.

    Instead of naming the rooms by someone's name, use a GUID (guaranteed unique id)

    string roomName = "room_" + System.Guid.NewGuid().ToString();

    // this is the properties of the room you want to show in the lobby/roomlist (these are for my game)
    // My master client in the room will update the teams/players as people join and leave, I want to show how many people are on what time in the lobby so people know which to join...
    string[] propertyList = {"gameType", "playerList", "teamList"};

    // when you create a room, you can do something like this
    PhotonNetwork.CreateRoom(roomName, true, true, 64, null, propertyList);

    // As you're looping through rooms, you can do something like this...

    I wouldn't worry about "thousands of rooms" at this time if you're game isn't up and running yet...

    Check out my game Quintet if you get the chance:
  • Tobias
    Alternatively: When you create a room, pass null as name and the server will assign a guid and you save some work.
    Or you can come up with a unique room name by adding a timestamp to the user's ID. You could use the server's timestamp from the lib.

    For the case with thousands of rooms, we will soon make multiple lobbies available and you can separate players with those.
    Make sure to close rooms when they are in use and no one should join anymore. That keeps the room list tidy.