@@ -83,25 +83,58 @@ public sealed class NetworkConnectionManager
8383
8484 internal IReadOnlyDictionary < ulong , PendingClient > PendingClients => m_PendingClients ;
8585
86+ internal Coroutine LocalClientApprovalCoroutine ;
87+
88+ /// <summary>
89+ /// Client-Side:
90+ /// Starts the client-side approval timeout coroutine
91+ /// </summary>
92+ /// <param name="clientId"></param>
93+ internal void StartClientApprovalCoroutine ( ulong clientId )
94+ {
95+ LocalClientApprovalCoroutine = NetworkManager . StartCoroutine ( ApprovalTimeout ( clientId ) ) ;
96+ }
97+
98+ /// <summary>
99+ /// Client-Side:
100+ /// Stops the client-side approval timeout when it is approved.
101+ /// <see cref="ConnectionApprovedMessage.Handle(ref NetworkContext)"/>
102+ /// </summary>
103+ internal void StopClientApprovalCoroutine ( )
104+ {
105+ if ( LocalClientApprovalCoroutine != null )
106+ {
107+ NetworkManager . StopCoroutine ( LocalClientApprovalCoroutine ) ;
108+ LocalClientApprovalCoroutine = null ;
109+ }
110+ }
111+
86112 /// <summary>
113+ /// Server-Side:
87114 /// Handles the issue with populating NetworkManager.PendingClients
88115 /// </summary>
89116 internal void AddPendingClient ( ulong clientId )
90117 {
91118 m_PendingClients . Add ( clientId , new PendingClient ( )
92119 {
93120 ClientId = clientId ,
94- ConnectionState = PendingClient . State . PendingConnection
121+ ConnectionState = PendingClient . State . PendingConnection ,
122+ ApprovalCoroutine = NetworkManager . StartCoroutine ( ApprovalTimeout ( clientId ) )
95123 } ) ;
96124
97125 NetworkManager . PendingClients . Add ( clientId , PendingClients [ clientId ] ) ;
98126 }
99127
100128 /// <summary>
129+ /// Server-Side:
101130 /// Handles the issue with depopulating NetworkManager.PendingClients
102131 /// </summary>
103132 internal void RemovePendingClient ( ulong clientId )
104133 {
134+ if ( m_PendingClients . ContainsKey ( clientId ) && m_PendingClients [ clientId ] . ApprovalCoroutine != null )
135+ {
136+ NetworkManager . StopCoroutine ( m_PendingClients [ clientId ] . ApprovalCoroutine ) ;
137+ }
105138 m_PendingClients . Remove ( clientId ) ;
106139 NetworkManager . PendingClients . Remove ( clientId ) ;
107140 }
@@ -272,8 +305,6 @@ internal void ConnectEventHandler(ulong transportClientId)
272305 }
273306
274307 AddPendingClient ( clientId ) ;
275-
276- NetworkManager . StartCoroutine ( ApprovalTimeout ( clientId ) ) ;
277308 }
278309 else
279310 {
@@ -283,7 +314,7 @@ internal void ConnectEventHandler(ulong transportClientId)
283314 }
284315
285316 SendConnectionRequest ( ) ;
286- NetworkManager . StartCoroutine ( ApprovalTimeout ( clientId ) ) ;
317+ StartClientApprovalCoroutine ( clientId ) ;
287318 }
288319
289320#if DEVELOPMENT_BUILD || UNITY_EDITOR
@@ -545,7 +576,7 @@ internal void HandleConnectionApproval(ulong ownerClientId, NetworkManager.Conne
545576 LocalClient . IsApproved = response . Approved ;
546577 if ( response . Approved )
547578 {
548- // Inform new client it got approved
579+ // The client was approved, stop the server-side approval time out coroutine
549580 RemovePendingClient ( ownerClientId ) ;
550581
551582 var client = AddClient ( ownerClientId ) ;
@@ -818,6 +849,8 @@ internal void OnClientDisconnectFromServer(ulong clientId)
818849 }
819850
820851 // Assure the client id is no longer in the pending clients list
852+ // and stop the server-side client approval timeout since the client
853+ // is no longer connected.
821854 RemovePendingClient ( clientId ) ;
822855
823856 // Handle cleaning up the server-side client send queue
0 commit comments