How do you create multiple, long lived rooms similar to popular mobile chess games?


I'm exploring Photon and I'm struggling to find a way that I can create a matchmaking scenario that is similar to the online mobile experience. If you're unfamilar with that, consider this:
  • User taps "New Game"
  • User sets some options for that game
  • User taps "Create Game"
  • The user does not immediatly join the game (unless they have the first turn) because its asynchronous multiplayer and needs to wait until an opponent joins that game and takes the first turn.
  • A list of active games is displayed for the user to see
  • A User can repeat this multiple times to have multiple games going with different/similar options
I'm struggling to see how I can:
  1. Create multiple rooms per user at the same time
  2. Create empty rooms, or at least have the player joined in the room and actually participate in the game once an opponent is found
  3. Have the rooms/games live while an opponent is found (the user may close the app until a push notification is received that an opponent is ready/ their turn"
Thanks in advance for your advice!

Best Answer


  • edited February 2019
    It looks like I'm not the first person to ask about this type of flow. (here, here)

    After searching around additional similar posts and finding the Room Persistence guide, it seems like the scenario is almost possible. Here is what I understand right now; please share your advice if I'm correct.
    • There is nothing out of the box to do exactly what I described above
    • Rooms persistence is not handled end-to-end in Photon - the developer needs to save the room state when the room is closed and how that is done is left to the developer.
    • To help make it possible, the PathCreate and PathClosed hooks can be used. From there, the developer can load and save room state to a database, etc.
    What I'm missing is how to create a room that can sit until an opponent joins it and how to create multiple rooms for a user. Any tips on that?

    EDIT: I've had some more time to play with this and I think I'm closer. Here is what I am trying to do now:

    1. Join or Create a room
        string roomName = $"Room-{PhotonNetwork.LocalPlayer.UserId}";
                var roomOptions = new RoomOptions
                    MaxPlayers = 2,
                    PlayerTtl = -1,                
       PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, null);
    PathCreate webhook is called and loads my state and sends me the custom property data I may have saved before (re-joined).

    2. Set some custom room properties to test game state
        var properties = new Hashtable() { { "test", textToSave } };
        PhotonNetwork.CurrentRoom.SetCustomProperties(properties, null, new     WebFlags(WebFlags.SendSyncConst));
    3. Use takes their turn and I call PhotonNetwork.LeaveRoom(true);
    4. PathClose webhook is called and I save the state using the info in the CustomProperties

    I'm working out the kinks with the backend part of saving the data. I have two remaining questions:

    1. Does this look like the right flow and usage of PhotonNetwork?
    2. How should I store and sync the games a player has since there are no rooms to get a list of? (I am not 100% sure how to show an "active games" list on the client since their are no more rooms. I was thinking I would have to handle this myself and sync it somehow with my backend storage.)
  • edited February 2019
    Whelp, I typed out a long update and edit on this with my latest questions and the forums bugged out...

    If a mod is reading this, please see if you can recover my comment to this post. I used triple backticks (GitHub style) to indicate a code block and it broke the post; hidden or deleted. >:O

    EDIT: Thanks for fixing the comment above!
Sign In or Register to comment.