Search in sources :

Example 6 with UnifiedMessenger

use of games.strategy.engine.message.unifiedmessenger.UnifiedMessenger 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

UnifiedMessenger (games.strategy.engine.message.unifiedmessenger.UnifiedMessenger)6 ChannelMessenger (games.strategy.engine.message.ChannelMessenger)5 IServerMessenger (games.strategy.net.IServerMessenger)5 IRemoteMessenger (games.strategy.engine.message.IRemoteMessenger)4 RemoteMessenger (games.strategy.engine.message.RemoteMessenger)4 ClientMessenger (games.strategy.net.ClientMessenger)4 IChannelMessenger (games.strategy.engine.message.IChannelMessenger)3 ChatPanel (games.strategy.engine.chat.ChatPanel)2 IChatPanel (games.strategy.engine.chat.IChatPanel)2 NullModeratorController (games.strategy.engine.lobby.server.NullModeratorController)2 ServerMessenger (games.strategy.net.ServerMessenger)2 ClientLogger (games.strategy.debug.ClientLogger)1 ClientContext (games.strategy.engine.ClientContext)1 ChatController (games.strategy.engine.chat.ChatController)1 HeadlessChat (games.strategy.engine.chat.HeadlessChat)1 GameStepListener (games.strategy.engine.data.events.GameStepListener)1 LOBBY_GAME_COMMENTS (games.strategy.engine.framework.CliProperties.LOBBY_GAME_COMMENTS)1 LOBBY_GAME_HOSTED_BY (games.strategy.engine.framework.CliProperties.LOBBY_GAME_HOSTED_BY)1 LOBBY_HOST (games.strategy.engine.framework.CliProperties.LOBBY_HOST)1 LOBBY_PORT (games.strategy.engine.framework.CliProperties.LOBBY_PORT)1