Search in sources :

Example 51 with Player

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

the class MatchMakerServiceTest method onClientDisconnect.

@Test
public void onClientDisconnect() throws Exception {
    Player player1 = (Player) new Player().setLogin(LOGIN_PLAYER_1).setId(1);
    Player player2 = (Player) new Player().setLogin(LOGIN_PLAYER_2).setId(2);
    instance.submitSearch(player1, Faction.CYBRAN, QUEUE_NAME);
    instance.submitSearch(player2, Faction.AEON, QUEUE_NAME);
    assertThat(instance.getSearchPools().get(QUEUE_NAME).keySet(), hasSize(2));
    instance.removePlayer(player1);
    assertThat(instance.getSearchPools().get(QUEUE_NAME).keySet(), hasSize(1));
}
Also used : Player(com.faforever.server.entity.Player) Test(org.junit.Test)

Example 52 with Player

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

the class PlayerServiceTest method setUp.

@Before
public void setUp() throws Exception {
    player = (Player) new Player().setId(1);
    player.setLogin("JUnit");
    instance = new PlayerService(clientService, counterService, eventPublisher);
}
Also used : Player(com.faforever.server.entity.Player) Before(org.junit.Before)

Example 53 with Player

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

the class CoopServiceTest method reportOperationComplete.

@Test
public void reportOperationComplete() throws Exception {
    Game game = new Game().setId(42).setMapName("SCMP_001");
    Map<Integer, GamePlayerStats> playerStats = game.getPlayerStats();
    playerStats.put(1, new GamePlayerStats());
    playerStats.put(2, new GamePlayerStats());
    playerStats.put(3, new GamePlayerStats());
    Player player = new Player();
    player.setCurrentGame(game);
    CoopMap mission = new CoopMap();
    when(coopMapRepository.findOneByFilenameLikeIgnoreCase("SCMP_001")).thenReturn(Optional.of(mission));
    instance.reportOperationComplete(player, false, Duration.ofMinutes(8));
    ArgumentCaptor<CoopLeaderboardEntry> captor = ArgumentCaptor.forClass(CoopLeaderboardEntry.class);
    verify(coopLeaderboardRepository).save(captor.capture());
    CoopLeaderboardEntry entry = captor.getValue();
    assertThat(entry.getGameId(), is(42L));
    assertThat(entry.getMission(), is(mission));
    assertThat(entry.getPlayerCount(), is(3));
    assertThat(entry.getTime(), is(Time.from(Instant.EPOCH.plus(Duration.ofMinutes(8)))));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) CoopMap(com.faforever.server.entity.CoopMap) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) CoopLeaderboardEntry(com.faforever.server.entity.CoopLeaderboardEntry) Test(org.junit.Test)

Example 54 with Player

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

the class GameServiceTest method scoresCalculatedCorrectly.

/**
 * Tests that scores are calculated based on the reports of the majority of players that are still connected when the
 * game ends, even if there are kiddies trying to trick the system. The only case they are able to do so is if they
 * stay until the end of the game and share the majority of the result reports. The only way to prevent this would be
 * a neutral referee who can always be trusted.
 */
@Test
public void scoresCalculatedCorrectly() throws Exception {
    Player player3 = (Player) new Player().setId(3);
    Player player4 = (Player) new Player().setId(4);
    Player player5 = (Player) new Player().setId(5);
    Player player6 = (Player) new Player().setId(6);
    Player player7 = (Player) new Player().setId(7);
    Player player8 = (Player) new Player().setId(8);
    Game game = hostGame(player1);
    Stream.of(player2, player3, player4, player5, player6, player7, player8).forEach(player -> addPlayer(game, player));
    Stream.of(player1, player3, player5, player7).forEach(player -> instance.updatePlayerOption(player1, player.getId(), OPTION_TEAM, 2));
    Stream.of(player2, player4, player6, player8).forEach(player -> instance.updatePlayerOption(player1, player.getId(), OPTION_TEAM, 3));
    Stream.of(player1, player2, player3, player4, player5, player6, player7, player8).forEach(player -> instance.updatePlayerOption(player1, player.getId(), OPTION_ARMY, player.getId()));
    launchGame(game);
    // 6 of 8 players got killed, player 1 - 3 are the only ones who report the correct result
    Stream.of(player1, player2, player3).forEach(reporter -> {
        // Army 3-8 have been defeated
        IntStream.range(3, 9).forEach(armyId -> {
            instance.reportArmyOutcome(reporter, armyId, Outcome.DEFEAT);
            instance.reportArmyScore(reporter, armyId, -1);
        });
        // Army 1 and 2 scored and are still in game
        IntStream.range(1, 3).forEach(armyId -> instance.reportArmyScore(reporter, armyId, 3));
    });
    // Players 4 - 8 are kiddies who try to trick the score system by reporting everybody but players 1 and 2 lost
    Stream.of(player4, player5, player6, player7, player8).forEach(reporter -> {
        // Army 1 and 2 have allegedly been defeated
        IntStream.range(1, 3).forEach(armyId -> {
            instance.reportArmyOutcome(reporter, armyId, Outcome.DEFEAT);
            instance.reportArmyScore(reporter, armyId, -1);
        });
        // Armies 3 - 8 allegedly won
        IntStream.range(3, 9).forEach(armyId -> {
            instance.reportArmyOutcome(reporter, armyId, Outcome.VICTORY);
            instance.reportArmyScore(reporter, armyId, 10);
        });
    });
    // All but players 1, 2, and 3 disconnect
    Stream.of(player4, player5, player6, player7, player8).forEach(player -> instance.removePlayer(player));
    // Player 1 claims to have defeated player 2, but player 2 and 3 claim that player 1 has been defeated.
    instance.reportArmyScore(player1, 1, 4);
    instance.reportArmyOutcome(player1, 1, Outcome.VICTORY);
    instance.reportArmyScore(player1, 2, 2);
    instance.reportArmyOutcome(player1, 2, Outcome.DEFEAT);
    Stream.of(player2, player3).forEach(reporter -> {
        instance.reportArmyScore(reporter, 1, 4);
        instance.reportArmyOutcome(reporter, 1, Outcome.DEFEAT);
        instance.reportArmyScore(reporter, 2, 2);
        instance.reportArmyOutcome(reporter, 2, Outcome.VICTORY);
    });
    /* Even though the intermediate results are the ones reported most often, the results to be considered are the ones
    with an outcome, since only those players saw the end of the game. */
    assertThat(game.getValidity(), is(Validity.VALID));
    // Expect that reports of all disconnected players have been discarded
    assertThat(game.getReportedArmyResults().values(), hasSize(3));
    // Expect all remaining players to have reported army results for all players
    game.getReportedArmyResults().forEach((playerId, resultMap) -> assertThat("Player " + playerId + " did not report all results", resultMap.size(), is(8)));
    assertThat(game.getPlayerStats().get(1).getScore(), is(4));
    assertThat(game.getPlayerStats().get(2).getScore(), is(2));
    assertThat(game.getPlayerStats().get(3).getScore(), is(-1));
    assertThat(game.getPlayerStats().get(4).getScore(), is(-1));
    assertThat(game.getPlayerStats().get(5).getScore(), is(-1));
    assertThat(game.getPlayerStats().get(6).getScore(), is(-1));
    assertThat(game.getPlayerStats().get(7).getScore(), is(-1));
    assertThat(game.getPlayerStats().get(8).getScore(), is(-1));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 55 with Player

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

the class GameServiceTest method disconnectFromGame.

/**
 * Tests whether all but the affected player are informed to drop someone.
 */
@Test
@SuppressWarnings("unchecked")
public void disconnectFromGame() throws Exception {
    Game game = hostGame(player1);
    Player player3 = (Player) new Player().setId(3);
    Player player4 = (Player) new Player().setId(4);
    addPlayer(game, player2);
    addPlayer(game, player3);
    addPlayer(game, player4);
    when(playerService.getOnlinePlayer(3)).thenReturn(Optional.of(player3));
    instance.disconnectPlayerFromGame(player1, 3);
    ArgumentCaptor<List<ConnectionAware>> captor = ArgumentCaptor.forClass((Class) List.class);
    verify(clientService).disconnectPlayerFromGame(eq(3), captor.capture());
    List<ConnectionAware> recipients = captor.getValue();
    assertThat(recipients, hasSize(3));
    assertThat(recipients, hasItems(player1, player2, player4));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) List(java.util.List) ConnectionAware(com.faforever.server.client.ConnectionAware) Test(org.junit.Test)

Aggregations

Player (com.faforever.server.entity.Player)73 Test (org.junit.Test)38 Game (com.faforever.server.entity.Game)25 Before (org.junit.Before)13 ServerProperties (com.faforever.server.config.ServerProperties)11 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)11 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)11 List (java.util.List)11 Slf4j (lombok.extern.slf4j.Slf4j)11 Service (org.springframework.stereotype.Service)11 ClientService (com.faforever.server.client.ClientService)10 ConnectionAware (com.faforever.server.client.ConnectionAware)10 FeaturedMod (com.faforever.server.entity.FeaturedMod)10 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)10 Optional (java.util.Optional)10 GlobalRating (com.faforever.server.entity.GlobalRating)9 ModService (com.faforever.server.mod.ModService)9 VisibleForTesting (com.google.common.annotations.VisibleForTesting)9 Duration (java.time.Duration)9 Map (java.util.Map)9