From 939f2820ea3f12ada3798dd362f70e9d064227b4 Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 10 May 2021 21:04:03 +0800 Subject: [PATCH] fix: NetworkServer.OnDisconnect now calls DestroyPlayerForConnection if NetworkManager doesn't handle it. --- Assets/Mirror/Runtime/NetworkServer.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index 9240ea120..c2df3bb61 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -424,18 +424,25 @@ internal static void OnTransportDisconnected(int connectionId) RemoveConnection(connectionId); // Debug.Log("Server lost client:" + connectionId); - // call OnDisconnected event. - // NetworkManager hooks into it with a virtual function to make - // DestroyPlayerForConnection(conn) optional, e.g. for PvP MMOs - // where players shouldn't be able to escape combat instantly. + // call OnDisconnected below. it's used in multiple places. OnDisconnected(conn); } } static void OnDisconnected(NetworkConnection conn) { - OnDisconnectedEvent?.Invoke(conn); - //Debug.Log("Server lost client:" + conn); + // NetworkManager hooks into OnDisconnectedEvent to make + // DestroyPlayerForConnection(conn) optional, e.g. for PvP MMOs + // where players shouldn't be able to escape combat instantly. + if (OnDisconnectedEvent != null) + { + OnDisconnectedEvent.Invoke(conn); + } + // if nobody hooked into it, then simply call DestroyPlayerForConnection + else + { + DestroyPlayerForConnection(conn); + } } static void OnError(int connectionId, Exception exception)