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;
}
}
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);
}
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);
}
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));
}
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()));
}
Aggregations