Search in sources :

Example 6 with Game

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

the class CoopService method reportOperationComplete.

public void reportOperationComplete(Player player, boolean secondaryTargets, Duration duration) {
    Game game = player.getCurrentGame();
    Requests.verify(game != null, ErrorCode.COOP_CANT_REPORT_NOT_IN_GAME);
    log.debug("Player '{}' reported coop result '{}' with secondary targets '{}' for game: {}", player, duration, secondaryTargets, game);
    Optional<CoopMap> optional = coopMapRepository.findOneByFilenameLikeIgnoreCase(game.getMapName());
    if (optional.isPresent()) {
        CoopLeaderboardEntry coopLeaderboardEntry = new CoopLeaderboardEntry();
        coopLeaderboardEntry.setGameId(game.getId());
        coopLeaderboardEntry.setMission(optional.get());
        coopLeaderboardEntry.setPlayerCount(game.getPlayerStats().size());
        coopLeaderboardEntry.setSecondary(secondaryTargets);
        coopLeaderboardEntry.setTime(new Time(duration.toMillis()));
        coopLeaderboardRepository.save(coopLeaderboardEntry);
    }
}
Also used : Game(com.faforever.server.entity.Game) CoopMap(com.faforever.server.entity.CoopMap) CoopLeaderboardEntry(com.faforever.server.entity.CoopLeaderboardEntry) Time(java.sql.Time)

Example 7 with Game

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

the class TeamKillServiceTest method reportTeamKillWhenKillerDoesntExist.

@Test
public void reportTeamKillWhenKillerDoesntExist() throws Exception {
    Player player = new Player();
    player.setCurrentGame(new Game());
    player.setId(1);
    when(playerService.getOnlinePlayer(player.getId())).thenReturn(Optional.of(player));
    instance.reportTeamKill(player, Duration.ofMinutes(28), 991234, player.getId());
    verifyZeroInteractions(teamKillRepository);
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 8 with Game

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

the class TeamKillServiceTest method reportTeamKill.

@Test
public void reportTeamKill() throws Exception {
    Game game = new Game();
    game.setId(10);
    Player player = (Player) new Player().setCurrentGame(game).setId(1);
    Player killer = (Player) new Player().setId(2);
    when(playerService.getOnlinePlayer(player.getId())).thenReturn(Optional.of(player));
    when(playerService.getOnlinePlayer(killer.getId())).thenReturn(Optional.of(killer));
    instance.reportTeamKill(player, Duration.ofMinutes(28), killer.getId(), player.getId());
    ArgumentCaptor<TeamKill> captor = ArgumentCaptor.forClass(TeamKill.class);
    verify(teamKillRepository).save(captor.capture());
    TeamKill teamKill = captor.getValue();
    assertThat(teamKill.getGameId(), is(game.getId()));
    assertThat(teamKill.getTeamKiller(), is(killer.getId()));
    assertThat(teamKill.getVictim(), is(player.getId()));
    assertThat(teamKill.getGameTime(), is((int) Duration.ofMinutes(28).getSeconds()));
    assertThat(teamKill.getReportedAt().after(Timestamp.from(Instant.now().minusSeconds(10))), is(true));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) TeamKill(com.faforever.server.entity.TeamKill) Test(org.junit.Test)

Example 9 with Game

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

the class TeamKillServiceTest method reportTeamKillWhenVictimIsntReported.

@Test
public void reportTeamKillWhenVictimIsntReported() throws Exception {
    Player reporter = new Player();
    reporter.setCurrentGame(new Game());
    reporter.setId(1);
    Player killer = (Player) new Player().setId(2);
    Player victim = (Player) new Player().setId(2);
    when(playerService.getOnlinePlayer(killer.getId())).thenReturn(Optional.of(killer));
    instance.reportTeamKill(reporter, Duration.ofMinutes(28), killer.getId(), victim.getId());
    verifyZeroInteractions(teamKillRepository);
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 10 with Game

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

the class ClientServiceTest method hostGame.

@Test
public void hostGame() throws Exception {
    Game game = new Game().setId(1).setMapName("SCMP_001");
    instance.hostGame(game, player);
    ArgumentCaptor<HostGameResponse> captor = ArgumentCaptor.forClass(HostGameResponse.class);
    verify(clientGateway).send(captor.capture(), any());
    assertThat(captor.getValue().getMapFilename(), is("SCMP_001"));
}
Also used : Game(com.faforever.server.entity.Game) HostGameResponse(com.faforever.server.game.HostGameResponse) 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