diff --git a/G-Earth/src/main/java/gearth/Main.java b/G-Earth/src/main/java/gearth/Main.java index 8c7e237..af983af 100644 --- a/G-Earth/src/main/java/gearth/Main.java +++ b/G-Earth/src/main/java/gearth/Main.java @@ -130,6 +130,17 @@ public class Main extends Application { } return false; } + + public static String getArgument(String... arg) { + for (int i = 0; i < args.length - 1; i++) { + for (String str : arg) { + if (args[i].toLowerCase().equals(str.toLowerCase())) { + return args[i+1]; + } + } + } + return null; + } } // Hi diff --git a/G-Earth/src/main/java/gearth/ui/GEarthController.java b/G-Earth/src/main/java/gearth/ui/GEarthController.java index c405c42..6690009 100644 --- a/G-Earth/src/main/java/gearth/ui/GEarthController.java +++ b/G-Earth/src/main/java/gearth/ui/GEarthController.java @@ -1,5 +1,7 @@ package gearth.ui; +import gearth.protocol.connection.proxy.ProxyProviderFactory; +import gearth.protocol.connection.proxy.SocksConfiguration; import gearth.ui.logger.loggerdisplays.PacketLoggerFactory; import javafx.event.Event; import javafx.event.EventHandler; @@ -41,6 +43,15 @@ public class GEarthController { public Pane mover; public GEarthController() { + SocksConfiguration temporary_socks = new SocksConfiguration() { + public boolean useSocks() { return false; } + public int getSocksPort() { return 0; } + public String getSocksHost() { return null; } + public boolean onlyUseIfNeeded() { return true; } + }; + + ProxyProviderFactory.setSocksConfig(temporary_socks); + hConnection = new HConnection(); } diff --git a/G-Earth/src/main/java/gearth/ui/connection/ConnectionController.java b/G-Earth/src/main/java/gearth/ui/connection/ConnectionController.java index 72d1a34..287d70a 100644 --- a/G-Earth/src/main/java/gearth/ui/connection/ConnectionController.java +++ b/G-Earth/src/main/java/gearth/ui/connection/ConnectionController.java @@ -1,5 +1,6 @@ package gearth.ui.connection; +import gearth.Main; import gearth.misc.Cacher; import gearth.protocol.connection.HState; import gearth.protocol.connection.proxy.ProxyProviderFactory; @@ -12,7 +13,6 @@ import gearth.ui.SubForm; import javafx.scene.layout.GridPane; import org.json.JSONObject; -import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -44,6 +44,8 @@ public class ConnectionController extends SubForm { public RadioButton rd_flash; public GridPane grd_clientSelection; + private volatile int initcount = 0; + public void initialize() { Constants.UNITY_PACKETS = rd_unity.isSelected(); @@ -114,6 +116,10 @@ public class ConnectionController extends SubForm { Platform.runLater(this::updateInputUI); } } + + synchronized (this) { + tryMaybeConnectOnInit(); + } } @@ -190,6 +196,47 @@ public class ConnectionController extends SubForm { })); Platform.runLater(this::updateInputUI); + + synchronized (this) { + tryMaybeConnectOnInit(); + } + } + + + private void tryMaybeConnectOnInit() { + if (++initcount == 2) { + maybeConnectOnInit(); + } + } + + private void maybeConnectOnInit() { + String connectMode = Main.getArgument("--connect", "-c"); + if (connectMode != null) { + if (connectMode.equals("flash")) { + Platform.runLater(() -> rd_flash.setSelected(true)); + String host = Main.getArgument("--host"); + String port = Main.getArgument("--port"); + if (host != null && port != null) { + Platform.runLater(() -> { + if (!inpHost.getItems().contains(host)) inpHost.getItems().add(host); + inpHost.getSelectionModel().select(host); + if (!inpPort.getItems().contains(port)) inpPort.getItems().add(port); + inpPort.getSelectionModel().select(port); + cbx_autodetect.setSelected(false); + }); + getHConnection().start(host, Integer.parseInt(port)); + } + else { + Platform.runLater(() -> cbx_autodetect.setSelected(true)); + getHConnection().start(); + } + } + else if (connectMode.equals("unity")) { + Platform.runLater(() -> rd_unity.setSelected(true)); + getHConnection().startUnity(); + } + Platform.runLater(this::updateInputUI); + } } public void btnConnect_clicked(ActionEvent actionEvent) {