use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameValidityUnrankedMod.
@Test
public void updateGameValidityUnrankedMod() throws Exception {
Game game = hostGame(player1);
game.getSimMods().add(new ModVersion().setRanked(false).setMod(new Mod().setDisplayName("Mod")));
launchGame(game);
instance.updateGameValidity(game);
assertThat(game.getValidity(), is(Validity.BAD_MOD));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method scoresCalculatedCorrectly.
/**
* Tests that scores are calculated based on the reports of the majority of players that are still connected when the
* game ends, even if there are kiddies trying to trick the system. The only case they are able to do so is if they
* stay until the end of the game and share the majority of the result reports. The only way to prevent this would be
* a neutral referee who can always be trusted.
*/
@Test
public void scoresCalculatedCorrectly() throws Exception {
Player player3 = (Player) new Player().setId(3);
Player player4 = (Player) new Player().setId(4);
Player player5 = (Player) new Player().setId(5);
Player player6 = (Player) new Player().setId(6);
Player player7 = (Player) new Player().setId(7);
Player player8 = (Player) new Player().setId(8);
Game game = hostGame(player1);
Stream.of(player2, player3, player4, player5, player6, player7, player8).forEach(player -> addPlayer(game, player));
Stream.of(player1, player3, player5, player7).forEach(player -> instance.updatePlayerOption(player1, player.getId(), OPTION_TEAM, 2));
Stream.of(player2, player4, player6, player8).forEach(player -> instance.updatePlayerOption(player1, player.getId(), OPTION_TEAM, 3));
Stream.of(player1, player2, player3, player4, player5, player6, player7, player8).forEach(player -> instance.updatePlayerOption(player1, player.getId(), OPTION_ARMY, player.getId()));
launchGame(game);
// 6 of 8 players got killed, player 1 - 3 are the only ones who report the correct result
Stream.of(player1, player2, player3).forEach(reporter -> {
// Army 3-8 have been defeated
IntStream.range(3, 9).forEach(armyId -> {
instance.reportArmyOutcome(reporter, armyId, Outcome.DEFEAT);
instance.reportArmyScore(reporter, armyId, -1);
});
// Army 1 and 2 scored and are still in game
IntStream.range(1, 3).forEach(armyId -> instance.reportArmyScore(reporter, armyId, 3));
});
// Players 4 - 8 are kiddies who try to trick the score system by reporting everybody but players 1 and 2 lost
Stream.of(player4, player5, player6, player7, player8).forEach(reporter -> {
// Army 1 and 2 have allegedly been defeated
IntStream.range(1, 3).forEach(armyId -> {
instance.reportArmyOutcome(reporter, armyId, Outcome.DEFEAT);
instance.reportArmyScore(reporter, armyId, -1);
});
// Armies 3 - 8 allegedly won
IntStream.range(3, 9).forEach(armyId -> {
instance.reportArmyOutcome(reporter, armyId, Outcome.VICTORY);
instance.reportArmyScore(reporter, armyId, 10);
});
});
// All but players 1, 2, and 3 disconnect
Stream.of(player4, player5, player6, player7, player8).forEach(player -> instance.removePlayer(player));
// Player 1 claims to have defeated player 2, but player 2 and 3 claim that player 1 has been defeated.
instance.reportArmyScore(player1, 1, 4);
instance.reportArmyOutcome(player1, 1, Outcome.VICTORY);
instance.reportArmyScore(player1, 2, 2);
instance.reportArmyOutcome(player1, 2, Outcome.DEFEAT);
Stream.of(player2, player3).forEach(reporter -> {
instance.reportArmyScore(reporter, 1, 4);
instance.reportArmyOutcome(reporter, 1, Outcome.DEFEAT);
instance.reportArmyScore(reporter, 2, 2);
instance.reportArmyOutcome(reporter, 2, Outcome.VICTORY);
});
/* Even though the intermediate results are the ones reported most often, the results to be considered are the ones
with an outcome, since only those players saw the end of the game. */
assertThat(game.getValidity(), is(Validity.VALID));
// Expect that reports of all disconnected players have been discarded
assertThat(game.getReportedArmyResults().values(), hasSize(3));
// Expect all remaining players to have reported army results for all players
game.getReportedArmyResults().forEach((playerId, resultMap) -> assertThat("Player " + playerId + " did not report all results", resultMap.size(), is(8)));
assertThat(game.getPlayerStats().get(1).getScore(), is(4));
assertThat(game.getPlayerStats().get(2).getScore(), is(2));
assertThat(game.getPlayerStats().get(3).getScore(), is(-1));
assertThat(game.getPlayerStats().get(4).getScore(), is(-1));
assertThat(game.getPlayerStats().get(5).getScore(), is(-1));
assertThat(game.getPlayerStats().get(6).getScore(), is(-1));
assertThat(game.getPlayerStats().get(7).getScore(), is(-1));
assertThat(game.getPlayerStats().get(8).getScore(), is(-1));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method onClientDisconnectRemovesPlayerAndUnsetsGameAndRemovesGameIfLastPlayer.
@Test
public void onClientDisconnectRemovesPlayerAndUnsetsGameAndRemovesGameIfLastPlayer() throws Exception {
Game game = hostGame(player1);
assertThat(player1.getCurrentGame(), is(game));
assertThat(player1.getGameState(), is(PlayerGameState.LOBBY));
assertThat(instance.getActiveGame(game.getId()).isPresent(), is(true));
instance.removePlayer(player1);
assertThat(player1.getCurrentGame(), is(nullValue()));
assertThat(player1.getGameState(), is(PlayerGameState.NONE));
assertThat(instance.getActiveGame(game.getId()).isPresent(), is(false));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameValidityWrongVictoryConditionSandboxNotCoop.
@Test
public void updateGameValidityWrongVictoryConditionSandboxNotCoop() throws Exception {
Game game = hostGame(player1);
game.setVictoryCondition(VictoryCondition.SANDBOX);
when(modService.isCoop(any())).thenReturn(false);
launchGame(game);
instance.updateGameValidity(game);
assertThat(game.getValidity(), is(Validity.WRONG_VICTORY_CONDITION));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameModsCountClearsIfZero.
@Test
public void updateGameModsCountClearsIfZero() throws Exception {
List<String> modUids = Arrays.asList("1-1-1-1", "2-2-2-2");
when(modService.findModVersionsByUids(modUids)).thenReturn(Arrays.asList(new ModVersion().setUid("1-1-1-1").setMod(new Mod().setDisplayName("Mod #1")), new ModVersion().setUid("2-2-2-2").setMod(new Mod().setDisplayName("Mod #2"))));
Game game = hostGame(player1);
instance.updateGameMods(game, Arrays.asList("1-1-1-1", "2-2-2-2"));
instance.updateGameModsCount(game, 0);
assertThat(game.getSimMods(), is(empty()));
}
Aggregations