mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Issue#424: Client now detects connection loss and asks for reconnecting
This commit is contained in:
parent
9021449970
commit
23e1f9196c
5 changed files with 67 additions and 37 deletions
|
@ -669,40 +669,46 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
public boolean autoConnect() {
|
||||
boolean autoConnect = Boolean.parseBoolean(prefs.get("autoConnect", "false"));
|
||||
if (autoConnect) {
|
||||
String userName = prefs.get("userName", "");
|
||||
String server = prefs.get("serverAddress", "");
|
||||
int port = Integer.parseInt(prefs.get("serverPort", ""));
|
||||
String proxyServer = prefs.get("proxyAddress", "");
|
||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", ""));
|
||||
ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
String proxyUsername = prefs.get("proxyUsername", "");
|
||||
String proxyPassword = prefs.get("proxyPassword", "");
|
||||
int avatarId = PreferencesDialog.getSelectedAvatar();
|
||||
boolean showAbilityPickerForced = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true");
|
||||
try {
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
Connection connection = new Connection();
|
||||
connection.setUsername(userName);
|
||||
connection.setHost(server);
|
||||
connection.setPort(port);
|
||||
connection.setProxyType(proxyType);
|
||||
connection.setProxyHost(proxyServer);
|
||||
connection.setProxyPort(proxyPort);
|
||||
connection.setProxyUsername(proxyUsername);
|
||||
connection.setProxyPassword(proxyPassword);
|
||||
connection.setAvatarId(avatarId);
|
||||
connection.setShowAbilityPickerForced(showAbilityPickerForced);
|
||||
logger.debug("connecting (auto): " + proxyType + " " + proxyServer + " " + proxyPort + " " + proxyUsername);
|
||||
if (MageFrame.connect(connection)) {
|
||||
return true;
|
||||
} else {
|
||||
showMessage("Unable to connect to server");
|
||||
}
|
||||
} finally {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
boolean autoConnectParamValue = Boolean.parseBoolean(prefs.get("autoConnect", "false"));
|
||||
boolean status = false;
|
||||
if (autoConnectParamValue) {
|
||||
status = performConnect();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
private boolean performConnect() {
|
||||
String userName = prefs.get("userName", "");
|
||||
String server = prefs.get("serverAddress", "");
|
||||
int port = Integer.parseInt(prefs.get("serverPort", ""));
|
||||
String proxyServer = prefs.get("proxyAddress", "");
|
||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", ""));
|
||||
ProxyType proxyType = ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
String proxyUsername = prefs.get("proxyUsername", "");
|
||||
String proxyPassword = prefs.get("proxyPassword", "");
|
||||
int avatarId = PreferencesDialog.getSelectedAvatar();
|
||||
boolean showAbilityPickerForced = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true");
|
||||
try {
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
Connection connection = new Connection();
|
||||
connection.setUsername(userName);
|
||||
connection.setHost(server);
|
||||
connection.setPort(port);
|
||||
connection.setProxyType(proxyType);
|
||||
connection.setProxyHost(proxyServer);
|
||||
connection.setProxyPort(proxyPort);
|
||||
connection.setProxyUsername(proxyUsername);
|
||||
connection.setProxyPassword(proxyPassword);
|
||||
connection.setAvatarId(avatarId);
|
||||
connection.setShowAbilityPickerForced(showAbilityPickerForced);
|
||||
logger.debug("connecting (auto): " + proxyType + " " + proxyServer + " " + proxyPort + " " + proxyUsername);
|
||||
if (MageFrame.connect(connection)) {
|
||||
return true;
|
||||
} else {
|
||||
showMessage("Unable to connect to server");
|
||||
}
|
||||
} finally {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -943,6 +949,15 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
System.exit(0);
|
||||
}
|
||||
|
||||
public void reconnect() {
|
||||
session.disconnect(false);
|
||||
tablesPane.clearChat();
|
||||
disableButtons();
|
||||
if (performConnect()) {
|
||||
enableButtons();
|
||||
}
|
||||
}
|
||||
|
||||
public void enableButtons() {
|
||||
btnConnect.setEnabled(true);
|
||||
btnConnect.setText("Disconnect");
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package mage.client.game;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import javax.swing.SwingUtilities;
|
||||
import mage.client.components.MageUI;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
|
@ -13,6 +10,9 @@ import mage.utils.MageVersion;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* Test for emulating the connection from multi mage clients.
|
||||
*
|
||||
|
@ -74,6 +74,11 @@ public class MultiConnectTest {
|
|||
logger.info("disconnected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
logger.info("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(String message) {
|
||||
logger.info("showMessage: " + message);
|
||||
|
|
|
@ -40,6 +40,7 @@ public interface MageClient extends CallbackClient {
|
|||
MageVersion getVersion();
|
||||
void connected(String message);
|
||||
void disconnected();
|
||||
void reconnect();
|
||||
void showMessage(String message);
|
||||
void showError(String message);
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.jboss.remoting.transport.bisocket.Bisocket;
|
|||
import org.jboss.remoting.transport.socket.SocketWrapper;
|
||||
import org.jboss.remoting.transporter.TransporterClient;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -1285,7 +1286,10 @@ public class SessionImpl implements Session {
|
|||
try {
|
||||
if (isConnected()) {
|
||||
if (!server.ping(sessionId)) {
|
||||
logger.error(new StringBuilder("Ping failed: ").append(this.getUserName()).append(" Session: ").append(sessionId).append(" to MAGE server at ").append(connection.getHost()).append(":").append(connection.getPort()).toString());
|
||||
logger.error(new StringBuilder("Ping failed: ").append(this.getUserName()).append(" Session: ").append(sessionId).append(" to MAGE server at ").append(connection.getHost()).append(":").append(connection.getPort()).toString());
|
||||
if (JOptionPane.showConfirmDialog(null, "The connection to server was lost. Reconnect?", "Warning", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
client.reconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -257,6 +257,11 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
logger.info("Not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
|
|
Loading…
Reference in a new issue