From 6ad23a2f3d73b0ae0f357c739317655b4aa1c95d Mon Sep 17 00:00:00 2001 From: campb Date: Mon, 7 May 2018 17:23:32 -0400 Subject: [PATCH 1/2] Parsing connect arguments and connecting. --- .../src/main/java/mage/client/MageFrame.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 4d3d0b2a71..269ef77bdb 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -105,6 +105,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { private static final String GRAY_MODE_ARG = "-gray"; private static final String FILL_SCREEN_ARG = "-fullscreen"; private static final String SKIP_DONE_SYMBOLS = "-skipDoneSymbols"; + private static final String USER_ARG = "-user"; + private static final String PASSWORD_ARG = "-pw"; + private static final String SERVER_ARG = "-server"; + private static final String PORT_ARG = "-port"; private static final String NOT_CONNECTED_TEXT = ""; private static MageFrame instance; @@ -123,6 +127,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { private static boolean grayMode = false; private static boolean fullscreenMode = false; private static boolean skipSmallSymbolGenerationForExisting = false; + private static String startUser = null; + private static String startPassword = ""; + private static String startServer = "localhost"; + private static int startPort = -1; private static final Map CHATS = new HashMap<>(); private static final Map GAMES = new HashMap<>(); @@ -1186,8 +1194,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { startTime = System.currentTimeMillis(); Thread.setDefaultUncaughtExceptionHandler((t, e) -> LOGGER.fatal(null, e)); + SwingUtilities.invokeLater(() -> { - for (String arg : args) { + for (int i = 0; i < args.length; i++) { + String arg = args[i]; if (arg.startsWith(LITE_MODE_ARG)) { liteMode = true; } @@ -1200,6 +1210,22 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { if (arg.startsWith(SKIP_DONE_SYMBOLS)) { skipSmallSymbolGenerationForExisting = true; } + if (arg.startsWith(USER_ARG)){ + startUser = args[i+1]; + i++; + } + if (arg.startsWith(PASSWORD_ARG)){ + startPassword = args[i+1]; + i++; + } + if (arg.startsWith(SERVER_ARG)){ + startServer = args[i+1]; + i++; + } + if (arg.startsWith(PORT_ARG)){ + startPort = Integer.valueOf(args[i+1]); + i++; + } } if (!liteMode) { final SplashScreen splash = SplashScreen.getSplashScreen(); @@ -1213,6 +1239,25 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } instance = new MageFrame(); instance.setVisible(true); + if( startUser != null){ + //instance.connectDialog. + Connection startConnection = new Connection(); + startConnection.setUsername(startUser); + startConnection.setHost(startServer); + if (startPort > 0){ + startConnection.setPort(startPort); + }else { + startConnection.setPort(MagePreferences.getServerPortWithDefault(Config.port)); + } + PreferencesDialog.setProxyInformation(startConnection); + startConnection.setPassword(startPassword); + boolean connectSuccess = connect(startConnection); + if (connectSuccess){ + instance.connectDialog.hideDialog(); + } else { + + } + } }); } From 5e6474c06e1f2aa09f3284966c2836ec1ce62f2c Mon Sep 17 00:00:00 2001 From: Blake Curry Date: Tue, 8 May 2018 13:42:55 -0400 Subject: [PATCH 2/2] Improved command line autoconnect Changed how the command line autoconnect was handled to leverage the existing autoconnect code. --- .../src/main/java/mage/client/MageFrame.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 269ef77bdb..59594260f4 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -740,7 +740,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } public boolean autoConnect() { - boolean autoConnectParamValue = Boolean.parseBoolean(PREFS.get("autoConnect", "false")); + boolean autoConnectParamValue = startUser != null || Boolean.parseBoolean(PREFS.get("autoConnect", "false")); boolean status = false; if (autoConnectParamValue) { status = performConnect(false); @@ -1238,26 +1238,20 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } } instance = new MageFrame(); - instance.setVisible(true); + if( startUser != null){ - //instance.connectDialog. - Connection startConnection = new Connection(); - startConnection.setUsername(startUser); - startConnection.setHost(startServer); + instance.currentConnection = new Connection(); + instance.currentConnection.setUsername(startUser); + instance.currentConnection.setHost(startServer); if (startPort > 0){ - startConnection.setPort(startPort); + instance.currentConnection.setPort(startPort); }else { - startConnection.setPort(MagePreferences.getServerPortWithDefault(Config.port)); - } - PreferencesDialog.setProxyInformation(startConnection); - startConnection.setPassword(startPassword); - boolean connectSuccess = connect(startConnection); - if (connectSuccess){ - instance.connectDialog.hideDialog(); - } else { - + instance.currentConnection.setPort(MagePreferences.getServerPortWithDefault(Config.port)); } + PreferencesDialog.setProxyInformation(instance.currentConnection); + instance.currentConnection.setPassword(startPassword); } + instance.setVisible(true); }); }