Check If Room Exists?

The whole answer can be found below.

Please note: 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! And we offer you support through 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.

Check If Room Exists?

11clock
2020-10-29 05:22:34

I am having room names for my game be randomly generated (think Jackbox Party Pack or Among Us). I would like to make sure that the generated room name does not already exist on the server before trying to create the room. What is the best way to go about checking this?

Comments

JohnTube
2020-10-29 14:30:09

Hi @11clock,

Thank you for choosing Photon!

There is no way to check if a room exists.

What you could do is:

  • go ahead and try to create the room, if the room name already exists, an error GameAlreadyExists will be returned.
  • [not recommended] have rooms list and check against that list.

In fact we do not recommend this, you can let the server decide by passing null as room name and the server will generate a GUID as room name.

11clock
2020-10-29 18:21:19

@JohnTube wrote: »

Hi @11clock,

Thank you for choosing Photon!

There is no way to check if a room exists.

What you could do is:

  • go ahead and try to create the room, if the room name already exists, an error GameAlreadyExists will be returned.
  • [not recommended] have rooms list and check against that list.

In fact we do not recommend this, you can let the server decide by passing null as room name and the server will generate a GUID as room name.

Thanks! I think I will just go with the first suggestion and have it try a few times to make the chance of failure practically nonexistent.

I would rather not have the server generate the room name since I need the name to be something simple for users to type in. I am going for a short string of random letters.

Dave_A
2021-04-07 04:14:12

I would also like an elegant way of doing this. I need to have a 'room master' start the game. Players may attempt to join any time, meaning before or after the room master. Room master creates the room. So other players may get there beforehand, and I need to know if the room exists or not. if not, they'll wait in the lobby until the room master starts the game, then enter the room as soon as that happens.

JohnTube
2021-04-07 13:48:32

Hi @Dave_A,

Thank you for choosing Photon!

So you need one specific player to be the room creator and first master client?
If this is a hard constraint, you could make use of FindFriend to periodically poll if the player with a specific known UserID is inside a room or not and which room. (similar to team matchmaking)
Otherwise, you can allow any player to join or create a room if you want to use a specific room name via JoinOrCreateRoom.

Dave_A
2021-04-09 03:19:49

Thank you! What we have in mind is one person creates and runs a 'meeting' (the 'game' is something like AltspaceVR but for webGL). We don't want the 'meeting' (room) to start until the person that called the meeting 'arrives'. I suppose we could share out the meeting creator's user name. So as I understand it, guests could arrive, login, be in the Lobby, poll for 'meeting creator is in room' and then let them join the room?

Tobias
2021-04-09 12:27:59

You can join everyone into the room but keep them from anything but waiting until the organizer arrives. Polling does not scale well and we discourage that. Ofc, you could also implement your own REST service, which only hands out the room's name when the organizer set it up. This way, you can control who is getting access and more.

Back to top