Search in sources :

Example 1 with Chat

use of com.faforever.server.config.ServerProperties.Chat in project faf-java-server by FAForever.

the class ChatServiceTest method setUp.

@Before
public void setUp() throws Exception {
    ServerProperties properties = new ServerProperties();
    Chat chat = properties.getChat();
    chat.setAdminChannels(Collections.singletonList("#admins"));
    chat.setModeratorChannels(Collections.singletonList("#moderators"));
    chat.setDefaultChannels(Arrays.asList("#foo", "#bar"));
    chat.setClanChannelFormat("#clan_%s");
    instance = new ChatService(nickCoreRepository, properties, clientService);
}
Also used : ServerProperties(com.faforever.server.config.ServerProperties) Chat(com.faforever.server.config.ServerProperties.Chat) Before(org.junit.Before)

Example 2 with Chat

use of com.faforever.server.config.ServerProperties.Chat 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)

Aggregations

ServerProperties (com.faforever.server.config.ServerProperties)2 Chat (com.faforever.server.config.ServerProperties.Chat)2 ClientService (com.faforever.server.client.ClientService)1 GroupAssociation (com.faforever.server.entity.GroupAssociation)1 User (com.faforever.server.entity.User)1 ProgrammingError (com.faforever.server.error.ProgrammingError)1 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)1 Hashing (com.google.common.hash.Hashing)1 StandardCharsets (java.nio.charset.StandardCharsets)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Before (org.junit.Before)1 EventListener (org.springframework.context.event.EventListener)1 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)1 Service (org.springframework.stereotype.Service)1