Kick out all players or close the room when the master client is disconnected

Hi,
we're trying to make a product with a strict hierarchy in which the master client has special rights that the other users don't have. Because of this, we want to prevent PUN's default behaviour of switching the master client if the current master client leaves and instead close the room or force every other client in the room to leave as well and return to the lobby scene.

Is there a way to facilitate this? Are there callbacks I can make use of?

Thank you for your time!

Comments

  • OneManArmyOneManArmy ✭✭✭
    edited July 22
    Try PhotonNetwork.LeaveRoom() on OnMasterClientSwitched()
  • Hi @YannickAtTuring,

    Thank you for choosing Photon!

    The master client can try to do this before disconnecting (in OnApplicationPause or OnApplicationQuit):
    close the room PhotonNetwork.CurrentRoom.IsOpen = false (also if you change these values CurrentRoom.EmptyRoomTtl = 0, CurrentRoom.PlayerTtl = 0) & send PhotonNetwork.CloseConnection(player) to all other joined actors. Don't forget to send outgoing commands right away (see here).

    The other already joined actors can do as @OneManArmy suggested.

    If the room is not closed future actors may join so detect if original/initial master client (room creator) is there or not: MasterClient.ActorNumber != 1 and then leave the room.
  • Thank you @JohnTube - this already helps a lot. I didn't know about the ability to send right away. Very useful!

    As far as I understand, your solution covers cases in which the master client switches off the device or closes the software. Would this also cover cases in which the master client loses their internet connection? Should I just bet on OnMasterClientSwitched() for edge cases like this?

    Thanks again, I learned a lot from your reply.
  • Would this also cover cases in which the master client loses their internet connection? Should I just bet on OnMasterClientSwitched() for edge cases like this?
    Yes but this does not handle one edge case where the master client is not responsive and the server does not notice this for 10 seconds (timeout period). The only way to handle this is to implement a custom keep alive or heart beat logic in your game. You can search the forum to find out more about it.
Sign In or Register to comment.