@@ -83,25 +83,58 @@ public sealed class NetworkConnectionManager
83
83
84
84
internal IReadOnlyDictionary < ulong , PendingClient > PendingClients => m_PendingClients ;
85
85
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
+
86
112
/// <summary>
113
+ /// Server-Side:
87
114
/// Handles the issue with populating NetworkManager.PendingClients
88
115
/// </summary>
89
116
internal void AddPendingClient ( ulong clientId )
90
117
{
91
118
m_PendingClients . Add ( clientId , new PendingClient ( )
92
119
{
93
120
ClientId = clientId ,
94
- ConnectionState = PendingClient . State . PendingConnection
121
+ ConnectionState = PendingClient . State . PendingConnection ,
122
+ ApprovalCoroutine = NetworkManager . StartCoroutine ( ApprovalTimeout ( clientId ) )
95
123
} ) ;
96
124
97
125
NetworkManager . PendingClients . Add ( clientId , PendingClients [ clientId ] ) ;
98
126
}
99
127
100
128
/// <summary>
129
+ /// Server-Side:
101
130
/// Handles the issue with depopulating NetworkManager.PendingClients
102
131
/// </summary>
103
132
internal void RemovePendingClient ( ulong clientId )
104
133
{
134
+ if ( m_PendingClients . ContainsKey ( clientId ) && m_PendingClients [ clientId ] . ApprovalCoroutine != null )
135
+ {
136
+ NetworkManager . StopCoroutine ( m_PendingClients [ clientId ] . ApprovalCoroutine ) ;
137
+ }
105
138
m_PendingClients . Remove ( clientId ) ;
106
139
NetworkManager . PendingClients . Remove ( clientId ) ;
107
140
}
@@ -272,8 +305,6 @@ internal void ConnectEventHandler(ulong transportClientId)
272
305
}
273
306
274
307
AddPendingClient ( clientId ) ;
275
-
276
- NetworkManager . StartCoroutine ( ApprovalTimeout ( clientId ) ) ;
277
308
}
278
309
else
279
310
{
@@ -283,7 +314,7 @@ internal void ConnectEventHandler(ulong transportClientId)
283
314
}
284
315
285
316
SendConnectionRequest ( ) ;
286
- NetworkManager . StartCoroutine ( ApprovalTimeout ( clientId ) ) ;
317
+ StartClientApprovalCoroutine ( clientId ) ;
287
318
}
288
319
289
320
#if DEVELOPMENT_BUILD || UNITY_EDITOR
@@ -545,7 +576,7 @@ internal void HandleConnectionApproval(ulong ownerClientId, NetworkManager.Conne
545
576
LocalClient . IsApproved = response . Approved ;
546
577
if ( response . Approved )
547
578
{
548
- // Inform new client it got approved
579
+ // The client was approved, stop the server-side approval time out coroutine
549
580
RemovePendingClient ( ownerClientId ) ;
550
581
551
582
var client = AddClient ( ownerClientId ) ;
@@ -818,6 +849,8 @@ internal void OnClientDisconnectFromServer(ulong clientId)
818
849
}
819
850
820
851
// 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.
821
854
RemovePendingClient ( clientId ) ;
822
855
823
856
// Handle cleaning up the server-side client send queue
0 commit comments