Search in sources :

Example 26 with INode

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

the class HeadlessGameServer method remoteMutePlayer.

public String remoteMutePlayer(final String playerName, final int minutes, 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, "");
    // (48 hours max)
    final Instant expire = Instant.now().plus(Duration.ofMinutes(Math.min(60 * 24 * 2, minutes)));
    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 Mute of Player: " + playerName);
                        messenger.notifyUsernameMutingOfPlayer(realName, expire);
                        messenger.notifyIpMutingOfPlayer(ip, expire);
                        messenger.notifyMacMutingOfPlayer(mac, expire);
                        return;
                    }
                }
            } catch (final Exception e) {
                logger.log(Level.SEVERE, "Failed to notify mute of player", e);
            }
        }).start();
        return null;
    }
    System.out.println("Attempted remote mute 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 27 with INode

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

the class ServerModel method getLauncher.

public Optional<ServerLauncher> getLauncher() {
    synchronized (this) {
        disallowRemoveConnections();
        // -1 since we dont count outselves
        final int clientCount = serverMessenger.getNodes().size() - 1;
        final Map<String, INode> remotePlayers = new HashMap<>();
        for (final Entry<String, String> entry : playersToNodeListing.entrySet()) {
            final String playedBy = entry.getValue();
            if (playedBy == null) {
                return Optional.empty();
            }
            if (!playedBy.equals(serverMessenger.getLocalNode().getName())) {
                serverMessenger.getNodes().stream().filter(node -> node.getName().equals(playedBy)).findAny().ifPresent(node -> remotePlayers.put(entry.getKey(), node));
            }
        }
        return Optional.of(new ServerLauncher(clientCount, remoteMessenger, channelMessenger, serverMessenger, gameSelectorModel, getPlayerListingInternal(), remotePlayers, this, headless));
    }
}
Also used : INode(games.strategy.net.INode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServerLauncher(games.strategy.engine.framework.startup.launcher.ServerLauncher)

Example 28 with INode

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

the class BanPlayerAction 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 ban", 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)) {
            final String realName = node.getName().split(" ")[0];
            final String ip = node.getAddress().getHostAddress();
            final String mac = messenger.getPlayerMac(node.getName());
            messenger.notifyUsernameMiniBanningOfPlayer(realName, null);
            messenger.notifyIpMiniBanningOfPlayer(ip, null);
            messenger.notifyMacMiniBanningOfPlayer(mac, null);
            messenger.removeConnection(node);
            return;
        }
    }
}
Also used : INode(games.strategy.net.INode) JComboBox(javax.swing.JComboBox) TreeSet(java.util.TreeSet) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 29 with INode

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

the class MutePlayerAction 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 mute", 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)) {
            final String realName = node.getName().split(" ")[0];
            final String ip = node.getAddress().getHostAddress();
            final String mac = messenger.getPlayerMac(node.getName());
            messenger.notifyUsernameMutingOfPlayer(realName, null);
            messenger.notifyIpMutingOfPlayer(ip, null);
            messenger.notifyMacMutingOfPlayer(mac, null);
            return;
        }
    }
}
Also used : INode(games.strategy.net.INode) JComboBox(javax.swing.JComboBox) TreeSet(java.util.TreeSet) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 30 with INode

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

the class SetMapClientAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final INode serverNode = clientMessenger.getServerNode();
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
    final JComboBox<String> combo = new JComboBox<>(model);
    model.addElement("");
    for (final String game : availableGames) {
        model.addElement(game);
    }
    if (serverNode == null || model.getSize() <= 1) {
        JOptionPane.showMessageDialog(parent, "No available games", "No available games", JOptionPane.ERROR_MESSAGE);
        return;
    }
    final int selectedOption = JOptionPane.showConfirmDialog(parent, combo, "Change Game To: ", JOptionPane.OK_CANCEL_OPTION);
    if (selectedOption != JOptionPane.OK_OPTION) {
        return;
    }
    final String name = (String) combo.getSelectedItem();
    if (name == null || name.length() <= 1) {
        return;
    }
    clientMessenger.changeServerGameTo(name);
}
Also used : INode(games.strategy.net.INode) JComboBox(javax.swing.JComboBox) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

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