Check If Room Exists?

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

  • 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.
  • 11clock11clock
    edited October 2020
    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.
  • 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.
  • 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.
  • 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?
  • TobiasTobias admin
    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.
Sign In or Register to comment.