Search in sources :

Example 1 with TeamKill

use of com.faforever.server.entity.TeamKill 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 2 with TeamKill

use of com.faforever.server.entity.TeamKill 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)

Aggregations

Game (com.faforever.server.entity.Game)2 Player (com.faforever.server.entity.Player)2 TeamKill (com.faforever.server.entity.TeamKill)2 Test (org.junit.Test)1