Search in sources :

Example 61 with Player

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

the class MatchMakerServiceActivatorTest 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 MatchMakerServiceActivator(matchmakerService, matchMakerMapper);
}
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)

Example 62 with Player

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

Example 63 with Player

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

the class ChatServiceTest method testJoinChannels.

@SuppressWarnings("unchecked")
private void testJoinChannels(Group group, String... expectedChannels) {
    User user = (User) new User().setPassword("pw").setGroupAssociation(group == null ? null : new GroupAssociation().setGroup(group)).setLogin("junit");
    Player player = new Player().setUser(user).setClanMemberships(Collections.singletonList(new ClanMembership().setClan(new Clan().setTag("junit"))));
    instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, player));
    ArgumentCaptor<Set<String>> captor = ArgumentCaptor.forClass((Class) Set.class);
    verify(clientService).sendChatChannels(captor.capture(), any());
    Set<String> channels = captor.getValue();
    assertThat(channels, containsInAnyOrder(expectedChannels));
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) GroupAssociation(com.faforever.server.entity.GroupAssociation) Set(java.util.Set) Clan(com.faforever.server.entity.Clan) ClanMembership(com.faforever.server.entity.ClanMembership) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent)

Example 64 with Player

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

the class ClientConnectionServiceTest method disconnectClient.

@Test
public void disconnectClient() throws Exception {
    ClientConnection clientConnection12 = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
    Player player12 = new Player().setClientConnection(clientConnection12);
    when(playerService.getOnlinePlayer(12)).thenReturn(Optional.of(player12));
    instance.disconnectClient(new TestingAuthenticationToken(new User(), null), 12);
    ArgumentCaptor<CloseConnectionEvent> captor = ArgumentCaptor.forClass(CloseConnectionEvent.class);
    verify(eventPublisher).publishEvent(captor.capture());
    CloseConnectionEvent value = captor.getValue();
    assertThat(value.getClientConnection(), is(clientConnection12));
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 65 with Player

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

the class ClientServiceTest method sendOnlinePlayerList.

@Test
public void sendOnlinePlayerList() throws Exception {
    List<Player> players = Arrays.asList((Player) new Player().setAvailableAvatars(emptyList()).setId(1).setLogin("JUnit").setCountry("CH"), (Player) new Player().setAvailableAvatars(emptyList()).setId(2).setLogin("JUnit").setCountry("CH"));
    ConnectionAware connectionAware = new Player().setClientConnection(clientConnection);
    CompletableFuture<PlayerResponses> sent = new CompletableFuture<>();
    doAnswer(invocation -> sent.complete(invocation.getArgumentAt(0, PlayerResponses.class))).when(clientGateway).send(any(PlayerResponses.class), eq(clientConnection));
    instance.sendPlayerInformation(players, connectionAware);
    PlayerResponses responses = sent.get(10, TimeUnit.SECONDS);
    assertThat(responses.getResponses(), hasSize(2));
    Iterator<PlayerResponse> iterator = responses.getResponses().iterator();
    assertThat(iterator.next().getPlayerId(), is(1));
    assertThat(iterator.next().getPlayerId(), is(2));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Player(com.faforever.server.entity.Player) CompletableFuture(java.util.concurrent.CompletableFuture) 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