Skip to content

Commit

Permalink
fix: save test mode scores before broadcasting GameResult
Browse files Browse the repository at this point in the history
Prevents race conditions creating errors in the TestClient and failing our CI.
  • Loading branch information
xeruf committed Feb 12, 2021
1 parent f168a29 commit 4f33fc0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions server/src/sc/server/gaming/GameRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public synchronized void onGameOver(Map<Player, PlayerScore> results) throws Inv
try {
result = generateGameResult(results);
logger.info("{} is over (regular={})", game, result.isRegular());
// save playerScore if test mode enabled
if (Boolean.parseBoolean(Configuration.get(Configuration.TEST_MODE))) {
List<Player> players = game.getPlayers();
gameRoomManager.addResultToScore(this.getResult(), players.get(0).getDisplayName(), players.get(1).getDisplayName());
}
broadcast(result);
} catch(Throwable t) {
logger.error("Failed to generate GameResult from " + results, t);
Expand All @@ -98,12 +103,6 @@ public synchronized void onGameOver(Map<Player, PlayerScore> results) throws Inv
saveReplay();
}

// save playerScore if test mode enabled
if (Boolean.parseBoolean(Configuration.get(Configuration.TEST_MODE))) {
List<Player> players = game.getPlayers();
gameRoomManager.addResultToScore(this.getResult(), players.get(0).getDisplayName(), players.get(1).getDisplayName());
}

kickAllClients();
cancel();
}
Expand Down

0 comments on commit 4f33fc0

Please sign in to comment.