Merge pull request #4916 from Faxn/enhancement/startArgs

Enhancement/Autoconnect by Argument
This commit is contained in:
LevelX2 2018-05-22 06:57:38 +02:00 committed by GitHub
commit edc7daf126
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 = "<not connected>";
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<UUID, ChatPanelBasic> CHATS = new HashMap<>();
private static final Map<UUID, GamePanel> GAMES = new HashMap<>();
@ -732,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);
@ -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();
@ -1212,6 +1238,19 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}
}
instance = new MageFrame();
if( startUser != null){
instance.currentConnection = new Connection();
instance.currentConnection.setUsername(startUser);
instance.currentConnection.setHost(startServer);
if (startPort > 0){
instance.currentConnection.setPort(startPort);
}else {
instance.currentConnection.setPort(MagePreferences.getServerPortWithDefault(Config.port));
}
PreferencesDialog.setProxyInformation(instance.currentConnection);
instance.currentConnection.setPassword(startPassword);
}
instance.setVisible(true);
});