Search in sources :

Example 6 with INode

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

the class StatusController method setStatus.

@Override
public void setStatus(final String newStatus) {
    final INode node = MessageContext.getSender();
    synchronized (mutex) {
        status.put(node, newStatus);
    }
    final IStatusChannel channel = (IStatusChannel) messengers.getChannelMessenger().getChannelBroadcastor(IStatusChannel.STATUS_CHANNEL);
    channel.statusChanged(node, newStatus);
}
Also used : INode(games.strategy.net.INode)

Example 7 with INode

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

the class ClientModel method startGameInNewThread.

private void startGameInNewThread(final byte[] gameData, final Map<String, INode> players, final boolean gameRunning) {
    final GameData data;
    try {
        // this normally takes a couple seconds, but can take
        // up to 60 seconds for a freaking huge game
        data = IoUtils.readFromMemory(gameData, GameDataManager::loadGame);
    } catch (final IOException ex) {
        ClientLogger.logQuietly("Failed to load game", ex);
        return;
    }
    objectStreamFactory.setData(data);
    final Map<String, String> playerMapping = playersToNodes.entrySet().stream().filter(e -> e.getValue().equals(messenger.getLocalNode().getName())).collect(Collectors.toMap(Map.Entry::getKey, e -> IGameLoader.CLIENT_PLAYER_TYPE));
    final Set<IGamePlayer> playerSet = data.getGameLoader().createPlayers(playerMapping);
    final Messengers messengers = new Messengers(messenger, remoteMessenger, channelMessenger);
    game = new ClientGame(data, playerSet, players, messengers);
    new Thread(() -> {
        SwingUtilities.invokeLater(() -> JOptionPane.getFrameForComponent(ui).setVisible(false));
        try {
            // game will be null if we loose the connection
            if (game != null) {
                try {
                    data.getGameLoader().startGame(game, playerSet, false);
                    data.testLocksOnRead();
                } catch (final Exception e) {
                    ClientLogger.logError("Failed to start Game", e);
                    game.shutDown();
                    messenger.shutDown();
                    gameLoadingWindow.doneWait();
                    // an ugly hack, we need a better
                    // way to get the main frame
                    GameRunner.clientLeftGame();
                }
            }
            if (!gameRunning) {
                ((IServerReady) remoteMessenger.getRemote(CLIENT_READY_CHANNEL)).clientReady();
            }
        } finally {
            gameLoadingWindow.doneWait();
        }
    }, "Client Game Launcher").start();
}
Also used : ClientGame(games.strategy.engine.framework.ClientGame) ClientMessenger(games.strategy.net.ClientMessenger) IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) TRIPLEA_STARTED(games.strategy.engine.framework.CliProperties.TRIPLEA_STARTED) TRIPLEA_HOST(games.strategy.engine.framework.CliProperties.TRIPLEA_HOST) Map(java.util.Map) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) SetMapClientAction(games.strategy.engine.framework.network.ui.SetMapClientAction) INode(games.strategy.net.INode) PlayerListing(games.strategy.engine.framework.message.PlayerListing) Collection(java.util.Collection) Set(java.util.Set) Logger(java.util.logging.Logger) GameRunner(games.strategy.engine.framework.GameRunner) Component(java.awt.Component) Collectors(java.util.stream.Collectors) TRIPLEA_PORT(games.strategy.engine.framework.CliProperties.TRIPLEA_PORT) IChatPanel(games.strategy.engine.chat.IChatPanel) UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) IChannelMessenger(games.strategy.engine.message.IChannelMessenger) CountDownLatch(java.util.concurrent.CountDownLatch) GameData(games.strategy.engine.data.GameData) List(java.util.List) ChangeToAutosaveClientAction(games.strategy.engine.framework.network.ui.ChangeToAutosaveClientAction) EventThreadJOptionPane(games.strategy.util.EventThreadJOptionPane) TRIPLEA_NAME(games.strategy.engine.framework.CliProperties.TRIPLEA_NAME) WaitWindow(games.strategy.engine.framework.ui.background.WaitWindow) SwingAction(games.strategy.ui.SwingAction) Setter(lombok.Setter) Getter(lombok.Getter) ChangeGameOptionsClientAction(games.strategy.engine.framework.network.ui.ChangeGameOptionsClientAction) Messengers(games.strategy.net.Messengers) HashMap(java.util.HashMap) Action(javax.swing.Action) MacFinder(games.strategy.net.MacFinder) RemoteName(games.strategy.engine.message.RemoteName) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) IMessengerErrorListener(games.strategy.net.IMessengerErrorListener) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SwingUtilities(javax.swing.SwingUtilities) ClientLogin(games.strategy.engine.framework.startup.login.ClientLogin) ClientOptions(games.strategy.engine.framework.startup.ui.ClientOptions) IMessenger(games.strategy.net.IMessenger) GameDataManager(games.strategy.engine.framework.GameDataManager) IoUtils(games.strategy.io.IoUtils) ClientSetting(games.strategy.triplea.settings.ClientSetting) Nonnull(javax.annotation.Nonnull) GetGameSaveClientAction(games.strategy.engine.framework.network.ui.GetGameSaveClientAction) ChangeGameToSaveGameClientAction(games.strategy.engine.framework.network.ui.ChangeGameToSaveGameClientAction) TRIPLEA_CLIENT(games.strategy.engine.framework.CliProperties.TRIPLEA_CLIENT) Interruptibles(games.strategy.util.Interruptibles) SaveGameFileChooser(games.strategy.engine.framework.ui.SaveGameFileChooser) IOException(java.io.IOException) Chat(games.strategy.engine.chat.Chat) JOptionPane(javax.swing.JOptionPane) IServerReady(games.strategy.engine.framework.startup.launcher.IServerReady) GameObjectStreamFactory(games.strategy.engine.framework.GameObjectStreamFactory) TimeUnit(java.util.concurrent.TimeUnit) ClientLogger(games.strategy.debug.ClientLogger) IRemoteMessenger(games.strategy.engine.message.IRemoteMessenger) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) IGameLoader(games.strategy.engine.framework.IGameLoader) CouldNotLogInException(games.strategy.net.CouldNotLogInException) Preconditions(com.google.common.base.Preconditions) ChatPanel(games.strategy.engine.chat.ChatPanel) IClientMessenger(games.strategy.net.IClientMessenger) IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) Messengers(games.strategy.net.Messengers) GameData(games.strategy.engine.data.GameData) IOException(java.io.IOException) ClientGame(games.strategy.engine.framework.ClientGame) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) CouldNotLogInException(games.strategy.net.CouldNotLogInException)

Example 8 with INode

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

the class LobbyGamePanel method shutDownHeadlessHostBot.

private void shutDownHeadlessHostBot() {
    final int selectedIndex = gameTable.getSelectedRow();
    if (selectedIndex == -1) {
        return;
    }
    final int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to perform a remote shutdown of this host? \n\nYou MUST email the host's owner FIRST!!", "Remote Shutdown 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.shutDownHeadlessHostBot(lobbyWatcherNode, hashedPassword, salt);
    JOptionPane.showMessageDialog(null, (response == null ? "Successfully attempted to shut down 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 9 with INode

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

the class LobbyGamePanel method getChatLogOfHeadlessHostBot.

private void getChatLogOfHeadlessHostBot() {
    final int selectedIndex = gameTable.getSelectedRow();
    if (selectedIndex == -1) {
        return;
    }
    final int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to perform a remote get chat log this host?", "Remote Get Chat Log Headless Host Bot", JOptionPane.OK_CANCEL_OPTION);
    if (result != JOptionPane.OK_OPTION) {
        return;
    }
    // we sort the table, so get the correct index
    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.getChatLogHeadlessHostBot(lobbyWatcherNode, hashedPassword, salt);
    final JTextPane textPane = new JTextPane();
    textPane.setEditable(false);
    textPane.setText(response == null ? "Failed to get chat log!" : response);
    textPane.setCaretPosition(textPane.getText().length());
    final JScrollPane scroll = new JScrollPane(textPane);
    final Dimension screenResolution = Toolkit.getDefaultToolkit().getScreenSize();
    final int availWidth = screenResolution.width - 100;
    final int availHeight = screenResolution.height - 140;
    scroll.setPreferredSize(new Dimension(Math.min(availWidth, scroll.getPreferredSize().width), Math.min(availHeight, scroll.getPreferredSize().height)));
    JOptionPane.showMessageDialog(null, scroll, "Bot Chat Log", JOptionPane.INFORMATION_MESSAGE);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextPane(javax.swing.JTextPane) INode(games.strategy.net.INode) IModeratorController(games.strategy.engine.lobby.server.IModeratorController) BorderLayout(java.awt.BorderLayout) JPasswordField(javax.swing.JPasswordField) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension)

Example 10 with INode

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

the class LobbyGamePanel method banPlayerInHeadlessHostBot.

private void banPlayerInHeadlessHostBot() {
    final int selectedIndex = gameTable.getSelectedRow();
    if (selectedIndex == -1) {
        return;
    }
    final int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to perform a (permanent) remote ban player on this host?", "Remote Player Ban Headless Host Bot", JOptionPane.OK_CANCEL_OPTION);
    if (result != JOptionPane.OK_OPTION) {
        return;
    }
    final String playerToBeBanned = JOptionPane.showInputDialog(getTopLevelAncestor(), "Player Name To Be Banned?", "Player Name To Be Banned?", JOptionPane.QUESTION_MESSAGE);
    if (playerToBeBanned == null) {
        return;
    }
    final Object hours = JOptionPane.showInputDialog(getTopLevelAncestor(), "Hours to Ban for?  (between 0 and 720, this is permanent and only a restart of the host will undo it!)", "Hours to Ban for?", JOptionPane.QUESTION_MESSAGE, null, null, 24);
    if (hours == null) {
        return;
    }
    final int hrs;
    try {
        hrs = Math.max(0, Math.min(24 * 30, Integer.parseInt((String) hours)));
    } catch (final NumberFormatException e) {
        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.banPlayerHeadlessHostBot(lobbyWatcherNode, playerToBeBanned, hrs, hashedPassword, salt);
    JOptionPane.showMessageDialog(null, (response == null ? "Successfully attempted banned player (" + playerToBeBanned + ") 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)

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