Search in sources :

Example 31 with Player

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

the class GameServiceTest method reportArmyScoreWithCheater.

/**
 * Tests whether the service correctly chooses the scores reported by the majority of connected players and ignores
 * the results reported by a "cheater" (that is, someone who reports different results).
 */
@Test
public void reportArmyScoreWithCheater() throws Exception {
    Game game = hostGame(player1);
    Player player3 = (Player) new Player().setId(3);
    addPlayer(game, player2);
    addPlayer(game, player3);
    instance.updatePlayerOption(player1, player1.getId(), OPTION_ARMY, 1);
    instance.updatePlayerOption(player1, player2.getId(), OPTION_ARMY, 2);
    instance.updatePlayerOption(player1, player3.getId(), OPTION_ARMY, 3);
    launchGame(game);
    instance.reportArmyScore(player1, 1, 10);
    instance.reportArmyScore(player1, 2, -1);
    instance.reportArmyScore(player1, 3, -1);
    instance.reportArmyOutcome(player1, 1, Outcome.VICTORY);
    instance.reportArmyOutcome(player1, 2, Outcome.DEFEAT);
    instance.reportArmyOutcome(player1, 3, Outcome.DEFEAT);
    instance.reportArmyScore(player2, 1, 10);
    instance.reportArmyScore(player2, 2, -1);
    instance.reportArmyScore(player2, 3, -1);
    instance.reportArmyOutcome(player2, 1, Outcome.VICTORY);
    instance.reportArmyOutcome(player2, 2, Outcome.DEFEAT);
    instance.reportArmyOutcome(player2, 3, Outcome.DEFEAT);
    instance.reportArmyScore(player3, 1, -1);
    instance.reportArmyScore(player3, 2, -1);
    instance.reportArmyScore(player3, 3, 10);
    instance.reportArmyOutcome(player3, 1, Outcome.DEFEAT);
    instance.reportArmyOutcome(player3, 2, Outcome.DEFEAT);
    instance.reportArmyOutcome(player3, 3, Outcome.VICTORY);
    instance.updatePlayerGameState(PlayerGameState.ENDED, player1);
    instance.updatePlayerGameState(PlayerGameState.ENDED, player2);
    instance.updatePlayerGameState(PlayerGameState.ENDED, player3);
    assertThat(game.getPlayerStats().values(), hasSize(3));
    assertThat(game.getPlayerStats().get(player1.getId()).getScore(), is(10));
    assertThat(game.getPlayerStats().get(player2.getId()).getScore(), is(-1));
    assertThat(game.getPlayerStats().get(player3.getId()).getScore(), is(-1));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 32 with Player

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

the class GameServiceTest method mutualDrawRequestedByAllPlayers.

@Test
public void mutualDrawRequestedByAllPlayers() throws Exception {
    Game game = hostGame(player1);
    instance.updatePlayerOption(player1, player1.getId(), OPTION_TEAM, 2);
    instance.joinGame(game.getId(), game.getPassword(), player2);
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player2);
    instance.updatePlayerOption(player1, player2.getId(), OPTION_TEAM, 3);
    Player player3 = new Player();
    player3.setId(3);
    instance.joinGame(game.getId(), game.getPassword(), player3);
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player3);
    instance.updatePlayerOption(player1, player3.getId(), OPTION_TEAM, GameService.OBSERVERS_TEAM_ID);
    launchGame(game);
    instance.mutuallyAgreeDraw(player1);
    assertThat(game.isMutuallyAgreedDraw(), is(false));
    instance.mutuallyAgreeDraw(player2);
    assertThat(game.isMutuallyAgreedDraw(), is(true));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 33 with Player

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

the class LegacyServicesActivatorsTest method setUp.

@Before
public void setUp() throws Exception {
    clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
    player = new Player();
    player.setClientConnection(clientConnection);
    when(geoIpService.lookupCountryCode(any())).thenReturn(Optional.empty());
    instance = new LegacyServicesActivators(authenticationManager, clientService, uniqueIdService, geoIpService, playerService, chatService, counterService);
}
Also used : Player(com.faforever.server.entity.Player) ClientConnection(com.faforever.server.client.ClientConnection) Before(org.junit.Before)

Example 34 with Player

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

the class GameServiceTest method updateGameValidityUnevenTeams.

@Test
public void updateGameValidityUnevenTeams() throws Exception {
    Player player3 = (Player) new Player().setId(3);
    Game game = hostGame(player1);
    addPlayer(game, player2);
    addPlayer(game, player3);
    instance.updatePlayerOption(player1, player1.getId(), OPTION_TEAM, 2);
    instance.updatePlayerOption(player1, player2.getId(), OPTION_TEAM, 2);
    instance.updatePlayerOption(player1, player3.getId(), OPTION_TEAM, 3);
    launchGame(game);
    instance.updateGameValidity(game);
    assertThat(game.getValidity(), is(Validity.UNEVEN_TEAMS));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 35 with Player

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

the class AvatarServiceActivatorTest method setUp.

@Before
public void setUp() throws Exception {
    player = new Player();
    authentication = new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player).setPassword("pw").setLogin("JUnit")), null);
    instance = new AvatarServiceActivator(avatarService);
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

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