Skip to content

Commit

Permalink
fix game end player removal error
Browse files Browse the repository at this point in the history
  • Loading branch information
yenuGH committed Aug 4, 2023
1 parent d0fbb67 commit 78e9af6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/com/wordhunter/server/ServerAcceptClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ public void removePlayer(int index) {
playerColorListLock.acquire();

// remove from server lists
Player removedPlayer = ServerMain.playerList.remove(index);
colorIds.add(removedPlayer.getColor());
// store for allowing reconnect attempt
disconnectedPlayerList.add(removedPlayer);
try {
Player removedPlayer = ServerMain.playerList.remove(index);
colorIds.add(removedPlayer.getColor());
// store for allowing reconnect attempt
disconnectedPlayerList.add(removedPlayer);

// broadcast updated player list and color ids
ServerMain.broadcast("playerDisconnect" + ServerMain.messageDelimiter
+ "playerList" + ServerMain.messageDelimiter
+ ","
+ PlayerConversion.fromPlayers(ServerMain.playerList)
+ ServerMain.messageDelimiter);
playerColorListLock.release();
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("Game has already ended, no players to remove.");
}

// broadcast updated player list and color ids
ServerMain.broadcast("playerDisconnect" + ServerMain.messageDelimiter
+ "playerList" + ServerMain.messageDelimiter
+ ","
+ PlayerConversion.fromPlayers(ServerMain.playerList)
+ ServerMain.messageDelimiter);
playerColorListLock.release();
} catch (InterruptedException ignored) {
}
}
Expand Down

0 comments on commit 78e9af6

Please sign in to comment.