Search in sources :

Example 21 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class LobbyGameController method testGame.

@Override
public String testGame(final GUID gameId) {
    final GameDescription description;
    synchronized (mutex) {
        description = allGames.get(gameId);
    }
    if (description == null) {
        return "No such game found";
    }
    // make sure we are being tested from the right node
    final INode from = MessageContext.getSender();
    assertCorrectHost(description, from);
    final int port = description.getPort();
    final String host = description.getHostedBy().getAddress().getHostAddress();
    try (Socket s = new Socket()) {
        s.connect(new InetSocketAddress(host, port), 10 * 1000);
        return null;
    } catch (final IOException e) {
        return "host:" + host + " " + " port:" + port;
    }
}
Also used : INode(games.strategy.net.INode) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Socket(java.net.Socket)

Example 22 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class LobbyGameController method postGame.

@Override
public void postGame(final GUID gameId, final GameDescription description) {
    final INode from = MessageContext.getSender();
    assertCorrectHost(description, from);
    logger.info("Game added:" + description);
    synchronized (mutex) {
        allGames.put(gameId, description);
    }
    broadcaster.gameUpdated(gameId, description);
}
Also used : INode(games.strategy.net.INode)

Example 23 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class LobbyMenu method addDisplayPlayersInformationMenu.

private void addDisplayPlayersInformationMenu(final JMenu parentMenu) {
    final JMenuItem revive = new JMenuItem("Display Players Information");
    revive.setEnabled(true);
    revive.addActionListener(event -> new Thread(() -> {
        final IModeratorController controller = (IModeratorController) lobbyFrame.getLobbyClient().getMessengers().getRemoteMessenger().getRemote(ModeratorController.getModeratorControllerName());
        final StringBuilder builder = new StringBuilder();
        builder.append("Online Players:\r\n\r\n");
        for (final INode player : lobbyFrame.getChatMessagePanel().getChat().getOnlinePlayers()) {
            builder.append(controller.getInformationOn(player)).append("\r\n\r\n");
        }
        builder.append("Players That Have Left (Last 10):\r\n\r\n");
        for (final INode player : lobbyFrame.getChatMessagePanel().getChat().getPlayersThatLeft_Last10()) {
            builder.append(controller.getInformationOn(player)).append("\r\n\r\n");
        }
        SwingUtilities.invokeLater(() -> {
            final JDialog dialog = new JDialog(lobbyFrame, "Players Information");
            final JTextArea label = new JTextArea(builder.toString());
            label.setFont(new Font("Segoe UI", Font.PLAIN, 12));
            label.setEditable(false);
            label.setAutoscrolls(true);
            label.setLineWrap(false);
            label.setFocusable(true);
            label.setWrapStyleWord(true);
            label.setLocation(0, 0);
            dialog.setBackground(label.getBackground());
            dialog.setLayout(new BorderLayout());
            final JScrollPane pane = new JScrollPane();
            pane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            pane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
            pane.setViewportView(label);
            dialog.add(pane, BorderLayout.CENTER);
            final JButton button = new JButton("Close");
            button.addActionListener(e -> dialog.dispose());
            button.setMinimumSize(new Dimension(100, 30));
            dialog.add(button, BorderLayout.SOUTH);
            dialog.setMinimumSize(new Dimension(500, 300));
            dialog.setSize(new Dimension(800, 600));
            dialog.setResizable(true);
            dialog.setLocationRelativeTo(lobbyFrame);
            dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        });
    }).start());
    parentMenu.add(revive);
}
Also used : JScrollPane(javax.swing.JScrollPane) IModeratorController(games.strategy.engine.lobby.server.IModeratorController) INode(games.strategy.net.INode) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) JMenuItem(javax.swing.JMenuItem) JDialog(javax.swing.JDialog) Font(java.awt.Font)

Example 24 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class ModeratorControllerIntegrationTest method testBoot.

@Test
public void testBoot() throws UnknownHostException {
    MessageContext.setSenderNodeForThread(adminNode);
    connectionChangeListener = new ConnectionChangeListener();
    final INode booted = new Node("foo", InetAddress.getByAddress(new byte[] { 1, 2, 3, 4 }), 0);
    doAnswer((Answer<Void>) invocation -> {
        connectionChangeListener.connectionRemoved(invocation.getArgument(0));
        return null;
    }).when(serverMessenger).removeConnection(booted);
    final INode dummyNode = new Node("dummy", InetAddress.getLocalHost(), 0);
    when(serverMessenger.getServerNode()).thenReturn(dummyNode);
    moderatorController.boot(booted);
    assertTrue(connectionChangeListener.getRemoved().contains(booted));
}
Also used : IConnectionChangeListener(games.strategy.net.IConnectionChangeListener) BeforeEach(org.junit.jupiter.api.BeforeEach) MessageContext(games.strategy.engine.message.MessageContext) INode(games.strategy.net.INode) Integration(games.strategy.test.Integration) Random(java.util.Random) Mockito.when(org.mockito.Mockito.when) UnknownHostException(java.net.UnknownHostException) MacFinder(games.strategy.net.MacFinder) Util(games.strategy.util.Util) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Answer(org.mockito.stubbing.Answer) List(java.util.List) Node(games.strategy.net.Node) IServerMessenger(games.strategy.net.IServerMessenger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.doAnswer(org.mockito.Mockito.doAnswer) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) BCrypt(org.mindrot.jbcrypt.BCrypt) IConnectionChangeListener(games.strategy.net.IConnectionChangeListener) UserController(games.strategy.engine.lobby.server.db.UserController) Mockito.mock(org.mockito.Mockito.mock) INode(games.strategy.net.INode) INode(games.strategy.net.INode) Node(games.strategy.net.Node) Test(org.junit.jupiter.api.Test)

Example 25 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class StatusTest method testStatus.

@Test
public void testStatus() throws Exception {
    final IServerMessenger messenger = mock(IServerMessenger.class);
    final INode dummyNode = new Node("dummy", InetAddress.getLocalHost(), 0);
    when(messenger.getLocalNode()).thenReturn(dummyNode);
    when(messenger.getServerNode()).thenReturn(dummyNode);
    when(messenger.isConnected()).thenReturn(true);
    when(messenger.isServer()).thenReturn(true);
    final Messengers messengers = new Messengers(messenger);
    final StatusManager manager = new StatusManager(messengers);
    assertNull(manager.getStatus(messenger.getLocalNode()));
    manager.setStatus("test");
    Interruptibles.sleep(200);
    assertEquals("test", manager.getStatus(messenger.getLocalNode()));
    assertEquals("test", new StatusManager(messengers).getStatus(messenger.getLocalNode()));
}
Also used : INode(games.strategy.net.INode) Messengers(games.strategy.net.Messengers) INode(games.strategy.net.INode) Node(games.strategy.net.Node) IServerMessenger(games.strategy.net.IServerMessenger) Test(org.junit.jupiter.api.Test)

Aggregations

INode (games.strategy.net.INode)46 IModeratorController (games.strategy.engine.lobby.server.IModeratorController)10 RemoteName (games.strategy.engine.message.RemoteName)8 BorderLayout (java.awt.BorderLayout)8 JLabel (javax.swing.JLabel)7 JPanel (javax.swing.JPanel)7 JPasswordField (javax.swing.JPasswordField)5 IServerMessenger (games.strategy.net.IServerMessenger)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Node (games.strategy.net.Node)3 Dimension (java.awt.Dimension)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)3 JComboBox (javax.swing.JComboBox)3 Chat (games.strategy.engine.chat.Chat)2 GameRunner (games.strategy.engine.framework.GameRunner)2 IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)2