Implementation inconsistency in JoinRoom() and JoinOrCreateRoom()

Options
Hello world,
first post here. Hopefully this post doesn't break any (formatting) rules here, if so, please let me know.

Stumbling through the docs I was wondering:
Why is CreateRoom() and JoinOrCreateRoom() implemented differently?
In the first case, using CreateRoom()+JoinRoom(), when creating the room with CreateRoom() no parameter for the room is mandatory and a random room name + new customroomprops are generated by the server.
In the second case, using JoinOrCreateRoom(), a room name and customroomprops as parameters are mandatory.

Why? Can someone explain?
It doesn't make any sense to me and I'd love to use the server generated name option on JoinOrCreateRoom(), too.

Looking forward to your answers. Thanks in advance!

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @manuvr,

    Thank you for choosing Photon!

    Here are the differences between CreateRoom() and JoinOrCreateRoom():

    - internally they use/call different operations (CreateRoom vs. JoinRoom)
    - CreateRoom is meant to ask the server to create a room, if the server can't create one it will return an error. If the client does not provide a room name, the server will assign a GUID.
    - JoinOrCreateRoom is first a join room attempt: the client will ask the server to join a room by name. If the server can't find the room, the server will create one with the same name and using the room creation options specified in the call and sent in the operation request. This is meant as a shortcut and optimization, sending a single request to the server at once instead of the back and forth: JoinRoom (server returns GameDoesNotExist) + CreateRoom. Also this is useful to avoid race conditions when two clients are trying to join the same room at once: the first one will create the room and the second one will create it. Since this method could lead to a room creation, a room creation options are required (although default ones could be sent / reused). And because this method is initially a join room the room name is required.
    In the second case, using JoinOrCreateRoom(), a room name and customroomprops as parameters are mandatory.
    You can call JoinOrCreateRoom() with all parameters set to null (or default) except room name.
  • manuvr
    manuvr
    edited February 2021
    Options
    Thank you @JohnTube for your detailed reply!
    Good to know Photon is using UIDs internally for random generated room names, haven't looked that up yet. You
    also helped me to understand the specific use case for JoinOrCreateRoom(), as a way of avoiding race conditions when joining the same room.

    I just noticed: the method I'm missing as an consinstent extension to the current list of methods is indeed "JoinOrCreateRandomRoom()" with no parameters at all.
    That would be useful in some cases.
  • manuvr
    Options
    ...just found "ConnectAndJoinRandom" Script in UtilityScripts. Why not a similar function as part of the API?
  • Tobias
    Options
    Because it's good for prototyping but then you want to customize it. It is something that should be part of the project / game's logic, not the API. Also: There are error cases, which need to be handled.