Kick out all players or close the room when the master client is disconnected
Options
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!
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!
0
Comments
-
Try PhotonNetwork.LeaveRoom() on OnMasterClientSwitched()1
-
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.1 -
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.0 -
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?0
-
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.
Hi John! I have one (I hope not so silly) question about CloseConnection() that I have not been able to answer reading the docs: when a Master Client uses CloseConnection to kick a player does this disconnect the player also from server (so they need to connect again)? Or does that just kicks them from the room?
Thanks!0