[C++ API] Cached Events and Master Client Disconnected

EON_YogiPrasida
edited June 2020 in Native
Hi,

Our logic does not depend on "host" or "master client". However we do make use of cached events. If I understand correctly, it is the responsibility of the master client to manage cached events. In the "Master Client and Host Migration" document:
Photon does not move player properties or cached events from one Master Client to another. Also Photon does not resend events meant to the old Master Client to the newly elected one.

This seem to make things overly complicated. We design our stuff to not depend on a master client (everyone's the same), but when someone who happens to be Photon's master client disconnected, we end up needing to handle it manually anyways (as I understand it). I was expecting the cached events are stored on the cloud so that we don't have to manage this by hand.

Note that in our case the disconnected master client will always try to return by calling reconnectAndRejoin() (it didn't purposely leave the room). I don't know if this makes any difference.

So, what is the common practices to have cached events still work when master client disconnected?

Thank you and best regards,
Yogi

Comments

  • By the way we're using the C++ API if that makes any difference. Platform is iOS, Android, Windows.
  • EON_YogiPrasida
    edited June 2020
    So, how do we handle this exactly?

    - How do we know if a master client gets disconnected? By checking in leaveRoomEventAction if the player is a master client?

    - What to do next? Force everyone to resend all their cached events again to be re-cached by the new master client?

    - How do we know if/when we have new master client?
  • Hi @EON_YogiPrasida.

    You are misunderstanding the docs.
    Cached events are cached on the server and not on the master client.
    The parts of the docs that you have quoted say that when you set player properties for player A or when you cache events for player A and that player A happens to be the master client and the time when you set the properties or cache the event, then those player properties and cached events DO NOT get assigned to a different player when player A should loose its master client role to that other player at a later point.
    I was expecting the cached events are stored on the cloud so that we don't have to manage this by hand.
    They are indeed stored on the cloud and you don't have to handle this by hand.
    So, what is the common practices to have cached events still work when master client disconnected?
    
    Note that when you cache events in the event cache for the player who has sent that event, then those cached events will be removed from the event cache, when that player leaves the room for good.

    However once the player has left the room for good (the player either left the room explicitly with opLeaveRoom() and with the 'willComeBack' parameter set to 'false' or his playerTtl ran out or no playerTtl has been set at all), it can't rejoin it anymore, so this should not matter in your scenario.

    If you need the cached events to stay in the cache even after their original sender has left the room for good, then store them in the global event cache of the room and not in the players event cache (use EventCache::ADD_TO_ROOM_CACHE_GLOBAL instead of EventCache::ADD_TO_ROOM_CACHE). That way the events stay in the cache for the lifetime of the room instead of the lifetime of their sender (unlesse you explicitly remove the events from the cache manually).

    Note that when a player only gets inactive and is still able to rejoin the room, then the event cache for that player still exists as well.

    Hence when after a disconnect you want your cached events to continue to exist for as long as you are still able to rejoin the room, then there is really nothing special that you need to pay attention to at all.

    When your cached events should continue to exist even when your player can't rejoin the room anymore, then add them to the global room cache.