use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method restoreGameSessionOpenGame.
@Test
public void restoreGameSessionOpenGame() throws Exception {
Game game = hostGame(player1);
assertThat(player2.getCurrentGame(), is(nullValue()));
instance.joinGame(game.getId(), game.getPassword(), player2);
assertThat(player2.getCurrentGame(), is(game));
assertThat(player2.getGameState(), is(PlayerGameState.INITIALIZING));
instance.updatePlayerGameState(PlayerGameState.LOBBY, player2);
instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player2);
assertThat(player2.getGameState(), is(PlayerGameState.LAUNCHING));
ClientConnection clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
clientConnection.setAuthentication(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null));
player2.setClientConnection(clientConnection);
instance.removePlayer(player2);
assertThat(player2.getCurrentGame(), is(nullValue()));
assertThat(player2.getGameState(), is(PlayerGameState.NONE));
instance.restoreGameSession(player2, game.getId());
assertThat(player2.getCurrentGame(), is(game));
assertThat(player2.getGameState(), is(PlayerGameState.LOBBY));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameMods.
@Test
public void updateGameMods() 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, modUids);
List<ModVersion> simMods = game.getSimMods();
assertThat(simMods, hasSize(2));
assertThat(simMods.get(0).getUid(), is("1-1-1-1"));
assertThat(simMods.get(0).getMod().getDisplayName(), is("Mod #1"));
assertThat(simMods.get(1).getUid(), is("2-2-2-2"));
assertThat(simMods.get(1).getMod().getDisplayName(), is("Mod #2"));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method reportArmyScoreWithCheater.
/**
* Tests whether the service correctly chooses the scores reported by the majority of connected players and ignores
* the results reported by a "cheater" (that is, someone who reports different results).
*/
@Test
public void reportArmyScoreWithCheater() throws Exception {
Game game = hostGame(player1);
Player player3 = (Player) new Player().setId(3);
addPlayer(game, player2);
addPlayer(game, player3);
instance.updatePlayerOption(player1, player1.getId(), OPTION_ARMY, 1);
instance.updatePlayerOption(player1, player2.getId(), OPTION_ARMY, 2);
instance.updatePlayerOption(player1, player3.getId(), OPTION_ARMY, 3);
launchGame(game);
instance.reportArmyScore(player1, 1, 10);
instance.reportArmyScore(player1, 2, -1);
instance.reportArmyScore(player1, 3, -1);
instance.reportArmyOutcome(player1, 1, Outcome.VICTORY);
instance.reportArmyOutcome(player1, 2, Outcome.DEFEAT);
instance.reportArmyOutcome(player1, 3, Outcome.DEFEAT);
instance.reportArmyScore(player2, 1, 10);
instance.reportArmyScore(player2, 2, -1);
instance.reportArmyScore(player2, 3, -1);
instance.reportArmyOutcome(player2, 1, Outcome.VICTORY);
instance.reportArmyOutcome(player2, 2, Outcome.DEFEAT);
instance.reportArmyOutcome(player2, 3, Outcome.DEFEAT);
instance.reportArmyScore(player3, 1, -1);
instance.reportArmyScore(player3, 2, -1);
instance.reportArmyScore(player3, 3, 10);
instance.reportArmyOutcome(player3, 1, Outcome.DEFEAT);
instance.reportArmyOutcome(player3, 2, Outcome.DEFEAT);
instance.reportArmyOutcome(player3, 3, Outcome.VICTORY);
instance.updatePlayerGameState(PlayerGameState.ENDED, player1);
instance.updatePlayerGameState(PlayerGameState.ENDED, player2);
instance.updatePlayerGameState(PlayerGameState.ENDED, player3);
assertThat(game.getPlayerStats().values(), hasSize(3));
assertThat(game.getPlayerStats().get(player1.getId()).getScore(), is(10));
assertThat(game.getPlayerStats().get(player2.getId()).getScore(), is(-1));
assertThat(game.getPlayerStats().get(player3.getId()).getScore(), is(-1));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameValidityCheatsEnabled.
@Test
public void updateGameValidityCheatsEnabled() throws Exception {
Game game = hostGame(player1);
game.getOptions().put(OPTION_CHEATS_ENABLED, "true");
launchGame(game);
instance.updateGameValidity(game);
assertThat(game.getValidity(), is(Validity.CHEATS_ENABLED));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameValidityTooShort.
@Test
public void updateGameValidityTooShort() throws Exception {
Game game = hostGame(player1);
addPlayer(game, player2);
launchGame(game);
game.getReportedArmyResults().put(1, ImmutableMap.of(1, ArmyResult.of(1, Outcome.VICTORY, 10)));
serverProperties.getGame().setRankedMinTimeMultiplicator(10_000);
instance.updateGameValidity(game);
assertThat(game.getValidity(), is(Validity.TOO_SHORT));
}
Aggregations