Search in sources :

Example 26 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method updateGameValidityNoFogOfWar.

@Test
public void updateGameValidityNoFogOfWar() throws Exception {
    Game game = hostGame(player1);
    game.getOptions().put(OPTION_FOG_OF_WAR, "foo");
    launchGame(game);
    instance.updateGameValidity(game);
    assertThat(game.getValidity(), is(Validity.NO_FOG_OF_WAR));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 27 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method updateGameOption.

@Test
public void updateGameOption() throws Exception {
    Game game = hostGame(player1);
    assertThat(game.getOptions().containsKey("GameSpeed"), is(false));
    instance.updateGameOption(player1, "GameSpeed", "normal");
    assertThat(game.getOptions().get("GameSpeed"), is("normal"));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 28 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method hostGame.

private Game hostGame(Player host) throws Exception {
    player1.setCurrentGame(null);
    CompletableFuture<Game> joinable = instance.createGame("Game title", FAF_TECHNICAL_NAME, MAP_NAME, "secret", GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, host);
    assertThat(joinable.isDone(), is(false));
    assertThat(joinable.isCancelled(), is(false));
    assertThat(joinable.isCompletedExceptionally(), is(false));
    verify(counterService, never()).decrement(String.format(Metrics.GAMES_STATE_FORMAT, GameState.CLOSED));
    verify(counterService).increment(String.format(Metrics.GAMES_STATE_FORMAT, GameState.INITIALIZING));
    Game game = instance.getActiveGame(1).get();
    assertThat(game.getState(), is(GameState.INITIALIZING));
    assertThat(player1.getCurrentGame(), is(game));
    assertThat(player1.getGameState(), is(PlayerGameState.INITIALIZING));
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player1);
    assertThat(player1.getGameState(), is(PlayerGameState.LOBBY));
    game = joinable.get();
    instance.updateGameOption(host, OPTION_VICTORY_CONDITION, VictoryCondition.DEMORALIZATION.getString());
    instance.updateGameOption(host, OPTION_FOG_OF_WAR, "explored");
    instance.updateGameOption(host, OPTION_CHEATS_ENABLED, "false");
    instance.updateGameOption(host, OPTION_PREBUILT_UNITS, "Off");
    instance.updateGameOption(host, OPTION_NO_RUSH, "Off");
    instance.updateGameOption(host, OPTION_RESTRICTED_CATEGORIES, 0);
    instance.updatePlayerOption(host, host.getId(), OPTION_ARMY, host.getId());
    instance.updatePlayerOption(host, host.getId(), OPTION_FACTION, 1);
    instance.updatePlayerOption(host, host.getId(), OPTION_COLOR, host.getId());
    instance.updatePlayerOption(host, host.getId(), OPTION_START_SPOT, host.getId());
    instance.updatePlayerOption(host, host.getId(), OPTION_TEAM, GameService.NO_TEAM_ID);
    verify(counterService).increment(String.format(Metrics.GAMES_STATE_FORMAT, GameState.INITIALIZING));
    verify(clientService).startGameProcess(game, player1);
    assertThat(game.getTitle(), is("Game title"));
    assertThat(game.getHost(), is(player1));
    assertThat(game.getFeaturedMod().getTechnicalName(), is(FAF_TECHNICAL_NAME));
    assertThat(game.getMapVersion(), is(notNullValue()));
    assertThat(game.getMapName(), is(MAP_NAME));
    assertThat(game.getPassword(), is("secret"));
    assertThat(game.getState(), is(GameState.OPEN));
    assertThat(game.getGameVisibility(), is(GameVisibility.PUBLIC));
    assertThat(game.getMinRating(), is(GAME_MIN_RATING));
    assertThat(game.getMaxRating(), is(GAME_MAX_RATING));
    assertThat(player1.getCurrentGame(), is(game));
    return game;
}
Also used : Game(com.faforever.server.entity.Game)

Example 29 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method updateAiOptionFactionIgnored.

@Test
public void updateAiOptionFactionIgnored() throws Exception {
    Game game = hostGame(player1);
    assertThat(game.getAiOptions().containsKey(QAI), is(false));
    instance.updateAiOption(player1, QAI, OPTION_FACTION, 2);
    assertThat(game.getAiOptions().containsKey(QAI), is(false));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 30 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method restoreGameSessionPlayingGame.

@Test
public void restoreGameSessionPlayingGame() throws Exception {
    Game game = hostGame(player1);
    instance.joinGame(game.getId(), game.getPassword(), player2);
    assertThat(player2.getCurrentGame(), is(game));
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player2);
    instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player2);
    assertThat(player2.getGameState(), is(PlayerGameState.LAUNCHING));
    instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player1);
    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.LAUNCHING));
}
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)

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