use of com.faforever.server.player.PlayerOnlineEvent in project faf-java-server by FAForever.
the class SocialService method onPlayerOnlineEvent.
@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
Player player = event.getPlayer();
List<SocialRelation> socialRelations = player.getSocialRelations();
if (socialRelations == null) {
return;
}
clientService.sendSocialRelations(new SocialRelationListResponse(socialRelations.stream().map(socialRelation -> new SocialRelationResponse(socialRelation.getSubjectId(), RelationType.valueOf(socialRelation.getStatus().toString()))).collect(Collectors.toList())), player);
}
use of com.faforever.server.player.PlayerOnlineEvent in project faf-java-server by FAForever.
the class SocialServiceTest method onAuthenticationSuccessNullRelations.
@Test
public void onAuthenticationSuccessNullRelations() throws Exception {
User user = (User) new User().setPlayer(new Player().setSocialRelations(null)).setPassword("pw").setLogin("junit");
FafUserDetails userDetails = new FafUserDetails(user);
instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, userDetails.getPlayer()));
verify(clientService, never()).sendSocialRelations(any(), any());
}
use of com.faforever.server.player.PlayerOnlineEvent in project faf-java-server by FAForever.
the class ChatService method onPlayerOnlineEvent.
@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
Chat chat = properties.getChat();
Set<String> channels = new HashSet<>(3, 1);
channels.addAll(chat.getDefaultChannels());
Optional.ofNullable(event.getPlayer().getClan()).map(clan -> (String.format(chat.getClanChannelFormat(), clan.getTag()))).ifPresent(channels::add);
User user = event.getPlayer().getUser();
GroupAssociation groupAssociation = user.getGroupAssociation();
if (groupAssociation != null) {
switch(groupAssociation.getGroup()) {
case ADMIN:
channels.addAll(chat.getAdminChannels());
break;
case MODERATOR:
channels.addAll(chat.getModeratorChannels());
break;
default:
throw new ProgrammingError("Uncovered group: " + groupAssociation.getGroup());
}
}
clientService.sendChatChannels(channels, event.getPlayer());
}
use of com.faforever.server.player.PlayerOnlineEvent in project faf-java-server by FAForever.
the class GameServiceTest method onAuthenticationSuccess.
@Test
@SuppressWarnings("unchecked")
public void onAuthenticationSuccess() throws Exception {
player1.setCurrentGame(null);
instance.createGame("Test game", FAF_TECHNICAL_NAME, MAP_NAME, null, GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1);
TestingAuthenticationToken authentication = new TestingAuthenticationToken("JUnit", "foo");
authentication.setDetails(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null));
instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, player2));
ArgumentCaptor<GameResponses> captor = ArgumentCaptor.forClass((Class) Collection.class);
verify(clientService).sendGameList(captor.capture(), eq(player2));
GameResponses games = captor.getValue();
assertThat(games.getResponses(), hasSize(1));
assertThat(games.getResponses().iterator().next().getTitle(), is("Test game"));
}
use of com.faforever.server.player.PlayerOnlineEvent 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));
}
Aggregations