fixes part 2, SOCKS now implemented

This commit is contained in:
sirjonasxx 2020-05-06 23:06:45 +02:00
parent 5ffc7b2313
commit d6e135eed1
4 changed files with 40 additions and 9 deletions

View File

@ -62,6 +62,11 @@ public class HConnection {
if (proxyProvider != null) { if (proxyProvider != null) {
proxyProvider.start(); proxyProvider.start();
} }
else {
// trigger UI update
setState(HState.ABORTING);
setState(HState.NOT_CONNECTED);
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -5,6 +5,10 @@ import gearth.misc.OSValidator;
import gearth.protocol.HConnection; import gearth.protocol.HConnection;
import gearth.protocol.connection.HProxySetter; import gearth.protocol.connection.HProxySetter;
import gearth.protocol.connection.HStateSetter; 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.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -92,6 +96,16 @@ public class ProxyProviderFactory {
else if (config.useSocks()) { else if (config.useSocks()) {
return new SocksProxyProvider(proxySetter, stateSetter, hConnection, domain, port); 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; return null;
} }
else { else {

View File

@ -52,7 +52,11 @@ public class RawIpProxyProvider extends ProxyProvider {
stateSetter.setState(HState.PREPARING); stateSetter.setState(HState.PREPARING);
proxy = new HProxy(input_host, input_host, input_port, input_port, "0.0.0.0"); 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(); maybeAddMapping();
if (HConnection.DEBUG) System.out.println("Added mapping for raw IP"); if (HConnection.DEBUG) System.out.println("Added mapping for raw IP");
@ -98,6 +102,12 @@ public class RawIpProxyProvider extends ProxyProvider {
super.abort(); super.abort();
} }
@Override
protected void onConnect() {
super.onConnect();
tryCloseProxy();
}
@Override @Override
protected void onConnectEnd() { protected void onConnectEnd() {
if (hasMapped) { if (hasMapped) {
@ -119,7 +129,8 @@ public class RawIpProxyProvider extends ProxyProvider {
private Queue<Socket> preConnectedServerConnections; private Queue<Socket> preConnectedServerConnections;
protected void onBeforeIpMapping() throws IOException, InterruptedException { // returns false if fail
protected boolean onBeforeIpMapping() throws IOException, InterruptedException {
preConnectedServerConnections = new LinkedList<>(); preConnectedServerConnections = new LinkedList<>();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Socket s1 = new Socket(); Socket s1 = new Socket();
@ -128,14 +139,15 @@ public class RawIpProxyProvider extends ProxyProvider {
s1.connect(new InetSocketAddress(proxy.getActual_domain(), proxy.getActual_port()), 1200); s1.connect(new InetSocketAddress(proxy.getActual_domain(), proxy.getActual_port()), 1200);
} }
catch (SocketTimeoutException e) { catch (SocketTimeoutException e) {
stateSetter.setState(HState.NOT_CONNECTED);
showInvalidConnectionError(); showInvalidConnectionError();
return; return false;
} }
preConnectedServerConnections.add(s1); preConnectedServerConnections.add(s1);
Thread.sleep(50); Thread.sleep(50);
} }
return true;
} }
protected void createProxyThread(Socket client) throws IOException, InterruptedException { protected void createProxyThread(Socket client) throws IOException, InterruptedException {
@ -215,7 +227,7 @@ public class RawIpProxyProvider extends ProxyProvider {
private void removeMappingCache() { private void removeMappingCache() {
JSONObject connections = getCurrentConnectionsCache(); JSONObject connections = getCurrentConnectionsCache();
connections.remove(proxy.getActual_domain()); connections.remove(INSTANCE_ID.toString());
saveCurrentConnectionsCache(connections); saveCurrentConnectionsCache(connections);
} }
@ -234,7 +246,7 @@ public class RawIpProxyProvider extends ProxyProvider {
static private JSONObject getCurrentConnectionsCache(String actual_host) { 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()); Cacher.put(RAWIP_CONNECTIONS, new JSONObject());
} }
JSONObject gearthConnections = Cacher.getCacheContents().getJSONObject(RAWIP_CONNECTIONS); JSONObject gearthConnections = Cacher.getCacheContents().getJSONObject(RAWIP_CONNECTIONS);
@ -252,7 +264,7 @@ public class RawIpProxyProvider extends ProxyProvider {
BigInteger timeoutTimestamp = BigInteger.valueOf(System.currentTimeMillis() - 60000); BigInteger timeoutTimestamp = BigInteger.valueOf(System.currentTimeMillis() - 60000);
for (String key : connections.keySet()) { for (String key : connections.keySet()) {
JSONObject connection = connections.getJSONObject(key); 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) { if (connection.getBigInteger("timestamp").compareTo(timeoutTimestamp) > 0) {
return false; return false;
} }

View File

@ -20,8 +20,8 @@ public class SocksProxyProvider extends RawIpProxyProvider {
} }
@Override @Override
protected void onBeforeIpMapping() { protected boolean onBeforeIpMapping() {
// do nothing return true;
} }
@Override @Override