mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
fix error when spamclicking abort+connect
This commit is contained in:
parent
6e5bc39489
commit
44e343499c
@ -65,7 +65,8 @@ public class HConnection {
|
|||||||
PREPARING, // DOMAIN AND PORT BEEN PASSED
|
PREPARING, // DOMAIN AND PORT BEEN PASSED
|
||||||
PREPARED, // FOUND IP ADDRESS OF DOMAIN
|
PREPARED, // FOUND IP ADDRESS OF DOMAIN
|
||||||
WAITING_FOR_CLIENT, // WAITING FOR CORRECT TCP CONNECTION TO BE SET UP
|
WAITING_FOR_CLIENT, // WAITING FOR CORRECT TCP CONNECTION TO BE SET UP
|
||||||
CONNECTED // CONNECTED
|
CONNECTED, // CONNECTED
|
||||||
|
ABORTING
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks if host is a raw IP instead of a domain
|
// checks if host is a raw IP instead of a domain
|
||||||
@ -116,7 +117,7 @@ public class HConnection {
|
|||||||
|
|
||||||
private static volatile ConnectionInfoOverrider connectionInfoOverrider;
|
private static volatile ConnectionInfoOverrider connectionInfoOverrider;
|
||||||
public static volatile boolean DECRYPTPACKETS = true;
|
public static volatile boolean DECRYPTPACKETS = true;
|
||||||
public static volatile boolean DEBUG = false;
|
public static volatile boolean DEBUG = true;
|
||||||
private static final HostReplacer hostsReplacer = HostReplacerFactory.get();
|
private static final HostReplacer hostsReplacer = HostReplacerFactory.get();
|
||||||
|
|
||||||
private volatile boolean hostRedirected = false;
|
private volatile boolean hostRedirected = false;
|
||||||
@ -220,10 +221,10 @@ public class HConnection {
|
|||||||
potentialHost.add(domain+":"+port);
|
potentialHost.add(domain+":"+port);
|
||||||
|
|
||||||
if (hostIsIpAddress(domain)) {
|
if (hostIsIpAddress(domain)) {
|
||||||
|
setState(State.PREPARING); // state will not be prepared until the server-connection is initialized
|
||||||
rawIpMode = true;
|
rawIpMode = true;
|
||||||
potentialProxies.clear();
|
potentialProxies.clear();
|
||||||
potentialProxies.add(new Proxy(domain, domain, port, port, "0.0.0.0"));
|
potentialProxies.add(new Proxy(domain, domain, port, port, "0.0.0.0"));
|
||||||
setState(State.PREPARED);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
prepare(potentialHost);
|
prepare(potentialHost);
|
||||||
@ -285,18 +286,21 @@ public class HConnection {
|
|||||||
setState(State.PREPARED);
|
setState(State.PREPARED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startForRawIp() throws IOException {
|
private void startForRawIp() {
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Proxy proxy = potentialProxies.get(0);
|
Proxy proxy = potentialProxies.get(0);
|
||||||
|
IpMapper ipMapper = IpMapperFactory.get();
|
||||||
|
ipMapper.deleteMapping(proxy.actual_domain); // just making sure
|
||||||
|
|
||||||
Queue<Socket> preConnectedServerConnections = new LinkedList<>();
|
Queue<Socket> preConnectedServerConnections = new LinkedList<>();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
preConnectedServerConnections.add(new Socket(proxy.actual_domain, proxy.actual_port));
|
preConnectedServerConnections.add(new Socket(proxy.actual_domain, proxy.actual_port));
|
||||||
Thread.sleep(80);
|
Thread.sleep(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
IpMapper ipMapper = IpMapperFactory.get();
|
|
||||||
ipMapper.enable();
|
ipMapper.enable();
|
||||||
ipMapper.addMapping(proxy.actual_domain);
|
ipMapper.addMapping(proxy.actual_domain);
|
||||||
|
|
||||||
@ -308,6 +312,8 @@ public class HConnection {
|
|||||||
|
|
||||||
|
|
||||||
Thread.sleep(30);
|
Thread.sleep(30);
|
||||||
|
setState(State.WAITING_FOR_CLIENT);
|
||||||
|
|
||||||
while ((state == State.WAITING_FOR_CLIENT) && !proxy_server.isClosed()) {
|
while ((state == State.WAITING_FOR_CLIENT) && !proxy_server.isClosed()) {
|
||||||
try {
|
try {
|
||||||
if (DEBUG) System.out.println("try accept proxy");
|
if (DEBUG) System.out.println("try accept proxy");
|
||||||
@ -345,15 +351,15 @@ public class HConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
if (state == State.PREPARED) {
|
if (state == State.PREPARING && rawIpMode) {
|
||||||
|
|
||||||
setState(State.WAITING_FOR_CLIENT);
|
|
||||||
|
|
||||||
if (rawIpMode) {
|
|
||||||
startForRawIp();
|
startForRawIp();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state == State.PREPARED && !rawIpMode) {
|
||||||
|
|
||||||
|
setState(State.WAITING_FOR_CLIENT);
|
||||||
|
|
||||||
if (!hostRedirected && !connectionInfoOverrider.mustOverrideConnection()) {
|
if (!hostRedirected && !connectionInfoOverrider.mustOverrideConnection()) {
|
||||||
addToHosts();
|
addToHosts();
|
||||||
}
|
}
|
||||||
@ -516,21 +522,25 @@ public class HConnection {
|
|||||||
removeFromHosts();
|
removeFromHosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!rawIpMode) {
|
||||||
clearAllProxies();
|
clearAllProxies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public void abort() {
|
public void abort() {
|
||||||
|
setState(State.ABORTING);
|
||||||
if (hostRedirected) {
|
if (hostRedirected) {
|
||||||
removeFromHosts();
|
removeFromHosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawIpMode && actual_proxy != null) {
|
if (rawIpMode && potentialProxies.size() == 1) {
|
||||||
IpMapperFactory.get().deleteMapping(actual_proxy.actual_domain);
|
IpMapperFactory.get().deleteMapping(potentialProxies.get(0).actual_domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
actual_proxy = null;
|
actual_proxy = null;
|
||||||
|
|
||||||
setState(State.NOT_CONNECTED);
|
|
||||||
clearAllProxies();
|
clearAllProxies();
|
||||||
|
setState(State.NOT_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearAllProxies() {
|
private void clearAllProxies() {
|
||||||
@ -540,9 +550,9 @@ public class HConnection {
|
|||||||
private void closeAllProxies(Proxy except) {
|
private void closeAllProxies(Proxy except) {
|
||||||
for (Proxy proxy : potentialProxies) {
|
for (Proxy proxy : potentialProxies) {
|
||||||
if (except != proxy) {
|
if (except != proxy) {
|
||||||
if (proxy.proxy_server != null && !proxy.proxy_server.isClosed()) {
|
if (proxy.getProxy_server() != null && !proxy.getProxy_server().isClosed()) {
|
||||||
try {
|
try {
|
||||||
proxy.proxy_server.close();
|
proxy.getProxy_server().close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -55,10 +55,11 @@ public class ConnectionController extends SubForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateInputUI() {
|
private void updateInputUI() {
|
||||||
if (cbx_autodetect.isSelected()) {
|
txtfield_hotelversion.setText(getHConnection().getHotelVersion());
|
||||||
btnConnect.setDisable(false);
|
|
||||||
}
|
System.out.println(getHConnection().getState());
|
||||||
else {
|
btnConnect.setDisable(getHConnection().getState() == HConnection.State.PREPARING || getHConnection().getState() == HConnection.State.ABORTING);
|
||||||
|
if (!cbx_autodetect.isSelected() && !btnConnect.isDisable()) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(inpPort.getEditor().getText());
|
int i = Integer.parseInt(inpPort.getEditor().getText());
|
||||||
btnConnect.setDisable(i < 0 || i >= 256 * 256);
|
btnConnect.setDisable(i < 0 || i >= 256 * 256);
|
||||||
@ -74,17 +75,14 @@ public class ConnectionController extends SubForm {
|
|||||||
|
|
||||||
public void onParentSet(){
|
public void onParentSet(){
|
||||||
getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(() -> {
|
getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(() -> {
|
||||||
txtfield_hotelversion.setText(getHConnection().getHotelVersion());
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
if (newState == HConnection.State.NOT_CONNECTED) {
|
|
||||||
updateInputUI();
|
updateInputUI();
|
||||||
|
if (newState == HConnection.State.NOT_CONNECTED) {
|
||||||
lblState.setText("Not connected");
|
lblState.setText("Not connected");
|
||||||
btnConnect.setText("Connect");
|
btnConnect.setText("Connect");
|
||||||
outHost.setText("");
|
outHost.setText("");
|
||||||
outPort.setText("");
|
outPort.setText("");
|
||||||
}
|
}
|
||||||
else if (oldState == HConnection.State.NOT_CONNECTED) {
|
else if (oldState == HConnection.State.NOT_CONNECTED) {
|
||||||
updateInputUI();
|
|
||||||
btnConnect.setText("Abort");
|
btnConnect.setText("Abort");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +94,6 @@ public class ConnectionController extends SubForm {
|
|||||||
if (newState == HConnection.State.WAITING_FOR_CLIENT) {
|
if (newState == HConnection.State.WAITING_FOR_CLIENT) {
|
||||||
lblState.setText("Waiting for connection");
|
lblState.setText("Waiting for connection");
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}));
|
}));
|
||||||
@ -113,10 +110,7 @@ public class ConnectionController extends SubForm {
|
|||||||
else {
|
else {
|
||||||
getHConnection().prepare(inpHost.getEditor().getText(), Integer.parseInt(inpPort.getEditor().getText()));
|
getHConnection().prepare(inpHost.getEditor().getText(), Integer.parseInt(inpPort.getEditor().getText()));
|
||||||
}
|
}
|
||||||
Platform.runLater(() -> btnConnect.setDisable(false));
|
|
||||||
|
|
||||||
if (HConnection.DEBUG) System.out.println("connecting");
|
if (HConnection.DEBUG) System.out.println("connecting");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getHConnection().start();
|
getHConnection().start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user