@@ -53,7 +53,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
53
53
// Instead of granting lock request, change this player to Inactive state.
54
54
CharSelectData . LobbyPlayers [ idx ] = new CharSelectData . LobbyPlayerState ( clientId ,
55
55
CharSelectData . LobbyPlayers [ idx ] . PlayerName ,
56
- CharSelectData . LobbyPlayers [ idx ] . PlayerNum ,
56
+ CharSelectData . LobbyPlayers [ idx ] . PlayerNumber ,
57
57
CharSelectData . SeatState . Inactive ) ;
58
58
59
59
// then early out
@@ -64,7 +64,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
64
64
65
65
CharSelectData . LobbyPlayers [ idx ] = new CharSelectData . LobbyPlayerState ( clientId ,
66
66
CharSelectData . LobbyPlayers [ idx ] . PlayerName ,
67
- CharSelectData . LobbyPlayers [ idx ] . PlayerNum ,
67
+ CharSelectData . LobbyPlayers [ idx ] . PlayerNumber ,
68
68
lockedIn ? CharSelectData . SeatState . LockedIn : CharSelectData . SeatState . Active ,
69
69
newSeatIdx ,
70
70
Time . time ) ;
@@ -81,7 +81,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
81
81
CharSelectData . LobbyPlayers [ i ] = new CharSelectData . LobbyPlayerState (
82
82
CharSelectData . LobbyPlayers [ i ] . ClientId ,
83
83
CharSelectData . LobbyPlayers [ i ] . PlayerName ,
84
- CharSelectData . LobbyPlayers [ i ] . PlayerNum ,
84
+ CharSelectData . LobbyPlayers [ i ] . PlayerNumber ,
85
85
CharSelectData . SeatState . Inactive ) ;
86
86
}
87
87
}
@@ -185,46 +185,52 @@ private void OnSceneEvent(SceneEvent sceneEvent)
185
185
SeatNewPlayer ( sceneEvent . ClientId ) ;
186
186
}
187
187
188
- private int GetAvailablePlayerNum ( )
188
+ private int GetAvailablePlayerNumber ( )
189
189
{
190
- for ( int possiblePlayerNum = 0 ; possiblePlayerNum < CharSelectData . k_MaxLobbyPlayers ; ++ possiblePlayerNum )
190
+ for ( int possiblePlayerNumber = 0 ; possiblePlayerNumber < CharSelectData . k_MaxLobbyPlayers ; ++ possiblePlayerNumber )
191
191
{
192
- bool found = false ;
193
- foreach ( CharSelectData . LobbyPlayerState playerState in CharSelectData . LobbyPlayers )
192
+ if ( IsPlayerNumberAvailable ( possiblePlayerNumber ) )
194
193
{
195
- if ( playerState . PlayerNum == possiblePlayerNum )
196
- {
197
- found = true ;
198
- break ;
199
- }
200
- }
201
- if ( ! found )
202
- {
203
- return possiblePlayerNum ;
194
+ return possiblePlayerNumber ;
204
195
}
205
196
}
206
197
// we couldn't get a Player# for this person... which means the lobby is full!
207
198
return - 1 ;
208
199
}
209
200
201
+ bool IsPlayerNumberAvailable ( int playerNumber )
202
+ {
203
+ bool found = false ;
204
+ foreach ( CharSelectData . LobbyPlayerState playerState in CharSelectData . LobbyPlayers )
205
+ {
206
+ if ( playerState . PlayerNumber == playerNumber )
207
+ {
208
+ found = true ;
209
+ break ;
210
+ }
211
+ }
212
+
213
+ return ! found ;
214
+ }
215
+
210
216
private void SeatNewPlayer ( ulong clientId )
211
217
{
212
218
SessionPlayerData ? sessionPlayerData = SessionManager < SessionPlayerData > . Instance . GetPlayerData ( clientId ) ;
213
219
if ( sessionPlayerData . HasValue )
214
220
{
215
221
var playerData = sessionPlayerData . Value ;
216
- if ( playerData . PlayerNum == - 1 )
222
+ if ( playerData . PlayerNumber == - 1 || ! IsPlayerNumberAvailable ( playerData . PlayerNumber ) )
217
223
{
218
- // If no player num already assigned, get an available one.
219
- playerData . PlayerNum = GetAvailablePlayerNum ( ) ;
224
+ // If no player num already assigned or if player num is no longer available , get an available one.
225
+ playerData . PlayerNumber = GetAvailablePlayerNumber ( ) ;
220
226
}
221
- if ( playerData . PlayerNum == - 1 )
227
+ if ( playerData . PlayerNumber == - 1 )
222
228
{
223
229
// Sanity check. We ran out of seats... there was no room!
224
- throw new Exception ( $ "we shouldn't be here, connection approval should have refused this connection already for client ID { clientId } and player num { playerData . PlayerNum } ") ;
230
+ throw new Exception ( $ "we shouldn't be here, connection approval should have refused this connection already for client ID { clientId } and player num { playerData . PlayerNumber } ") ;
225
231
}
226
232
227
- CharSelectData . LobbyPlayers . Add ( new CharSelectData . LobbyPlayerState ( clientId , playerData . PlayerName , playerData . PlayerNum , CharSelectData . SeatState . Inactive ) ) ;
233
+ CharSelectData . LobbyPlayers . Add ( new CharSelectData . LobbyPlayerState ( clientId , playerData . PlayerName , playerData . PlayerNumber , CharSelectData . SeatState . Inactive ) ) ;
228
234
SessionManager < SessionPlayerData > . Instance . SetPlayerData ( clientId , playerData ) ;
229
235
}
230
236
}
0 commit comments