Search Unity

  1. We have added dedicated sub-forums for UNet, the experimental MLAPI and Unity Transport Package. Please use the new forums to discuss related topics.
    Dismiss Notice
  2. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Photon PUN - How to tell if a client is get kicked?

Discussion in 'Multiplayer' started by Paulx774, Jul 16, 2021.

  1. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    62
    I'm using PhotonNetwork.CloseConnection to kick players from rooms. I want to show a popup when a client gets kicked from a room. How can I determine this?

    I also close the room when the master client leaves. I use the same function, CloseConnection. I also need to determine which one occurs in the game. How can I do that?

    This is the simplified version of the code:

    Code (CSharp):
    1.     public void Leave()
    2.     {
    3.         // Check if the master client is leaving
    4.         if (PhotonNetwork.IsMasterClient)
    5.         {
    6.             PhotonNetwork.CurrentRoom.IsOpen = false;
    7.             PhotonNetwork.CurrentRoom.IsVisible = false;
    8.  
    9.             // Kick the other players from the room
    10.             Player[] otherPlayers = PhotonNetwork.PlayerListOthers;
    11.             for (int i = 0; i < otherPlayers.Length; ++i)
    12.             {
    13.                 PhotonNetwork.CloseConnection(otherPlayers[i]);
    14.                 // TODO: I need to show a popup message saying the master client left to the other clients
    15.             }
    16.         }
    17.  
    18.         PhotonNetwork.LeaveRoom();
    19.     }
    20.  
    21.     public void Kick(Player kick)
    22.     {
    23.         PhotonNetwork.CloseConnection(kick);
    24.         // TODO: I need to show a popup message saying you're kicked from the room to the client
    25.     }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,642
    The way it's implemented right now, nobody else knows if someone was kicked.

    If you just want to make everyone leave when the Master Client leaves, then it's better make your clients do that as soon as the Master Client leaves.
    Instead of sending a kick to each player, you could also just send your own, custom event to the room (by default, everyone else) and implement a disconnect. CloseConnection(player) is not truly executed on the server either.

    You can probably hide and close the room earlier. Do it when the game starts (unless that doesn't apply to your game).
     
unityunity