@@ -178,6 +178,9 @@ void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.Connect
178
178
return ;
179
179
}
180
180
181
+ string payload = System . Text . Encoding . UTF8 . GetString ( connectionData ) ;
182
+ var connectionPayload = JsonUtility . FromJson < ConnectionPayload > ( payload ) ; // https://docs.unity3d.com/2020.2/Documentation/Manual/JSONSerialization.html
183
+
181
184
ConnectStatus gameReturnStatus ;
182
185
183
186
// 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
@@ -186,53 +189,42 @@ void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.Connect
186
189
if ( m_Portal . NetManager . ConnectedClientsIds . Count >= CharSelectData . k_MaxLobbyPlayers )
187
190
{
188
191
gameReturnStatus = ConnectStatus . ServerFull ;
189
- //TODO-FIXME:Netcode Issue #796. We should be able to send a reason and disconnect without a coroutine delay.
190
- //TODO:Netcode: In the future we expect Netcode to allow us to return more information as part of
191
- //the approval callback, so that we can provide more context on a reject. In the meantime we must provide the extra information ourselves,
192
- //and then manually close down the connection.
193
- SendServerToClientConnectResult ( clientId , gameReturnStatus ) ;
194
- SendServerToClientSetDisconnectReason ( clientId , gameReturnStatus ) ;
195
- StartCoroutine ( WaitToDisconnect ( clientId ) ) ;
196
- return ;
197
192
}
198
-
199
- string payload = System . Text . Encoding . UTF8 . GetString ( connectionData ) ;
200
- var connectionPayload = JsonUtility . FromJson < ConnectionPayload > ( payload ) ; // https://docs.unity3d.com/2020.2/Documentation/Manual/JSONSerialization.html
201
-
202
- int clientScene = connectionPayload . clientScene ;
203
-
204
- Debug . Log ( "Host ApprovalCheck: connecting client with player ID: " + connectionPayload . playerId ) ;
205
-
206
- gameReturnStatus = SessionManager < SessionPlayerData > . Instance . SetupConnectingPlayerSessionData ( clientId , connectionPayload . playerId ,
207
- new SessionPlayerData ( clientId , connectionPayload . playerName , m_Portal . AvatarRegistry . GetRandomAvatar ( ) . Guid . ToNetworkGuid ( ) , 0 , true ) )
208
- ? ConnectStatus . Success
209
- : ConnectStatus . LoggedInAgain ;
210
-
211
- //Test for Duplicate Login.
212
- if ( gameReturnStatus == ConnectStatus . LoggedInAgain )
193
+ else
213
194
{
214
- SessionPlayerData ? sessionPlayerData =
215
- SessionManager < SessionPlayerData > . Instance . GetPlayerData ( connectionPayload . playerId ) ;
216
-
217
- ulong oldClientId = sessionPlayerData ? . ClientID ?? 0 ;
218
- // kicking old client to leave only current
219
- SendServerToClientSetDisconnectReason ( oldClientId , ConnectStatus . LoggedInAgain ) ;
195
+ Debug . Log ( "Host ApprovalCheck: connecting client with player ID: " + connectionPayload . playerId ) ;
220
196
221
- StartCoroutine ( WaitToDisconnect ( clientId ) ) ;
222
- return ;
197
+ gameReturnStatus = SessionManager < SessionPlayerData > . Instance . SetupConnectingPlayerSessionData ( clientId , connectionPayload . playerId ,
198
+ new SessionPlayerData ( clientId , connectionPayload . playerName , m_Portal . AvatarRegistry . GetRandomAvatar ( ) . Guid . ToNetworkGuid ( ) , 0 , true ) )
199
+ ? ConnectStatus . Success
200
+ : ConnectStatus . LoggedInAgain ;
223
201
}
224
202
225
203
if ( gameReturnStatus == ConnectStatus . Success )
226
204
{
205
+ int clientScene = connectionPayload . clientScene ;
227
206
SendServerToClientConnectResult ( clientId , gameReturnStatus ) ;
228
207
229
208
//Populate our dictionaries with the playerData
230
209
m_ClientSceneMap [ clientId ] = clientScene ;
231
210
232
211
connectionApprovedCallback ( true , null , true , Vector3 . zero , Quaternion . identity ) ;
233
-
234
212
// connection approval will create a player object for you
235
213
}
214
+ else
215
+ {
216
+ //TODO-FIXME:Netcode Issue #796. We should be able to send a reason and disconnect without a coroutine delay.
217
+ //TODO:Netcode: In the future we expect Netcode to allow us to return more information as part of
218
+ //the approval callback, so that we can provide more context on a reject. In the meantime we must provide the extra information ourselves,
219
+ //and then manually close down the connection.
220
+ SendServerToClientConnectResult ( clientId , gameReturnStatus ) ;
221
+ SendServerToClientSetDisconnectReason ( clientId , gameReturnStatus ) ;
222
+ StartCoroutine ( WaitToDisconnect ( clientId ) ) ;
223
+ if ( m_LobbyServiceFacade . CurrentUnityLobby != null )
224
+ {
225
+ m_LobbyServiceFacade . RemovePlayerFromLobbyAsync ( connectionPayload . playerId , m_LobbyServiceFacade . CurrentUnityLobby . Id , null , null ) ;
226
+ }
227
+ }
236
228
}
237
229
238
230
IEnumerator WaitToDisconnect ( ulong clientId )
0 commit comments