You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: client side disconnect incorrect client count on host-server side [MTTB-135] (Up-Port) (#3075)
* fix
Fixed issue with the client count not being correct on the host or server side when a client disconnects itself from a session.
* test
validation tests for the changes/updates to this pr.
* update
updating the changelog.
// Process the incoming message queue so that we get everything from the server disconnecting us or, if we are the server, so we got everything from that client.
497
501
MessageManager.ProcessIncomingMessageQueue();
498
502
499
-
InvokeOnClientDisconnectCallback(clientId);
500
-
501
-
if(LocalClient.IsHost)
502
-
{
503
-
InvokeOnPeerDisconnectedCallback(clientId);
504
-
}
505
-
506
503
if(LocalClient.IsServer)
507
504
{
505
+
// We need to process the disconnection before notifying
508
506
OnClientDisconnectFromServer(clientId);
507
+
508
+
// Now notify the client has disconnected
509
+
InvokeOnClientDisconnectCallback(clientId);
510
+
511
+
if(LocalClient.IsHost)
512
+
{
513
+
InvokeOnPeerDisconnectedCallback(clientId);
514
+
}
509
515
}
510
-
else// As long as we are not in the middle of a shutdown
511
-
if(!NetworkManager.ShutdownInProgress)
516
+
else
512
517
{
513
-
// We must pass true here and not process any sends messages as we are no longer connected.
514
-
// Otherwise, attempting to process messages here can cause an exception within UnityTransport
515
-
// as the client ID is no longer valid.
516
-
NetworkManager.Shutdown(true);
518
+
// Notify local client of disconnection
519
+
InvokeOnClientDisconnectCallback(clientId);
520
+
521
+
// As long as we are not in the middle of a shutdown
522
+
if(!NetworkManager.ShutdownInProgress)
523
+
{
524
+
// We must pass true here and not process any sends messages as we are no longer connected.
525
+
// Otherwise, attempting to process messages here can cause an exception within UnityTransport
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Tests/Runtime/DisconnectTests.cs
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -180,6 +180,9 @@ public IEnumerator ClientPlayerDisconnected([Values] ClientDisconnectType client
180
180
Assert.IsTrue(m_DisconnectedEvent[m_ServerNetworkManager].ClientId==m_ClientId,$"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the server {nameof(NetworkManager)} disconnect event entry!");
181
181
Assert.IsTrue(m_DisconnectedEvent.ContainsKey(m_ClientNetworkManagers[0]),$"Could not find the client {nameof(NetworkManager)} disconnect event entry!");
182
182
Assert.IsTrue(m_DisconnectedEvent[m_ClientNetworkManagers[0]].ClientId==m_ClientId,$"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the client {nameof(NetworkManager)} disconnect event entry!");
183
+
Assert.IsTrue(m_ServerNetworkManager.ConnectedClientsIds.Count==1,$"Expected connected client identifiers count to be 1 but it was {m_ServerNetworkManager.ConnectedClientsIds.Count}!");
184
+
Assert.IsTrue(m_ServerNetworkManager.ConnectedClients.Count==1,$"Expected connected client identifiers count to be 1 but it was {m_ServerNetworkManager.ConnectedClients.Count}!");
185
+
Assert.IsTrue(m_ServerNetworkManager.ConnectedClientsList.Count==1,$"Expected connected client identifiers count to be 1 but it was {m_ServerNetworkManager.ConnectedClientsList.Count}!");
0 commit comments