PhotonNetwork.LeaveRoom and disconnect all clients

Dear professionals!
is it possible to call PhotonNetwork.LeaveRoom() on the master client and let the other clients also leave the room to close the room? Instead of using PhotonNetwork.Disconnect().
If we use PhotonNetwork.Disconnect(), sometimes, I can't connect to the master server, but I noticed that if I call PhotonNetwork.LeaveRoom(), I was able to connect to the Master server again and the error won't happen.
But when I call PhotonNetwork.LeaveRoom() on the master client, the master client changes and the other client becomes a new master client. But I don't want to change the master client and if the master client left the room, the other clients also need to left the room.
Please kindly let me know the best solution
Thanks

Best Answer

  • JohnTubeJohnTube mod
    edited May 16 Accepted Answer
    Hi @sweetmei25,

    What you could do is, from MasterClient:

    - Set CurrentRoom.IsOpen = false, CurrentRoom.IsVisible = false CurrentRoom.PlayerTtl= 0 and CurrentRoom.EmptyRoomTtl = 0.
    - Send a "disconnect even" to all CACHED (or buffered RPC), raiseEventOptions.CachingOption = CachingOption.AddToRoomCache or raiseEventOptions.CachingOption = CachingOption.AddToRoomCacheGlobal, this way when the actor who is in the background or inactive will leave as soon as joined to the room if that happens.
    - Leave the room.

    Otherwise, your only options are server side via custom plugin or custom app. code.

Answers

  • use RPC,call it from the master, them all players will leave
  • Well. then if a player goes to the background, he will not receive the RPC command.
  • JohnTubeJohnTube mod
    edited May 16 Accepted Answer
    Hi @sweetmei25,

    What you could do is, from MasterClient:

    - Set CurrentRoom.IsOpen = false, CurrentRoom.IsVisible = false CurrentRoom.PlayerTtl= 0 and CurrentRoom.EmptyRoomTtl = 0.
    - Send a "disconnect even" to all CACHED (or buffered RPC), raiseEventOptions.CachingOption = CachingOption.AddToRoomCache or raiseEventOptions.CachingOption = CachingOption.AddToRoomCacheGlobal, this way when the actor who is in the background or inactive will leave as soon as joined to the room if that happens.
    - Leave the room.

    Otherwise, your only options are server side via custom plugin or custom app. code.
Sign In or Register to comment.