Search in sources :

Example 1 with INode

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

the class ServerGame method waitForPlayerToFinishStep.

private void waitForPlayerToFinishStep() {
    final PlayerID playerId = getCurrentStep().getPlayerId();
    // no player specified for the given step
    if (playerId == null) {
        return;
    }
    if (!getCurrentStep().getDelegate().delegateCurrentlyRequiresUserInput()) {
        return;
    }
    final IGamePlayer player = gamePlayers.get(playerId);
    if (player != null) {
        // a local player
        player.start(getCurrentStep().getName());
    } else {
        // a remote player
        final INode destination = playerManager.getNode(playerId.getName());
        final IGameStepAdvancer advancer = (IGameStepAdvancer) remoteMessenger.getRemote(ClientGame.getRemoteStepAdvancerName(destination));
        advancer.startPlayerStep(getCurrentStep().getName(), playerId);
    }
}
Also used : IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) PlayerID(games.strategy.engine.data.PlayerID) INode(games.strategy.net.INode)

Example 2 with INode

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

the class HeadlessGameServer method remoteBanPlayer.

public String remoteBanPlayer(final String playerName, final int hours, final String hashedPassword, final String salt) {
    final String password = System.getProperty(LOBBY_GAME_SUPPORT_PASSWORD, "");
    if (password.equals(GameRunner.NO_REMOTE_REQUESTS_ALLOWED)) {
        return "Host not accepting remote requests!";
    }
    final String localPassword = System.getProperty(LOBBY_GAME_SUPPORT_PASSWORD, "");
    // milliseconds (30 days max)
    final Instant expire = Instant.now().plus(Duration.ofHours(Math.min(24 * 30, hours)));
    if (hashPassword(localPassword, salt).equals(hashedPassword)) {
        new Thread(() -> {
            if (getServerModel() == null) {
                return;
            }
            final IServerMessenger messenger = getServerModel().getMessenger();
            if (messenger == null) {
                return;
            }
            final Set<INode> nodes = messenger.getNodes();
            if (nodes == null) {
                return;
            }
            try {
                for (final INode node : nodes) {
                    final String realName = node.getName().split(" ")[0];
                    final String ip = node.getAddress().getHostAddress();
                    final String mac = messenger.getPlayerMac(node.getName());
                    if (realName.equals(playerName)) {
                        System.out.println("Remote Ban of Player: " + playerName);
                        try {
                            messenger.notifyUsernameMiniBanningOfPlayer(realName, expire);
                        } catch (final Exception e) {
                            logger.log(Level.SEVERE, "Failed to notify username ban of player", e);
                        }
                        try {
                            messenger.notifyIpMiniBanningOfPlayer(ip, expire);
                        } catch (final Exception e) {
                            logger.log(Level.SEVERE, "Failed to notify IP ban of player", e);
                        }
                        try {
                            messenger.notifyMacMiniBanningOfPlayer(mac, expire);
                        } catch (final Exception e) {
                            logger.log(Level.SEVERE, "Failed to notify MAC ban of player", e);
                        }
                        messenger.removeConnection(node);
                    }
                }
            } catch (final Exception e) {
                logger.log(Level.SEVERE, "Failed to notify ban of player", e);
            }
        }).start();
        return null;
    }
    System.out.println("Attempted remote ban player with invalid password.");
    return "Invalid password!";
}
Also used : INode(games.strategy.net.INode) Set(java.util.Set) HashSet(java.util.HashSet) Instant(java.time.Instant) IServerMessenger(games.strategy.net.IServerMessenger)

Example 3 with INode

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

the class BootPlayerAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
    final JComboBox<String> combo = new JComboBox<>(model);
    model.addElement("");
    for (final INode node : new TreeSet<>(messenger.getNodes())) {
        if (!node.equals(messenger.getLocalNode())) {
            model.addElement(node.getName());
        }
    }
    if (model.getSize() == 1) {
        JOptionPane.showMessageDialog(parent, "No remote players", "No Remote Players", JOptionPane.ERROR_MESSAGE);
        return;
    }
    final int selectedOption = JOptionPane.showConfirmDialog(parent, combo, "Select player to remove", JOptionPane.OK_CANCEL_OPTION);
    if (selectedOption != JOptionPane.OK_OPTION) {
        return;
    }
    final String name = (String) combo.getSelectedItem();
    for (final INode node : messenger.getNodes()) {
        if (node.getName().equals(name)) {
            messenger.removeConnection(node);
        }
    }
}
Also used : INode(games.strategy.net.INode) JComboBox(javax.swing.JComboBox) TreeSet(java.util.TreeSet) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 4 with INode

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

the class ChatPlayerPanel method setDynamicPreferredSize.

/**
 * set minimum size based on players (number and max name length) and distribution to playerIDs.
 */
private void setDynamicPreferredSize() {
    final List<INode> onlinePlayers = chat.getOnlinePlayers();
    int maxNameLength = 0;
    final FontMetrics fontMetrics = this.getFontMetrics(UIManager.getFont("TextField.font"));
    for (final INode onlinePlayer : onlinePlayers) {
        maxNameLength = Math.max(maxNameLength, fontMetrics.stringWidth(onlinePlayer.getName()));
    }
    int iconCounter = 0;
    if (setCellRenderer instanceof PlayerChatRenderer) {
        iconCounter = ((PlayerChatRenderer) setCellRenderer).getMaxIconCounter();
    }
    setPreferredSize(new Dimension(maxNameLength + 40 + iconCounter * 14, 80));
}
Also used : INode(games.strategy.net.INode) FontMetrics(java.awt.FontMetrics) Dimension(java.awt.Dimension)

Example 5 with INode

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

the class PlayerChatRenderer method setIconMap.

private void setIconMap() {
    final PlayerManager playerManager = game.getPlayerManager();
    PlayerList playerList;
    game.getData().acquireReadLock();
    try {
        playerList = game.getData().getPlayerList();
    } finally {
        game.getData().releaseReadLock();
    }
    // new HashSet removes duplicates
    for (final INode playerNode : new HashSet<>(playerManager.getPlayerMapping().values())) {
        final Set<String> players = playerManager.getPlayedBy(playerNode);
        if (players.size() > 0) {
            final List<Icon> icons = players.stream().filter(player -> uiContext != null && uiContext.getFlagImageFactory() != null).map(player -> new ImageIcon(uiContext.getFlagImageFactory().getSmallFlag(playerList.getPlayerId(player)))).collect(Collectors.toList());
            maxIconCounter = Math.max(maxIconCounter, icons.size());
            playerMap.put(playerNode.toString(), players);
            if (uiContext == null) {
                iconMap.put(playerNode.toString(), null);
            } else {
                iconMap.put(playerNode.toString(), icons);
            }
        }
    }
}
Also used : DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) INode(games.strategy.net.INode) JList(javax.swing.JList) Set(java.util.Set) PlayerList(games.strategy.engine.data.PlayerList) HashMap(java.util.HashMap) Icon(javax.swing.Icon) Component(java.awt.Component) Collectors(java.util.stream.Collectors) SwingConstants(javax.swing.SwingConstants) PlayerManager(games.strategy.engine.data.PlayerManager) HashSet(java.util.HashSet) List(java.util.List) UiContext(games.strategy.triplea.ui.UiContext) IGame(games.strategy.engine.framework.IGame) ImageIcon(javax.swing.ImageIcon) Joiner(com.google.common.base.Joiner) ImageIcon(javax.swing.ImageIcon) INode(games.strategy.net.INode) PlayerManager(games.strategy.engine.data.PlayerManager) PlayerList(games.strategy.engine.data.PlayerList) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) HashSet(java.util.HashSet)

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