Search in sources :

Example 6 with ChannelMessenger

use of games.strategy.engine.message.ChannelMessenger in project triplea by triplea-game.

the class ChatIntegrationTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    serverMessenger = new ServerMessenger("Server", 0);
    serverMessenger.setAcceptNewConnections(true);
    final int serverPort = serverMessenger.getLocalNode().getSocketAddress().getPort();
    final String mac = MacFinder.getHashedMacAddress();
    client1Messenger = new ClientMessenger("localhost", serverPort, "client1", mac);
    client2Messenger = new ClientMessenger("localhost", serverPort, "client2", mac);
    final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(serverMessenger);
    serverRemoteMessenger = new RemoteMessenger(serverUnifiedMessenger);
    serverChannelMessenger = new ChannelMessenger(serverUnifiedMessenger);
    final UnifiedMessenger client1UnifiedMessenger = new UnifiedMessenger(client1Messenger);
    client1RemoteMessenger = new RemoteMessenger(client1UnifiedMessenger);
    client1ChannelMessenger = new ChannelMessenger(client1UnifiedMessenger);
    final UnifiedMessenger client2UnifiedMessenger = new UnifiedMessenger(client2Messenger);
    client2RemoteMessenger = new RemoteMessenger(client2UnifiedMessenger);
    client2ChannelMessenger = new ChannelMessenger(client2UnifiedMessenger);
    serverModeratorController = new NullModeratorController(serverMessenger, null);
    serverModeratorController.register(serverRemoteMessenger);
}
Also used : IRemoteMessenger(games.strategy.engine.message.IRemoteMessenger) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) NullModeratorController(games.strategy.engine.lobby.server.NullModeratorController) IChannelMessenger(games.strategy.engine.message.IChannelMessenger) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) ClientMessenger(games.strategy.net.ClientMessenger) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ChannelMessenger

use of games.strategy.engine.message.ChannelMessenger in project triplea by triplea-game.

the class VaultTest method setUp.

@BeforeEach
public void setUp() throws IOException {
    serverMessenger = new ServerMessenger("Server", 0);
    serverMessenger.setAcceptNewConnections(true);
    final int serverPort = serverMessenger.getLocalNode().getSocketAddress().getPort();
    final String mac = MacFinder.getHashedMacAddress();
    clientMessenger = new ClientMessenger("localhost", serverPort, "client1", mac);
    final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(serverMessenger);
    final UnifiedMessenger clientUnifiedMessenger = new UnifiedMessenger(clientMessenger);
    serverVault = new Vault(new ChannelMessenger(serverUnifiedMessenger));
    clientVault = new Vault(new ChannelMessenger(clientUnifiedMessenger));
    Thread.yield();
}
Also used : UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) ClientMessenger(games.strategy.net.ClientMessenger) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ChannelMessenger

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

ChannelMessenger (games.strategy.engine.message.ChannelMessenger)8 UnifiedMessenger (games.strategy.engine.message.unifiedmessenger.UnifiedMessenger)6 ClientMessenger (games.strategy.net.ClientMessenger)6 IServerMessenger (games.strategy.net.IServerMessenger)5 IChannelMessenger (games.strategy.engine.message.IChannelMessenger)4 IRemoteMessenger (games.strategy.engine.message.IRemoteMessenger)4 RemoteMessenger (games.strategy.engine.message.RemoteMessenger)4 ServerMessenger (games.strategy.net.ServerMessenger)4 ChatPanel (games.strategy.engine.chat.ChatPanel)3 IChatPanel (games.strategy.engine.chat.IChatPanel)3 IOException (java.io.IOException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 PlayerListing (games.strategy.engine.framework.message.PlayerListing)2 ClientLogin (games.strategy.engine.framework.startup.login.ClientLogin)2 RemoteName (games.strategy.engine.message.RemoteName)2 CouldNotLogInException (games.strategy.net.CouldNotLogInException)2 IClientMessenger (games.strategy.net.IClientMessenger)2 Test (org.junit.jupiter.api.Test)2 Preconditions (com.google.common.base.Preconditions)1 ClientLogger (games.strategy.debug.ClientLogger)1