Search in sources :

Example 16 with Game

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));
}
Also used : Game(com.faforever.server.entity.Game) User(com.faforever.server.entity.User) ClientConnection(com.faforever.server.client.ClientConnection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 17 with Game

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"));
}
Also used : ModVersion(com.faforever.server.entity.ModVersion) FeaturedMod(com.faforever.server.entity.FeaturedMod) Mod(com.faforever.server.entity.Mod) Game(com.faforever.server.entity.Game) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 18 with Game

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));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 19 with Game

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));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 20 with Game

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));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Aggregations

Game (com.faforever.server.entity.Game)96 Test (org.junit.Test)71 Player (com.faforever.server.entity.Player)26 FeaturedMod (com.faforever.server.entity.FeaturedMod)15 ModVersion (com.faforever.server.entity.ModVersion)12 ConnectionAware (com.faforever.server.client.ConnectionAware)11 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)11 List (java.util.List)11 ClientService (com.faforever.server.client.ClientService)10 ServerProperties (com.faforever.server.config.ServerProperties)10 RequestException (com.faforever.server.error.RequestException)10 ModService (com.faforever.server.mod.ModService)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)10 Duration (java.time.Duration)10 Map (java.util.Map)10 Optional (java.util.Optional)10 Slf4j (lombok.extern.slf4j.Slf4j)10 Service (org.springframework.stereotype.Service)10 ArmyResult (com.faforever.server.entity.ArmyResult)9 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)9