Best practices for "reserve slot leftovers"? +Clarifications?

Options
Let's say group A (3/6) leaves their group to follow their leader into a public room. The leader joins or creates a random room and joins with another 3 people, with 3 slots left (3/6). Together, they would be full.

Now, when group A joins group B, there will be reserved slots for the incoming 3.
  1. What happens if 1 of these players didn't make it? They will have a reserved slot forever, right? They will linger at 5/6, with no 6th ever being able to join?
  2. When a user joins that has a reserved slot, the reservation clears automatically, right?
  3. I saw I can clear reserved slots, but not quite sure the best way to handle this. Perhaps the master can clear every 10~15 seconds, but it would be unfortunate if it clears 1 second before new reservations just come in. What is the best way to clear this?
  4. Is there a "reservation timeout"? That would be super ideal, unless someone has a better out-of-box answer~
Thanks~

Best Answer

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited November 2017 Answer ✓
    Options
    Hi @xblade724,

    1. yes the room is full unless you remove the reserved slot(s) of the player(s) who left.
    2. no. but you can do it manually.
    3. manually as it depends on your game logic. check snippet below.
    4. no. also depends on game logic. you can add it manually as well.

    Talk is cheap, here is the code:

        public void AddExpectedUser(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return;
            }
            if (!PhotonNetwork.inRoom)
            {
                return;
            }
            if (null != PhotonNetwork.room.ExpectedUsers && PhotonNetwork.room.ExpectedUsers.Contains(userId))
            {
                return;
            }
            List<string> list = new List<string>(PhotonNetwork.room.ExpectedUsers);
            list.Add(userId);
            PhotonNetwork.room.SetExpectedUsers(list.ToArray());
        }
    
        public void RemoveExpectedUser(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return;
            }
            if (!PhotonNetwork.inRoom)
            {
                return;
            }
            if (null == PhotonNetwork.room.ExpectedUsers || !PhotonNetwork.room.ExpectedUsers.Contains(userId))
            {
                return;
            }
            List<string> list = new List<string>(PhotonNetwork.room.ExpectedUsers);
            list.Remove(userId);
            PhotonNetwork.room.SetExpectedUsers(list.ToArray());
        }
        

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited November 2017 Answer ✓
    Options
    Hi @xblade724,

    1. yes the room is full unless you remove the reserved slot(s) of the player(s) who left.
    2. no. but you can do it manually.
    3. manually as it depends on your game logic. check snippet below.
    4. no. also depends on game logic. you can add it manually as well.

    Talk is cheap, here is the code:

        public void AddExpectedUser(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return;
            }
            if (!PhotonNetwork.inRoom)
            {
                return;
            }
            if (null != PhotonNetwork.room.ExpectedUsers && PhotonNetwork.room.ExpectedUsers.Contains(userId))
            {
                return;
            }
            List<string> list = new List<string>(PhotonNetwork.room.ExpectedUsers);
            list.Add(userId);
            PhotonNetwork.room.SetExpectedUsers(list.ToArray());
        }
    
        public void RemoveExpectedUser(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return;
            }
            if (!PhotonNetwork.inRoom)
            {
                return;
            }
            if (null == PhotonNetwork.room.ExpectedUsers || !PhotonNetwork.room.ExpectedUsers.Contains(userId))
            {
                return;
            }
            List<string> list = new List<string>(PhotonNetwork.room.ExpectedUsers);
            list.Remove(userId);
            PhotonNetwork.room.SetExpectedUsers(list.ToArray());
        }