Fixed Issue 244

This commit is contained in:
magenoxx 2011-09-20 22:42:36 +04:00
parent 928ee4036a
commit 4534f11f3d
3 changed files with 26 additions and 7 deletions

View file

@ -554,6 +554,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
return session.connect(connection); return session.connect(connection);
} }
public static boolean stopConnecting() {
return session.stopConnecting();
}
public boolean autoConnect() { public boolean autoConnect() {
boolean autoConnect = Boolean.parseBoolean(prefs.get("autoConnect", "false")); boolean autoConnect = Boolean.parseBoolean(prefs.get("autoConnect", "false"));
if (autoConnect) { if (autoConnect) {

View file

@ -322,7 +322,6 @@ public class ConnectDialog extends MageDialog {
try { try {
get(); get();
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
btnConnect.setEnabled(true);
if (result) { if (result) {
lblStatus.setText(""); lblStatus.setText("");
connected(); connected();
@ -334,7 +333,13 @@ public class ConnectDialog extends MageDialog {
logger.fatal("Update Players Task error", ex); logger.fatal("Update Players Task error", ex);
} catch (ExecutionException ex) { } catch (ExecutionException ex) {
logger.fatal("Update Players Task error", ex); logger.fatal("Update Players Task error", ex);
} catch (CancellationException ex) {} } catch (CancellationException ex) {
logger.info("Connect was canceled");
lblStatus.setText("Connect was canceled");
MageFrame.stopConnecting();
} finally {
btnConnect.setEnabled(true);
}
} }
} }

View file

@ -78,6 +78,7 @@ public class Session {
private Connection connection; private Connection connection;
private static boolean debugMode = false; private static boolean debugMode = false;
private boolean canceled = false;
static { static {
debugMode = System.getProperty("debug.mage") != null; debugMode = System.getProperty("debug.mage") != null;
@ -92,9 +93,15 @@ public class Session {
disconnect(true); disconnect(true);
} }
this.connection = connection; this.connection = connection;
this.canceled = false;
return connect(); return connect();
} }
public boolean stopConnecting() {
canceled = true;
return true;
}
public boolean connect() { public boolean connect() {
sessionState = SessionState.CONNECTING; sessionState = SessionState.CONNECTING;
try { try {
@ -171,12 +178,16 @@ public class Session {
logger.fatal("", ex); logger.fatal("", ex);
client.showMessage("Unable to connect to server. " + ex.getMessage()); client.showMessage("Unable to connect to server. " + ex.getMessage());
} catch (MageVersionException ex) { } catch (MageVersionException ex) {
client.showMessage("Unable to connect to server. " + ex.getMessage()); if (!canceled) {
client.showMessage("Unable to connect to server. " + ex.getMessage());
}
// TODO: download client that matches server version // TODO: download client that matches server version
} catch (Throwable t) { } catch (Throwable t) {
logger.fatal("Unable to connect to server - ", t); logger.fatal("Unable to connect to server - ", t);
disconnect(false); if (!canceled) {
client.showMessage("Unable to connect to server. " + t.getMessage()); disconnect(false);
client.showMessage("Unable to connect to server. " + t.getMessage());
}
} }
return false; return false;
} }
@ -187,7 +198,6 @@ public class Session {
if (connection == null) if (connection == null)
return; return;
try { try {
callbackClient.disconnect(); callbackClient.disconnect();
TransporterClient.destroyTransporterClient(server); TransporterClient.destroyTransporterClient(server);
} catch (Throwable ex) { } catch (Throwable ex) {