Search in sources :

Example 11 with IModeratorController

use of games.strategy.engine.lobby.server.IModeratorController in project triplea by triplea-game.

the class LobbyMenu method addBanMacAddressMenu.

private void addBanMacAddressMenu(final JMenu parentMenu) {
    final JMenuItem item = new JMenuItem("Ban Hashed Mac Address");
    item.addActionListener(e -> {
        final String mac = JOptionPane.showInputDialog(null, "Enter the hashed Mac Address that you want to ban from the lobby.\r\n\r\n" + "Hashed Mac Addresses should be entered in this format: $1$MH$345ntXD4G3AKpAeHZdaGe3", "");
        if (mac == null || mac.length() < 1) {
            return;
        }
        if (!MacFinder.isValidHashedMacAddress(mac)) {
            JOptionPane.showMessageDialog(lobbyFrame, "The hashed Mac Address you entered is invalid.", "Invalid Hashed Mac", JOptionPane.ERROR_MESSAGE);
            return;
        }
        TimespanDialog.prompt(lobbyFrame, "Select Timespan", "Please consult other admins before banning longer than 1 day.", date -> {
            final IModeratorController controller = (IModeratorController) lobbyFrame.getLobbyClient().getMessengers().getRemoteMessenger().getRemote(ModeratorController.getModeratorControllerName());
            controller.banMac(newDummyNode("__unknown__"), mac, date);
        });
    });
    item.setEnabled(true);
    parentMenu.add(item);
}
Also used : IModeratorController(games.strategy.engine.lobby.server.IModeratorController) JMenuItem(javax.swing.JMenuItem)

Example 12 with IModeratorController

use of games.strategy.engine.lobby.server.IModeratorController in project triplea by triplea-game.

the class LobbyFrame method createAdminActions.

private List<Action> createAdminActions(final INode clickedOn) {
    if (!client.isAdmin()) {
        return Collections.emptyList();
    }
    if (clickedOn.equals(client.getMessenger().getLocalNode())) {
        return Collections.emptyList();
    }
    final IModeratorController controller = (IModeratorController) client.getRemoteMessenger().getRemote(ModeratorController.getModeratorControllerName());
    final List<Action> actions = new ArrayList<>();
    actions.add(SwingAction.of("Boot " + clickedOn.getName(), e -> {
        if (!confirm("Boot " + clickedOn.getName())) {
            return;
        }
        controller.boot(clickedOn);
    }));
    actions.add(SwingAction.of("Ban Player", e -> {
        final int resultBanType = JOptionPane.showOptionDialog(LobbyFrame.this, "Select the type of ban:", "Select Ban Type", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, banOrMuteOptions.toArray(), banOrMuteOptions.get(banOrMuteOptions.size() - 1));
        if (resultBanType < 0) {
            return;
        }
        final String selectedBanType = banOrMuteOptions.get(resultBanType);
        if (selectedBanType.equals("Cancel")) {
            return;
        }
        TimespanDialog.prompt(this, "Select Timespan", "Please consult other admins before banning longer than 1 day. \n" + "And please remember to report this ban.", date -> {
            if (selectedBanType.toLowerCase().contains("name")) {
                controller.banUsername(clickedOn, date);
            }
            if (selectedBanType.toLowerCase().contains("mac")) {
                controller.banMac(clickedOn, date);
            }
            // Should we keep this auto?
            controller.boot(clickedOn);
        });
    }));
    actions.add(SwingAction.of("Mute Player", e -> {
        final int resultMuteType = JOptionPane.showOptionDialog(LobbyFrame.this, "<html>Select the type of mute: <br>Please consult other admins before muting longer than 1 day.</html>", "Select Mute Type", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, banOrMuteOptions.toArray(), banOrMuteOptions.get(banOrMuteOptions.size() - 1));
        if (resultMuteType < 0) {
            return;
        }
        final String selectedMuteType = banOrMuteOptions.get(resultMuteType);
        if (selectedMuteType.equals("Cancel")) {
            return;
        }
        TimespanDialog.prompt(this, "Select Timespan", "Please consult other admins before muting longer than 1 day. \n" + "And please remember to report this mute.", date -> {
            if (selectedMuteType.toLowerCase().contains("name")) {
                controller.muteUsername(clickedOn, date);
            }
            if (selectedMuteType.toLowerCase().contains("mac")) {
                controller.muteMac(clickedOn, date);
            }
        });
    }));
    actions.add(SwingAction.of("Quick Mute", e -> {
        final JLabel label = new JLabel("How many minutes should this player be muted?");
        final JSpinner spinner = new JSpinner(new SpinnerNumberModel(10, 0, 60 * 24 * 2, 1));
        final JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
        panel.add(label);
        panel.add(spinner);
        if (JOptionPane.showConfirmDialog(LobbyFrame.this, panel, "Mute Player", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            final Object value = spinner.getValue();
            if (value == null) {
                return;
            }
            final long resultMuteLengthInMinutes = Long.parseLong(value.toString());
            if (resultMuteLengthInMinutes < 0) {
                return;
            }
            final Instant expire = Instant.now().plus(Duration.ofMinutes(resultMuteLengthInMinutes));
            controller.muteUsername(clickedOn, Date.from(expire));
            controller.muteMac(clickedOn, Date.from(expire));
        }
    }));
    actions.add(SwingAction.of("Show player information", e -> {
        final String text = controller.getInformationOn(clickedOn);
        final JTextPane textPane = new JTextPane();
        textPane.setEditable(false);
        textPane.setText(text);
        JOptionPane.showMessageDialog(null, textPane, "Player Info", JOptionPane.INFORMATION_MESSAGE);
    }));
    return actions;
}
Also used : JSplitPane(javax.swing.JSplitPane) Date(java.util.Date) SpinnerNumberModel(javax.swing.SpinnerNumberModel) IModeratorController(games.strategy.engine.lobby.server.IModeratorController) Action(javax.swing.Action) ChatMessagePanel(games.strategy.engine.chat.ChatMessagePanel) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) ChatPlayerPanel(games.strategy.engine.chat.ChatPlayerPanel) ArrayList(java.util.ArrayList) ModeratorController(games.strategy.engine.lobby.server.ModeratorController) ImmutableList(com.google.common.collect.ImmutableList) LobbyClient(games.strategy.engine.lobby.client.LobbyClient) Duration(java.time.Duration) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) LobbyMenu(games.strategy.triplea.ui.menubar.LobbyMenu) BoxLayout(javax.swing.BoxLayout) INode(games.strategy.net.INode) JSpinner(javax.swing.JSpinner) LobbyServerProperties(games.strategy.engine.lobby.client.login.LobbyServerProperties) Chat(games.strategy.engine.chat.Chat) WindowAdapter(java.awt.event.WindowAdapter) Instant(java.time.Instant) JOptionPane(javax.swing.JOptionPane) GameRunner(games.strategy.engine.framework.GameRunner) WindowEvent(java.awt.event.WindowEvent) Dimension(java.awt.Dimension) List(java.util.List) JLabel(javax.swing.JLabel) EventThreadJOptionPane(games.strategy.util.EventThreadJOptionPane) Collections(java.util.Collections) JPanel(javax.swing.JPanel) SwingAction(games.strategy.ui.SwingAction) JPanel(javax.swing.JPanel) IModeratorController(games.strategy.engine.lobby.server.IModeratorController) Action(javax.swing.Action) SwingAction(games.strategy.ui.SwingAction) BoxLayout(javax.swing.BoxLayout) Instant(java.time.Instant) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JTextPane(javax.swing.JTextPane) JSpinner(javax.swing.JSpinner)

Example 13 with IModeratorController

use of games.strategy.engine.lobby.server.IModeratorController in project triplea by triplea-game.

the class LobbyGamePanel method stopGameHeadlessHostBot.

private void stopGameHeadlessHostBot() {
    final int selectedIndex = gameTable.getSelectedRow();
    if (selectedIndex == -1) {
        return;
    }
    final int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to perform a remote stop game on this host?", "Remote Stopgame Headless Host Bot", JOptionPane.OK_CANCEL_OPTION);
    if (result != JOptionPane.OK_OPTION) {
        return;
    }
    final INode lobbyWatcherNode = getLobbyWatcherNodeForTableRow(selectedIndex);
    final IModeratorController controller = (IModeratorController) messengers.getRemoteMessenger().getRemote(AbstractModeratorController.getModeratorControllerName());
    final JLabel label = new JLabel("Enter Host Remote Access Password, (Leave blank for no password).");
    final JPasswordField passwordField = new JPasswordField();
    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(label, BorderLayout.NORTH);
    panel.add(passwordField, BorderLayout.CENTER);
    final int selectedOption = JOptionPane.showOptionDialog(getTopLevelAncestor(), panel, "Host Remote Access Password?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
    if (selectedOption != JOptionPane.OK_OPTION || passwordField.getPassword() == null) {
        return;
    }
    final String password = new String(passwordField.getPassword());
    final String salt = controller.getHeadlessHostBotSalt(lobbyWatcherNode);
    final String hashedPassword = hashPassword(password, salt);
    final String response = controller.stopGameHeadlessHostBot(lobbyWatcherNode, hashedPassword, salt);
    JOptionPane.showMessageDialog(null, (response == null ? "Successfully attempted stop of current game on host" : "Failed: " + response));
}
Also used : JPanel(javax.swing.JPanel) INode(games.strategy.net.INode) IModeratorController(games.strategy.engine.lobby.server.IModeratorController) BorderLayout(java.awt.BorderLayout) JPasswordField(javax.swing.JPasswordField) JLabel(javax.swing.JLabel)

Example 14 with IModeratorController

use of games.strategy.engine.lobby.server.IModeratorController in project triplea by triplea-game.

the class LobbyGamePanel method getHostInfo.

private void getHostInfo() {
    final int selectedIndex = gameTable.getSelectedRow();
    if (selectedIndex == -1) {
        return;
    }
    final INode lobbyWatcherNode = getLobbyWatcherNodeForTableRow(selectedIndex);
    final IModeratorController controller = (IModeratorController) messengers.getRemoteMessenger().getRemote(AbstractModeratorController.getModeratorControllerName());
    final String text = controller.getInformationOn(lobbyWatcherNode);
    final String connections = controller.getHostConnections(lobbyWatcherNode);
    final JTextPane textPane = new JTextPane();
    textPane.setEditable(false);
    textPane.setText(text + "\n\n" + connections);
    JOptionPane.showMessageDialog(null, textPane, "Player Info", JOptionPane.INFORMATION_MESSAGE);
}
Also used : JTextPane(javax.swing.JTextPane) INode(games.strategy.net.INode) IModeratorController(games.strategy.engine.lobby.server.IModeratorController)

Example 15 with IModeratorController

use of games.strategy.engine.lobby.server.IModeratorController in project triplea by triplea-game.

the class LobbyMenu method addUnbanMacAddressMenu.

private void addUnbanMacAddressMenu(final JMenu parentMenu) {
    final JMenuItem item = new JMenuItem("Unban Hashed Mac Address");
    item.addActionListener(e -> {
        final String mac = JOptionPane.showInputDialog(null, "Enter the hashed Mac Address that you want to unban from the lobby.\n\n" + "Hashed Mac Addresses should be entered in this format: $1$MH$345ntXD4G3AKpAeHZdaGe3", "");
        if (mac == null || mac.length() < 1) {
            return;
        }
        if (!MacFinder.isValidHashedMacAddress(mac)) {
            JOptionPane.showMessageDialog(lobbyFrame, "The hashed Mac Address you entered is invalid.", "Invalid Hashed Mac", JOptionPane.ERROR_MESSAGE);
            return;
        }
        final IModeratorController controller = (IModeratorController) lobbyFrame.getLobbyClient().getMessengers().getRemoteMessenger().getRemote(ModeratorController.getModeratorControllerName());
        controller.banMac(newDummyNode("__unknown__"), mac, Date.from(Instant.EPOCH));
    });
    item.setEnabled(true);
    parentMenu.add(item);
}
Also used : IModeratorController(games.strategy.engine.lobby.server.IModeratorController) JMenuItem(javax.swing.JMenuItem)

Aggregations

IModeratorController (games.strategy.engine.lobby.server.IModeratorController)15 INode (games.strategy.net.INode)10 BorderLayout (java.awt.BorderLayout)8 JLabel (javax.swing.JLabel)7 JPanel (javax.swing.JPanel)7 JPasswordField (javax.swing.JPasswordField)6 JMenuItem (javax.swing.JMenuItem)5 Dimension (java.awt.Dimension)3 JTextPane (javax.swing.JTextPane)3 JScrollPane (javax.swing.JScrollPane)2 ImmutableList (com.google.common.collect.ImmutableList)1 Chat (games.strategy.engine.chat.Chat)1 ChatMessagePanel (games.strategy.engine.chat.ChatMessagePanel)1 ChatPlayerPanel (games.strategy.engine.chat.ChatPlayerPanel)1 GameRunner (games.strategy.engine.framework.GameRunner)1 LobbyClient (games.strategy.engine.lobby.client.LobbyClient)1 LobbyServerProperties (games.strategy.engine.lobby.client.login.LobbyServerProperties)1 LobbyServer (games.strategy.engine.lobby.server.LobbyServer)1 ModeratorController (games.strategy.engine.lobby.server.ModeratorController)1 LobbyMenu (games.strategy.triplea.ui.menubar.LobbyMenu)1