@@ -362,11 +362,6 @@ internal void RemovePendingClient(ulong clientId)
362362 return ( clientId , true ) ;
363363 }
364364
365- if ( NetworkLog . CurrentLogLevel == LogLevel . Developer )
366- {
367- NetworkLog . LogWarning ( $ "Trying to get the NGO client ID map for the transport ID ({ transportId } ) but did not find the map entry! Returning default transport ID value.") ;
368- }
369-
370365 return ( default , false ) ;
371366 }
372367
@@ -488,6 +483,15 @@ internal void HandleNetworkEvent(NetworkEvent networkEvent, ulong transportClien
488483 }
489484 }
490485
486+ /// <summary>
487+ /// Client's save their assigned transport id.
488+ /// </summary>
489+ /// <remarks>
490+ /// Added to be able to appropriately log the client's transport
491+ /// id when it is shutdown or disconnected.
492+ /// </remarks>
493+ private ulong m_LocalClientTransportId ;
494+
491495 /// <summary>
492496 /// Handles a <see cref="NetworkEvent.Connect"/> event.
493497 /// </summary>
@@ -508,6 +512,8 @@ internal void ConnectEventHandler(ulong transportClientId)
508512 }
509513 else
510514 {
515+ // Cache the local client's transport id.
516+ m_LocalClientTransportId = transportClientId ;
511517 clientId = NetworkManager . ServerClientId ;
512518 }
513519
@@ -585,9 +591,12 @@ private void GenerateDisconnectInformation(ulong clientId, ulong transportClient
585591 /// </summary>
586592 internal void DisconnectEventHandler ( ulong transportClientId )
587593 {
588- var ( clientId , wasConnectedClient ) = TransportIdCleanUp ( transportClientId ) ;
589- if ( ! wasConnectedClient )
594+ // Check to see if the client has already been removed from the table but
595+ // do not remove it just yet.
596+ var ( clientId , isConnectedClient ) = TransportIdToClientId ( transportClientId ) ;
597+ if ( ! isConnectedClient )
590598 {
599+ // If so, exit early
591600 return ;
592601 }
593602
@@ -623,7 +632,8 @@ internal void DisconnectEventHandler(ulong transportClientId)
623632 // We need to process the disconnection before notifying
624633 OnClientDisconnectFromServer ( clientId ) ;
625634
626- // Now notify the client has disconnected
635+ // Now notify the client has disconnected.
636+ // (transport id cleanup is handled within)
627637 InvokeOnClientDisconnectCallback ( clientId ) ;
628638
629639 if ( LocalClient . IsHost )
@@ -633,6 +643,9 @@ internal void DisconnectEventHandler(ulong transportClientId)
633643 }
634644 else
635645 {
646+ // Client's clean up their transport id separately from the server.
647+ TransportIdCleanUp ( transportClientId ) ;
648+
636649 // Notify local client of disconnection
637650 InvokeOnClientDisconnectCallback ( clientId ) ;
638651
@@ -1392,8 +1405,20 @@ internal void OnClientDisconnectFromServer(ulong clientId)
13921405 }
13931406
13941407 ConnectedClientIds . Remove ( clientId ) ;
1395- var message = new ClientDisconnectedMessage { ClientId = clientId } ;
1396- MessageManager ? . SendMessage ( ref message , MessageDeliveryType < ClientDisconnectedMessage > . DefaultDelivery , ConnectedClientIds ) ;
1408+
1409+ if ( MessageManager != null )
1410+ {
1411+ var message = new ClientDisconnectedMessage { ClientId = clientId } ;
1412+ foreach ( var sendToId in ConnectedClientIds )
1413+ {
1414+ // Do not send a disconnect message to ourself
1415+ if ( sendToId == NetworkManager . LocalClientId )
1416+ {
1417+ continue ;
1418+ }
1419+ MessageManager . SendMessage ( ref message , MessageDeliveryType < ClientDisconnectedMessage > . DefaultDelivery , sendToId ) ;
1420+ }
1421+ }
13971422
13981423 // Used for testing/validation purposes only
13991424 // Promote a new session owner when the ENABLE_DAHOST_AUTOPROMOTE_SESSION_OWNER scripting define is set
@@ -1491,6 +1516,7 @@ internal void DisconnectClient(ulong clientId, string reason = null)
14911516 internal void Initialize ( NetworkManager networkManager )
14921517 {
14931518 // Prepare for a new session
1519+ m_LocalClientTransportId = 0 ;
14941520 LocalClient . IsApproved = false ;
14951521 m_PendingClients . Clear ( ) ;
14961522 ConnectedClients . Clear ( ) ;
@@ -1524,8 +1550,9 @@ internal void Shutdown()
15241550 {
15251551 Transport . ShuttingDown ( ) ;
15261552 var clientId = NetworkManager ? NetworkManager . LocalClientId : NetworkManager . ServerClientId ;
1527- var transportId = ClientIdToTransportId ( clientId ) ;
1528- GenerateDisconnectInformation ( clientId , transportId . Item1 , $ "{ nameof ( NetworkConnectionManager ) } was shutdown.") ;
1553+ // Server and host just log 0 for their transport id while clients will log their cached m_LocalClientTransportId
1554+ var transportId = clientId == NetworkManager . ServerClientId ? 0 : m_LocalClientTransportId ;
1555+ GenerateDisconnectInformation ( clientId , transportId , $ "{ nameof ( NetworkConnectionManager ) } was shutdown.") ;
15291556 }
15301557
15311558 if ( LocalClient . IsServer )
0 commit comments