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