Search in sources :

Example 1 with PlayerOnlineEvent

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);
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) SocialRelationStatus(com.faforever.server.entity.SocialRelationStatus) EventListener(org.springframework.context.event.EventListener) RelationType(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse.RelationType) Collectors(java.util.stream.Collectors) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SocialRelation(com.faforever.server.entity.SocialRelation) Service(org.springframework.stereotype.Service) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) ClientService(com.faforever.server.client.ClientService) Transactional(org.springframework.transaction.annotation.Transactional) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) EventListener(org.springframework.context.event.EventListener)

Example 2 with PlayerOnlineEvent

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());
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) FafUserDetails(com.faforever.server.security.FafUserDetails) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) Test(org.junit.Test)

Example 3 with PlayerOnlineEvent

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());
}
Also used : Chat(com.faforever.server.config.ServerProperties.Chat) ProgrammingError(com.faforever.server.error.ProgrammingError) User(com.faforever.server.entity.User) EventListener(org.springframework.context.event.EventListener) Set(java.util.Set) Hashing(com.google.common.hash.Hashing) GroupAssociation(com.faforever.server.entity.GroupAssociation) BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) StandardCharsets(java.nio.charset.StandardCharsets) HashSet(java.util.HashSet) Slf4j(lombok.extern.slf4j.Slf4j) Service(org.springframework.stereotype.Service) ServerProperties(com.faforever.server.config.ServerProperties) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) Optional(java.util.Optional) ClientService(com.faforever.server.client.ClientService) User(com.faforever.server.entity.User) GroupAssociation(com.faforever.server.entity.GroupAssociation) Chat(com.faforever.server.config.ServerProperties.Chat) ProgrammingError(com.faforever.server.error.ProgrammingError) HashSet(java.util.HashSet) EventListener(org.springframework.context.event.EventListener)

Example 4 with PlayerOnlineEvent

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"));
}
Also used : User(com.faforever.server.entity.User) Collection(java.util.Collection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) GameResponses(com.faforever.server.client.GameResponses) Test(org.junit.Test)

Example 5 with PlayerOnlineEvent

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

Aggregations

PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)6 User (com.faforever.server.entity.User)5 Player (com.faforever.server.entity.Player)4 FafUserDetails (com.faforever.server.security.FafUserDetails)3 Test (org.junit.Test)3 ClientService (com.faforever.server.client.ClientService)2 GroupAssociation (com.faforever.server.entity.GroupAssociation)2 SocialRelation (com.faforever.server.entity.SocialRelation)2 SocialRelationResponse (com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 EventListener (org.springframework.context.event.EventListener)2 Service (org.springframework.stereotype.Service)2 GameResponses (com.faforever.server.client.GameResponses)1 ServerProperties (com.faforever.server.config.ServerProperties)1 Chat (com.faforever.server.config.ServerProperties.Chat)1 Clan (com.faforever.server.entity.Clan)1 ClanMembership (com.faforever.server.entity.ClanMembership)1 SocialRelationStatus (com.faforever.server.entity.SocialRelationStatus)1 ProgrammingError (com.faforever.server.error.ProgrammingError)1