diff --git a/G-Earth/src/main/java/gearth/protocol/HConnection.java b/G-Earth/src/main/java/gearth/protocol/HConnection.java index 5724528..f2124c9 100644 --- a/G-Earth/src/main/java/gearth/protocol/HConnection.java +++ b/G-Earth/src/main/java/gearth/protocol/HConnection.java @@ -62,6 +62,11 @@ public class HConnection { if (proxyProvider != null) { proxyProvider.start(); } + else { + // trigger UI update + setState(HState.ABORTING); + setState(HState.NOT_CONNECTED); + } } catch (IOException e) { e.printStackTrace(); } diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java index 558d2a7..bc5251b 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java @@ -5,6 +5,10 @@ import gearth.misc.OSValidator; import gearth.protocol.HConnection; import gearth.protocol.connection.HProxySetter; import gearth.protocol.connection.HStateSetter; +import javafx.application.Platform; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; +import javafx.scene.layout.Region; import java.io.IOException; import java.util.ArrayList; @@ -92,6 +96,16 @@ public class ProxyProviderFactory { else if (config.useSocks()) { return new SocksProxyProvider(proxySetter, stateSetter, hConnection, domain, port); } + + Platform.runLater(() -> { + Alert alert = new Alert(Alert.AlertType.ERROR, "G-Earth is already connected to this hotel. " + + "Due to current limitations you can only connect one session per hotel to G-Earth in Raw IP mode.\n\n" + + "You can bypass this by using a SOCKS proxy [Extra -> Advanced -> SOCKS]", ButtonType.OK); + alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE); + alert.setResizable(false); + alert.show(); + }); + return null; } else { diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/RawIpProxyProvider.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/RawIpProxyProvider.java index 86184c4..2382907 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/RawIpProxyProvider.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/RawIpProxyProvider.java @@ -52,7 +52,11 @@ public class RawIpProxyProvider extends ProxyProvider { stateSetter.setState(HState.PREPARING); proxy = new HProxy(input_host, input_host, input_port, input_port, "0.0.0.0"); - onBeforeIpMapping(); + if (!onBeforeIpMapping()) { + stateSetter.setState(HState.NOT_CONNECTED); + return; + } + maybeAddMapping(); if (HConnection.DEBUG) System.out.println("Added mapping for raw IP"); @@ -98,6 +102,12 @@ public class RawIpProxyProvider extends ProxyProvider { super.abort(); } + @Override + protected void onConnect() { + super.onConnect(); + tryCloseProxy(); + } + @Override protected void onConnectEnd() { if (hasMapped) { @@ -119,7 +129,8 @@ public class RawIpProxyProvider extends ProxyProvider { private Queue preConnectedServerConnections; - protected void onBeforeIpMapping() throws IOException, InterruptedException { + // returns false if fail + protected boolean onBeforeIpMapping() throws IOException, InterruptedException { preConnectedServerConnections = new LinkedList<>(); for (int i = 0; i < 3; i++) { Socket s1 = new Socket(); @@ -128,14 +139,15 @@ public class RawIpProxyProvider extends ProxyProvider { s1.connect(new InetSocketAddress(proxy.getActual_domain(), proxy.getActual_port()), 1200); } catch (SocketTimeoutException e) { - stateSetter.setState(HState.NOT_CONNECTED); showInvalidConnectionError(); - return; + return false; } preConnectedServerConnections.add(s1); Thread.sleep(50); } + + return true; } protected void createProxyThread(Socket client) throws IOException, InterruptedException { @@ -215,7 +227,7 @@ public class RawIpProxyProvider extends ProxyProvider { private void removeMappingCache() { JSONObject connections = getCurrentConnectionsCache(); - connections.remove(proxy.getActual_domain()); + connections.remove(INSTANCE_ID.toString()); saveCurrentConnectionsCache(connections); } @@ -234,7 +246,7 @@ public class RawIpProxyProvider extends ProxyProvider { static private JSONObject getCurrentConnectionsCache(String actual_host) { - if (!Cacher.getCacheContents().has(actual_host)) { + if (!Cacher.getCacheContents().has(RAWIP_CONNECTIONS)) { Cacher.put(RAWIP_CONNECTIONS, new JSONObject()); } JSONObject gearthConnections = Cacher.getCacheContents().getJSONObject(RAWIP_CONNECTIONS); @@ -252,7 +264,7 @@ public class RawIpProxyProvider extends ProxyProvider { BigInteger timeoutTimestamp = BigInteger.valueOf(System.currentTimeMillis() - 60000); for (String key : connections.keySet()) { JSONObject connection = connections.getJSONObject(key); - if (!connection.getString("id").equals(INSTANCE_ID.toString())) { + if (!key.equals(INSTANCE_ID.toString())) { if (connection.getBigInteger("timestamp").compareTo(timeoutTimestamp) > 0) { return false; } diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/SocksProxyProvider.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/SocksProxyProvider.java index d970864..c69fb43 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/SocksProxyProvider.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/SocksProxyProvider.java @@ -20,8 +20,8 @@ public class SocksProxyProvider extends RawIpProxyProvider { } @Override - protected void onBeforeIpMapping() { - // do nothing + protected boolean onBeforeIpMapping() { + return true; } @Override