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] (#2941)
* fix
This resolves the issue with the client count not being correct on the host or server side when a client disconnects itself from a session.
This also resolves the issue with the host trying to send itself a message that it has connected when first starting up.
Fixing issue with NetworkSceneManager finishing synchronization prior to the server connection timing out.
* test
Adding validation for the connected clients count on the server side when the client-side disconnects.
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
15
15
16
16
### Fixed
17
17
18
+
- Fixed issue with the client count not being correct on the host or server side when a client disconnects itself from a session. (#2941)
19
+
- Fixed issue with the host trying to send itself a message that it has connected when first starting up. (#2941)
18
20
- Fixed issue where in-scene placed NetworkObjects could be destroyed if a client disconnects early and/or before approval. (#2923)
19
21
- Fixed issue where `NetworkDeltaPosition` would "jitter" periodically if both unreliable delta state updates and half-floats were used together. (#2922)
20
22
- Fixed issue where `NetworkRigidbody2D` would not properly change body type based on the instance's authority when spawned. (#2916)
// 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.
492
494
MessageManager.ProcessIncomingMessageQueue();
493
495
494
-
InvokeOnClientDisconnectCallback(clientId);
495
-
496
-
if(LocalClient.IsHost)
497
-
{
498
-
InvokeOnPeerDisconnectedCallback(clientId);
499
-
}
500
-
501
496
if(LocalClient.IsServer)
502
497
{
498
+
// We need to process the disconnection before notifying
503
499
OnClientDisconnectFromServer(clientId);
500
+
501
+
// Now notify the client has disconnected
502
+
InvokeOnClientDisconnectCallback(clientId);
503
+
504
+
if(LocalClient.IsHost)
505
+
{
506
+
InvokeOnPeerDisconnectedCallback(clientId);
507
+
}
504
508
}
505
-
else// As long as we are not in the middle of a shutdown
506
-
if(!NetworkManager.ShutdownInProgress)
509
+
else
507
510
{
508
-
// We must pass true here and not process any sends messages as we are no longer connected.
509
-
// Otherwise, attempting to process messages here can cause an exception within UnityTransport
510
-
// as the client ID is no longer valid.
511
-
NetworkManager.Shutdown(true);
511
+
// Notify local client of disconnection
512
+
InvokeOnClientDisconnectCallback(clientId);
513
+
514
+
// As long as we are not in the middle of a shutdown
515
+
if(!NetworkManager.ShutdownInProgress)
516
+
{
517
+
// We must pass true here and not process any sends messages as we are no longer connected.
518
+
// 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
@@ -182,6 +182,9 @@ public IEnumerator ClientPlayerDisconnected([Values] ClientDisconnectType client
182
182
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!");
183
183
Assert.IsTrue(m_DisconnectedEvent.ContainsKey(clientManager),$"Could not find the client {nameof(NetworkManager)} disconnect event entry!");
184
184
Assert.IsTrue(m_DisconnectedEvent[clientManager].ClientId==m_ClientId,$"Expected ClientID {m_ClientId} but found ClientID {m_DisconnectedEvent[m_ServerNetworkManager].ClientId} for the client {nameof(NetworkManager)} disconnect event entry!");
185
+
Assert.IsTrue(m_ServerNetworkManager.ConnectedClientsIds.Count==1,$"Expected connected client identifiers count to be 1 but it was {m_ServerNetworkManager.ConnectedClientsIds.Count}!");
186
+
Assert.IsTrue(m_ServerNetworkManager.ConnectedClients.Count==1,$"Expected connected client identifiers count to be 1 but it was {m_ServerNetworkManager.ConnectedClients.Count}!");
187
+
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