Search in sources :

Example 1 with ChatController

use of games.strategy.engine.chat.ChatController in project triplea by triplea-game.

the class ServerModel method createServerMessenger.

/**
 * UI can be null. We use it as the parent for message dialogs we show.
 * If you have a component displayed, use it.
 */
boolean createServerMessenger(@Nullable final Component ui, @Nonnull final ServerConnectionProps props) {
    this.ui = (ui == null) ? null : JOptionPane.getFrameForComponent(ui);
    try {
        serverMessenger = new ServerMessenger(props.getName(), props.getPort(), objectStreamFactory);
        final ClientLoginValidator clientLoginValidator = new ClientLoginValidator(serverMessenger);
        clientLoginValidator.setGamePassword(props.getPassword());
        serverMessenger.setLoginValidator(clientLoginValidator);
        serverMessenger.addErrorListener(this);
        serverMessenger.addConnectionChangeListener(this);
        final UnifiedMessenger unifiedMessenger = new UnifiedMessenger(serverMessenger);
        remoteMessenger = new RemoteMessenger(unifiedMessenger);
        remoteMessenger.registerRemote(serverStartupRemote, SERVER_REMOTE_NAME);
        channelMessenger = new ChannelMessenger(unifiedMessenger);
        final NullModeratorController moderatorController = new NullModeratorController(serverMessenger, null);
        moderatorController.register(remoteMessenger);
        chatController = new ChatController(CHAT_NAME, serverMessenger, remoteMessenger, channelMessenger, moderatorController);
        if (ui == null && headless) {
            chatPanel = new HeadlessChat(serverMessenger, channelMessenger, remoteMessenger, CHAT_NAME, Chat.ChatSoundProfile.GAME_CHATROOM);
        } else {
            chatPanel = new ChatPanel(serverMessenger, channelMessenger, remoteMessenger, CHAT_NAME, Chat.ChatSoundProfile.GAME_CHATROOM);
        }
        serverMessenger.setAcceptNewConnections(true);
        gameDataChanged();
        return true;
    } catch (final IOException ioe) {
        ioe.printStackTrace(System.out);
        if (headless) {
            System.out.println("Unable to create server socket:" + ioe.getMessage());
        } else {
            JOptionPane.showMessageDialog(ui, "Unable to create server socket:" + ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }
}
Also used : RemoteMessenger(games.strategy.engine.message.RemoteMessenger) IRemoteMessenger(games.strategy.engine.message.IRemoteMessenger) UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) ChatController(games.strategy.engine.chat.ChatController) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) NullModeratorController(games.strategy.engine.lobby.server.NullModeratorController) HeadlessChat(games.strategy.engine.chat.HeadlessChat) IChannelMessenger(games.strategy.engine.message.IChannelMessenger) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) IChatPanel(games.strategy.engine.chat.IChatPanel) ChatPanel(games.strategy.engine.chat.ChatPanel) IOException(java.io.IOException) ClientLoginValidator(games.strategy.engine.framework.startup.login.ClientLoginValidator)

Aggregations

ChatController (games.strategy.engine.chat.ChatController)1 ChatPanel (games.strategy.engine.chat.ChatPanel)1 HeadlessChat (games.strategy.engine.chat.HeadlessChat)1 IChatPanel (games.strategy.engine.chat.IChatPanel)1 ClientLoginValidator (games.strategy.engine.framework.startup.login.ClientLoginValidator)1 NullModeratorController (games.strategy.engine.lobby.server.NullModeratorController)1 ChannelMessenger (games.strategy.engine.message.ChannelMessenger)1 IChannelMessenger (games.strategy.engine.message.IChannelMessenger)1 IRemoteMessenger (games.strategy.engine.message.IRemoteMessenger)1 RemoteMessenger (games.strategy.engine.message.RemoteMessenger)1 UnifiedMessenger (games.strategy.engine.message.unifiedmessenger.UnifiedMessenger)1 IServerMessenger (games.strategy.net.IServerMessenger)1 ServerMessenger (games.strategy.net.ServerMessenger)1 IOException (java.io.IOException)1