Skip to content

Commit

Permalink
fix: Stop calling ClientDisconnect on host (#597)
Browse files Browse the repository at this point in the history
* Stop calling ClientDisconnect on host

* Update NetworkConnection.cs

* Update NetworkServer.cs
  • Loading branch information
MichalPetryka authored and miwarnec committed Mar 17, 2019
1 parent 7850453 commit b67b3e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 5 additions & 4 deletions Assets/Mirror/Runtime/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ public void Disconnect()
isReady = false;
ClientScene.HandleClientDisconnect(this);

// paul: we may be connecting or connected, either way, we need to disconnect
// transport should not do anything if it is not connecting/connected
Transport.activeTransport.ClientDisconnect();

// server? then disconnect that client
if (Transport.activeTransport.ServerActive())
{
Transport.activeTransport.ServerDisconnect(connectionId);
}
// not server and not host mode? then disconnect client
else
{
Transport.activeTransport.ClientDisconnect();
}

// remove observers
Expand Down
14 changes: 4 additions & 10 deletions Assets/Mirror/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,7 @@ public static bool SendToReady(NetworkIdentity identity, short msgType, MessageB
public static void DisconnectAll()
{
DisconnectAllConnections();

if (s_LocalConnection != null)
{
s_LocalConnection.Disconnect();
s_LocalConnection.Dispose();
s_LocalConnection = null;
}
s_LocalConnection = null;

active = false;
localClientActive = false;
Expand All @@ -307,7 +301,9 @@ public static void DisconnectAllConnections()
{
NetworkConnection conn = kvp.Value;
conn.Disconnect();
OnDisconnected(conn);
// call OnDisconnected unless local player in host mode
if (conn.connectionId != 0)
OnDisconnected(conn);
conn.Dispose();
}
connections.Clear();
Expand Down Expand Up @@ -415,8 +411,6 @@ static void OnDisconnected(NetworkConnection conn)
}

if (LogFilter.Debug) Debug.Log("Server lost client:" + conn.connectionId);
conn.RemoveObservers();
conn.Dispose();
}

static void OnDataReceived(int connectionId, byte[] data)
Expand Down

0 comments on commit b67b3e4

Please sign in to comment.