public override void OnStopServer() { GameManage.players.Remove(IDName); NetworkServer.DestroyPlayerForConnection(gameObject.GetComponent <NetworkIdentity>().connectionToClient); NetworkServer.DestroyPlayerForConnection(gameObject.GetComponent <NetworkIdentity>().connectionToServer); NetworkServer.RemoveConnection(gameObject.GetComponent <NetworkIdentity>().connectionToClient.connectionId); NetworkServer.RemoveConnection(gameObject.GetComponent <NetworkIdentity>().connectionToServer.connectionId); }
/// <summary> /// When client disconnected from mirror server /// </summary> /// <param name="conn"></param> public override void OnServerDisconnect(NetworkConnection conn) { // Notify room server about this mirrorRoomServer.OnPlayerLeftRoomHandler(conn); // Destroy player NetworkServer.DestroyPlayerForConnection(conn); }
/// <summary> /// Call when a client disconnects /// </summary> /// <param name="conn"></param> internal static void OnServerRemoveClient(NetworkConnection conn) { NetworkServer.DestroyPlayerForConnection(conn); Logger.Info("Client '{ConnectionId}' disconnected from the server.", conn.connectionId); //Our first connected client disconnected if(CloseServerOnFirstClientDisconnect && conn.connectionId == firstConnectionId) Game.QuitGame(); }
public override void OnServerDisconnect(NetworkConnection info) { Debug.Log("SOmeone disconnected"); Debug.Log("" + info.connectionId); Player player = info.identity.GetComponent <Player>(); player.ExitSala(); NetworkServer.DestroyPlayerForConnection(info); }
public IEnumerator DestroyPlayerForConnectionTest() { // create spawned player CreateNetworkedAndSpawnPlayer(out GameObject player, out _, NetworkServer.localConnection); // destroy player for connection, wait 1 frame to unspawn and destroy NetworkServer.DestroyPlayerForConnection(NetworkServer.localConnection); yield return(null); Assert.That(player == null, "Player should be destroyed with DestroyPlayerForConnection"); }
public void Die() { NetworkServer.Destroy(gameObject); NetworkServer.DestroyPlayerForConnection(connectionToClient); if (Room.Players.Count == 0) { Room.EndGame(); } print("Player Count: " + Room.Players.Count); }
private void GamePlayerToRoomPlayer() { for (int i = NetworkGamePlayers.Count; i-- > 0;) { NetworkConnection connection = NetworkGamePlayers[i].connectionToClient; NetworkRoomPlayerMageBall roomPlayerInstance = Instantiate(networkRoomPlayerPrefab); roomPlayerInstance.SetIsHost(NetworkGamePlayers[i].IsHost); NetworkServer.DestroyPlayerForConnection(connection); NetworkServer.AddPlayerForConnection(connection, roomPlayerInstance.gameObject); } }
public override void OnServerDisconnect(NetworkConnection conn) { NetworkIdentity p = conn.playerController; int team = p.gameObject.GetComponent <Player>().teamIndex; if (team >= 0) { teamSizes[team]--; playerList.Remove(p.gameObject); } NetworkServer.DestroyPlayerForConnection(conn); Debug.Log("OnServerDisconnect: Client disconnected."); }
private void RoomPlayerToGamePlayer() { for (int i = NetworkRoomPlayers.Count; i-- > 0;) { NetworkConnection connection = NetworkRoomPlayers[i].connectionToClient; NetworkGamePlayerMageBall gamePlayerInstance = Instantiate(gamePlayerPrefab); gamePlayerInstance.SetDisplayName(NetworkRoomPlayers[i].DisplayName); gamePlayerInstance.SetIsHost(NetworkRoomPlayers[i].IsHost); gamePlayerInstance.SetPlayerLoadout(NetworkRoomPlayers[i].PlayerLoadout); NetworkServer.DestroyPlayerForConnection(connection); NetworkServer.AddPlayerForConnection(connection, gamePlayerInstance.gameObject); } }
public IEnumerator DestroyPlayerForConnectionTest() { GameObject player = new GameObject("testPlayer", typeof(NetworkIdentity)); NetworkConnectionToClient conn = new NetworkConnectionToClient(1); NetworkServer.AddPlayerForConnection(conn, player); NetworkServer.DestroyPlayerForConnection(conn); // takes 1 frame for unity to destroy object yield return(null); Assert.That(player == null, "Player should be destroyed with DestroyPlayerForConnection"); }
public void EndGame() { if ("Assets/Scenes/" + SceneManager.GetActiveScene().name + ".unity" == gameScene) { ServerChangeScene("EndScene"); for (int i = 0; i < Players.Count; i++) { NetworkServer.Destroy(Players[i].gameObject); NetworkServer.DestroyPlayerForConnection(Players[i].connectionToClient); } RoomPlayers.Clear(); GamePlayers.Clear(); Players.Clear(); } }
/// <summary> /// This causes the server to switch scenes and sets the networkSceneName. /// <para>Clients that connect to this server will automatically switch to this scene. This is called autmatically if onlineScene or offlineScene are set, but it can be called from user code to switch scenes again while the game is in progress. This automatically sets clients to be not-ready. The clients must call NetworkClient.Ready() again to participate in the new scene.</para> /// </summary> /// <param name="newSceneName"></param> public override void ServerChangeScene(string newSceneName) { if (SceneManager.GetActiveScene().path == menuScene) { for (int i = lobbyPlayers.Count - 1; i >= 0; i--) { var conn = lobbyPlayers[i].connectionToClient; var gamePlayerInstance = Instantiate(gamePlayerPrefab); gamePlayerInstance.SetDisplayName(lobbyPlayers[i].DisplayName); NetworkServer.DestroyPlayerForConnection(conn); NetworkServer.ReplacePlayerForConnection(conn, gamePlayerInstance.gameObject, true); } } base.ServerChangeScene(newSceneName); }
/// <summary> /// Call when a client disconnects /// </summary> /// <param name="conn"></param> internal static void OnServerRemoveClient(NetworkConnection conn) { NetworkServer.DestroyPlayerForConnection(conn); if (netManager == null) { CloseServerIfNecessary(conn); return; } if (netManager.tcAuthenticator != null) { IUser user = netManager.tcAuthenticator.GetAccount(conn.connectionId); if (user != null) { ServerChat.SendChatMessage("<b>Disconnect</b>", user.UserName); } } netManager.tcAuthenticator.OnServerClientDisconnect(conn); Logger.Info("Client '{ConnectionId}' disconnected from the server.", conn.connectionId); CloseServerIfNecessary(conn); }
private void DestroyCharacter(NetworkConnection conn) { Debug.LogWarning("Mirror: Destroying player objects for " + conn.address); NetworkServer.DestroyPlayerForConnection(conn); }
/// <summary> /// Upon player disconnect, delete the player, remove the Player game object and synchronise on all clients. /// </summary> /// <param name="conn">Player's connection info.</param> public override void OnServerDisconnect(NetworkConnection conn) { ServerStateMachine.Singleton.RemovePlayer(conn.identity.gameObject); NetworkServer.DestroyPlayerForConnection(conn); SentrySdk.AddBreadcrumb("Player disconnected."); }
public override void OnServerDisconnect(NetworkConnection info) { Debug.Log("SOmeone disconnected"); NetworkServer.DestroyPlayerForConnection(info); Debug.Log("" + info.connectionId); }
static public void DestroyPlayerForConnection(NetworkConnection conn) { NetworkServer.DestroyPlayerForConnection(conn); }
public void DespawnPlayer() { NetworkServer.DestroyPlayerForConnection(NetworkServer.localConnection); }