Search in sources :

Example 91 with Game

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

the class GameServiceTest method reportArmyOutcome.

@Test
public void reportArmyOutcome() throws Exception {
    Game game = hostGame(player1);
    addPlayer(game, player2);
    instance.updatePlayerOption(player1, player1.getId(), OPTION_ARMY, 1);
    instance.updatePlayerOption(player1, player2.getId(), OPTION_ARMY, 2);
    launchGame(game);
    instance.reportArmyOutcome(player1, 1, Outcome.VICTORY);
    instance.reportArmyOutcome(player1, 2, Outcome.DEFEAT);
    instance.reportArmyOutcome(player2, 1, Outcome.VICTORY);
    instance.reportArmyOutcome(player2, 2, Outcome.DEFEAT);
    assertThat(game.getReportedArmyResults().values(), hasSize(2));
    assertThat(game.getReportedArmyResults().get(player1.getId()).values(), hasSize(2));
    assertThat(game.getReportedArmyResults().get(player2.getId()).values(), hasSize(2));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 92 with Game

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

the class GameServiceTest method updateGameStateIdle.

@Test
public void updateGameStateIdle() throws Exception {
    instance.createGame("Game title", FAF_TECHNICAL_NAME, MAP_NAME, "secret", GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1);
    instance.updatePlayerGameState(PlayerGameState.IDLE, player1);
    Game game = instance.getActiveGame(1).get();
    assertThat(game.getState(), is(GameState.INITIALIZING));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 93 with Game

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

the class TeamKillService method reportTeamKill.

public void reportTeamKill(Player player, Duration timeDelta, int killerId, int victimId) {
    Optional<Player> victim = playerService.getOnlinePlayer(victimId);
    Optional<Player> killer = playerService.getOnlinePlayer(killerId);
    Game game = player.getCurrentGame();
    if (game == null) {
        log.warn("Player '{}' reported team kill by '{}' but is not associated with a game", player, killer);
        return;
    }
    // Player's shouldn't even be able to specify a victim, but that's what the current protocol allows.
    if (victimId != player.getId()) {
        log.warn("Player '{}' reported team kill by '{}' for player '{}'", player, killer, victim);
        return;
    }
    if (!killer.isPresent()) {
        log.warn("Player '{}' reported team kill by unknown player '{}' in game '{}' (victim: '{}')", player, killerId, game, victim);
        return;
    }
    boolean isKillerPartOfGame = game.getPlayerStats().values().stream().anyMatch(gamePlayerStats -> gamePlayerStats.getPlayer().getId() == killerId);
    if (!isKillerPartOfGame) {
        log.warn("Player '{}' reported team kill by '{}' in game '{}', but killer is not part of the game", player, killer, game);
    }
    log.debug("Player '{}' reported team kill by '{}' in game: {}", victim, killer, game);
    TeamKill teamKill = new TeamKill(0, killerId, victimId, game.getId(), (int) timeDelta.getSeconds(), Timestamp.from(Instant.now()));
    teamKillRepository.save(teamKill);
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) TeamKill(com.faforever.server.entity.TeamKill)

Example 94 with Game

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

the class ClientServiceTest method startGameProcess.

@Test
public void startGameProcess() throws Exception {
    Game game = new Game().setId(1).setFeaturedMod(new FeaturedMod());
    instance.startGameProcess(game, player);
    ArgumentCaptor<StartGameProcessResponse> captor = ArgumentCaptor.forClass(StartGameProcessResponse.class);
    verify(clientGateway).send(captor.capture(), any());
    assertThat(captor.getValue().getGameId(), is(1));
}
Also used : Game(com.faforever.server.entity.Game) FeaturedMod(com.faforever.server.entity.FeaturedMod) StartGameProcessResponse(com.faforever.server.game.StartGameProcessResponse) Test(org.junit.Test)

Example 95 with Game

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

the class ClientServiceTest method connectToHost.

@Test
public void connectToHost() throws Exception {
    Game game = new Game().setHost((Player) new Player().setLogin("JUnit").setId(1));
    instance.connectToHost(player, game);
    verify(clientGateway).send(new ConnectToHostResponse("JUnit", 1), clientConnection);
}
Also used : Player(com.faforever.server.entity.Player) 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