The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Room renaming, Unique room names and lobby room list sorting

troglodescu
2013-08-16 10:13:53

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

}[/code2] 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:

Ted Ted(1) Ted(2)

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 :)

Comments

carmine
2013-08-16 18:12:19

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... room.customProperties["gameType"].ToString()

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: http://quintet.us

Tobias
2013-08-19 14:23:03

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.

Back to top