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));
}
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));
}
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);
}
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));
}
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);
}
Aggregations