@@ -197,6 +197,9 @@ void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.Connect
197
197
return ;
198
198
}
199
199
200
+ string payload = System . Text . Encoding . UTF8 . GetString ( connectionData ) ;
201
+ var connectionPayload = JsonUtility . FromJson < ConnectionPayload > ( payload ) ; // https://docs.unity3d.com/2020.2/Documentation/Manual/JSONSerialization.html
202
+
200
203
ConnectStatus gameReturnStatus ;
201
204
202
205
// Test for over-capacity connection. This needs to be done asap, to make sure we refuse connections asap and don't spend useless time server side
@@ -205,53 +208,42 @@ void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.Connect
205
208
if ( m_Portal . NetManager . ConnectedClientsIds . Count >= CharSelectData . k_MaxLobbyPlayers )
206
209
{
207
210
gameReturnStatus = ConnectStatus . ServerFull ;
208
- //TODO-FIXME:Netcode Issue #796. We should be able to send a reason and disconnect without a coroutine delay.
209
- //TODO:Netcode: In the future we expect Netcode to allow us to return more information as part of
210
- //the approval callback, so that we can provide more context on a reject. In the meantime we must provide the extra information ourselves,
211
- //and then manually close down the connection.
212
- SendServerToClientConnectResult ( clientId , gameReturnStatus ) ;
213
- SendServerToClientSetDisconnectReason ( clientId , gameReturnStatus ) ;
214
- StartCoroutine ( WaitToDisconnect ( clientId ) ) ;
215
- return ;
216
211
}
217
-
218
- string payload = System . Text . Encoding . UTF8 . GetString ( connectionData ) ;
219
- var connectionPayload = JsonUtility . FromJson < ConnectionPayload > ( payload ) ; // https://docs.unity3d.com/2020.2/Documentation/Manual/JSONSerialization.html
220
-
221
- int clientScene = connectionPayload . clientScene ;
222
-
223
- Debug . Log ( "Host ApprovalCheck: connecting client with player ID: " + connectionPayload . playerId ) ;
224
-
225
- gameReturnStatus = SessionManager < SessionPlayerData > . Instance . SetupConnectingPlayerSessionData ( clientId , connectionPayload . playerId ,
226
- new SessionPlayerData ( clientId , connectionPayload . playerName , m_Portal . AvatarRegistry . GetRandomAvatar ( ) . Guid . ToNetworkGuid ( ) , 0 , true ) )
227
- ? ConnectStatus . Success
228
- : ConnectStatus . LoggedInAgain ;
229
-
230
- //Test for Duplicate Login.
231
- if ( gameReturnStatus == ConnectStatus . LoggedInAgain )
212
+ else
232
213
{
233
- SessionPlayerData ? sessionPlayerData =
234
- SessionManager < SessionPlayerData > . Instance . GetPlayerData ( connectionPayload . playerId ) ;
235
-
236
- ulong oldClientId = sessionPlayerData ? . ClientID ?? 0 ;
237
- // kicking old client to leave only current
238
- SendServerToClientSetDisconnectReason ( oldClientId , ConnectStatus . LoggedInAgain ) ;
214
+ Debug . Log ( "Host ApprovalCheck: connecting client with player ID: " + connectionPayload . playerId ) ;
239
215
240
- StartCoroutine ( WaitToDisconnect ( clientId ) ) ;
241
- return ;
216
+ gameReturnStatus = SessionManager < SessionPlayerData > . Instance . SetupConnectingPlayerSessionData ( clientId , connectionPayload . playerId ,
217
+ new SessionPlayerData ( clientId , connectionPayload . playerName , m_Portal . AvatarRegistry . GetRandomAvatar ( ) . Guid . ToNetworkGuid ( ) , 0 , true ) )
218
+ ? ConnectStatus . Success
219
+ : ConnectStatus . LoggedInAgain ;
242
220
}
243
221
244
222
if ( gameReturnStatus == ConnectStatus . Success )
245
223
{
224
+ int clientScene = connectionPayload . clientScene ;
246
225
SendServerToClientConnectResult ( clientId , gameReturnStatus ) ;
247
226
248
227
//Populate our dictionaries with the playerData
249
228
m_ClientSceneMap [ clientId ] = clientScene ;
250
229
251
230
connectionApprovedCallback ( true , null , true , Vector3 . zero , Quaternion . identity ) ;
252
-
253
231
// connection approval will create a player object for you
254
232
}
233
+ else
234
+ {
235
+ //TODO-FIXME:Netcode Issue #796. We should be able to send a reason and disconnect without a coroutine delay.
236
+ //TODO:Netcode: In the future we expect Netcode to allow us to return more information as part of
237
+ //the approval callback, so that we can provide more context on a reject. In the meantime we must provide the extra information ourselves,
238
+ //and then manually close down the connection.
239
+ SendServerToClientConnectResult ( clientId , gameReturnStatus ) ;
240
+ SendServerToClientSetDisconnectReason ( clientId , gameReturnStatus ) ;
241
+ StartCoroutine ( WaitToDisconnect ( clientId ) ) ;
242
+ if ( m_LobbyServiceFacade . CurrentUnityLobby != null )
243
+ {
244
+ m_LobbyServiceFacade . RemovePlayerFromLobbyAsync ( connectionPayload . playerId , m_LobbyServiceFacade . CurrentUnityLobby . Id , null , null ) ;
245
+ }
246
+ }
255
247
}
256
248
257
249
IEnumerator WaitToDisconnect ( ulong clientId )
0 commit comments