How to update room properties when a player is offline (iOS and Android)

Hi,

I am trying to solve the following case.
Two players have joined a room, and are playing a game.
Suddenly, one player goes offline, the other player is informed about this. Now, I do not want the second player to wait for the first one to re-join this game. Thus, I give him/ her the choice to quite the game. If this happens, the second player updates the room properties to inform the other player that he left the room.
Now, the first player re-joins the room, but, the room properties are not updated. When I call the method
[self.photonEngine getRoomProperties]

I have also used the callback
 (void) onRoomPropertiesChange:(NSDictionary*)changes

but, I get an empty dictionary. Which method do I need to call to force the photon client to fetch the latest properties of the room?

Thank you

Comments

  • Hi @Vasilis.
    Which method do I need to call to force the photon client to fetch the latest properties of the room?
    None.
    Room properties are updated automatically.
    If the first player does not receive them, then that means that they are not on the server either.
    There are two potential causes for this:
    a) The second client has never successfully set them in the first place (you could test with setting them in the second client while the first client is still inside the room and see if the first client can see them).
    b) The first client has not rejoined the same room, but just a new room with the same room name. If all clients have left the room for good, then the empty room will be deleted. If a client now tries to join it again and uses opJoinOrCreateRoom(), then it will just create a new room with the same name as the previous one. That new room won't have the properties that have been set for the old one. You can set the emptyRoomTTL on room creation to prevent empty rooms from getting immediately closed after the last player has left.
  • Hi @Kaiserludi,

    This is really strange. Today, I retested my code, and I do see the properties.
    Also, each room has many properties, some of which are updated in a game. Occasionally, I can not update them, but, today, I do not have this issue.
    Could it be that the values in the dictionary that I am creating is not string or number? But, NSValue objects?
  • Hi @Vasilis.

    NSValue instances as property values are fine provided that the value that they hold is one of the ones that are supported by Photons serialization.
    The property keys must be strings, though.

    If the value of a certain property is of an unsupported type, then sending that property would fail every time, not just occasionally.

    So maybe there is some property that is only occasionally part of an update and only on those occasions when it is part of it the update fails, but there are no occasions on which an update that includes that property goes through.
    You would just have to find out which property is the culprit here.

    You could add all your properties one at a time and see which updates go through and which don't.

    Also it makes sense to check that all your properties are of types that are supported by Photons serialization.
    See https://forum.photonengine.com/discussion/comment/53403 for an overview about the supported types.

    It is also a good idea if you assign an implementation of the EGBaseListener protocol to ListenerEGBase.Listener like mentioned on that link, as that way the Photon client can log an error when it stumbles upon some unsupported time.

Sign In or Register to comment.