Application Closing - Kicking players out of room

Options
Hi all,

I haven't been able to figure this out yet, I may be looking at it the wrong way. Currently I save whoever is the MasterClient as Host within the room's custom property, as well as their photon player's custom property. If they leave via quitting the application (leaving ingame is no problem), the other players should be kicked out.

Initially I checked via PhotonNetwork.playerlist and by other clients, iterated through to see if the host is there anymore at OnPhotonPlayerDisconnect(). However, this was giving me issues since sometimes when a player leaves, it kicks another random player even though the Host is still in the game (tells me that host left the room despite there being a player with Host in their custom property). So I moved on to checking the room property instead and that gave me more stability. I haven't had random kicks anymore, but now if the Host quits their app, the players do not see that the host left.

I tried using OnApplicationQuit to send a rpc that kicks everyone out, it tells me that I'm no longer online so I can't send it (makes sense since app is practically closing at this point). I tried calling Disconnect() at OnApplicationQuit() to invoke OnDisconnectedFromPhoton so host will set the property to closed, that didn't work.

Is there something I'm missing? I appreciate any insights and advice.

Thanks!
Andy

Comments

  • Hi @AndyWasHere,

    I guess you can use the void OnMasterClientSwitched(PhotonPlayer newMasterClient) callback to achieve what you want to have, even so it was not intended for such a scenario. This callback gets called, whenever a new MasterClient is selected, for example when the current MasterClient leaves the room. Please note that this gets called, too, if you are using PhotonNetwork.SetMasterClient(...);.
  • AndyWasHere
    edited January 2018
    Options
    @Christian_Simon

    That actually makes sense; I did not think of that! Thanks for the suggestion! Much appreciation. :)

    Edit: It works! Thanks so much for that out of the box advice! I honestly wouldn't have thought much of that callback. I will definitely keep in mind of other ways to use these callbacks when necessary.