mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +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() {
|
public boolean autoConnect() {
|
||||||
boolean autoConnect = Boolean.parseBoolean(prefs.get("autoConnect", "false"));
|
boolean autoConnectParamValue = Boolean.parseBoolean(prefs.get("autoConnect", "false"));
|
||||||
if (autoConnect) {
|
boolean status = false;
|
||||||
String userName = prefs.get("userName", "");
|
if (autoConnectParamValue) {
|
||||||
String server = prefs.get("serverAddress", "");
|
status = performConnect();
|
||||||
int port = Integer.parseInt(prefs.get("serverPort", ""));
|
}
|
||||||
String proxyServer = prefs.get("proxyAddress", "");
|
return status;
|
||||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", ""));
|
}
|
||||||
ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
|
||||||
String proxyUsername = prefs.get("proxyUsername", "");
|
private boolean performConnect() {
|
||||||
String proxyPassword = prefs.get("proxyPassword", "");
|
String userName = prefs.get("userName", "");
|
||||||
int avatarId = PreferencesDialog.getSelectedAvatar();
|
String server = prefs.get("serverAddress", "");
|
||||||
boolean showAbilityPickerForced = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true");
|
int port = Integer.parseInt(prefs.get("serverPort", ""));
|
||||||
try {
|
String proxyServer = prefs.get("proxyAddress", "");
|
||||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
int proxyPort = Integer.parseInt(prefs.get("proxyPort", ""));
|
||||||
Connection connection = new Connection();
|
ProxyType proxyType = ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||||
connection.setUsername(userName);
|
String proxyUsername = prefs.get("proxyUsername", "");
|
||||||
connection.setHost(server);
|
String proxyPassword = prefs.get("proxyPassword", "");
|
||||||
connection.setPort(port);
|
int avatarId = PreferencesDialog.getSelectedAvatar();
|
||||||
connection.setProxyType(proxyType);
|
boolean showAbilityPickerForced = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true");
|
||||||
connection.setProxyHost(proxyServer);
|
try {
|
||||||
connection.setProxyPort(proxyPort);
|
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||||
connection.setProxyUsername(proxyUsername);
|
Connection connection = new Connection();
|
||||||
connection.setProxyPassword(proxyPassword);
|
connection.setUsername(userName);
|
||||||
connection.setAvatarId(avatarId);
|
connection.setHost(server);
|
||||||
connection.setShowAbilityPickerForced(showAbilityPickerForced);
|
connection.setPort(port);
|
||||||
logger.debug("connecting (auto): " + proxyType + " " + proxyServer + " " + proxyPort + " " + proxyUsername);
|
connection.setProxyType(proxyType);
|
||||||
if (MageFrame.connect(connection)) {
|
connection.setProxyHost(proxyServer);
|
||||||
return true;
|
connection.setProxyPort(proxyPort);
|
||||||
} else {
|
connection.setProxyUsername(proxyUsername);
|
||||||
showMessage("Unable to connect to server");
|
connection.setProxyPassword(proxyPassword);
|
||||||
}
|
connection.setAvatarId(avatarId);
|
||||||
} finally {
|
connection.setShowAbilityPickerForced(showAbilityPickerForced);
|
||||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -943,6 +949,15 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reconnect() {
|
||||||
|
session.disconnect(false);
|
||||||
|
tablesPane.clearChat();
|
||||||
|
disableButtons();
|
||||||
|
if (performConnect()) {
|
||||||
|
enableButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void enableButtons() {
|
public void enableButtons() {
|
||||||
btnConnect.setEnabled(true);
|
btnConnect.setEnabled(true);
|
||||||
btnConnect.setText("Disconnect");
|
btnConnect.setText("Disconnect");
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package mage.client.game;
|
package mage.client.game;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import mage.client.components.MageUI;
|
import mage.client.components.MageUI;
|
||||||
import mage.interfaces.MageClient;
|
import mage.interfaces.MageClient;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
|
@ -13,6 +10,9 @@ import mage.utils.MageVersion;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for emulating the connection from multi mage clients.
|
* Test for emulating the connection from multi mage clients.
|
||||||
*
|
*
|
||||||
|
@ -74,6 +74,11 @@ public class MultiConnectTest {
|
||||||
logger.info("disconnected");
|
logger.info("disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reconnect() {
|
||||||
|
logger.info("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showMessage(String message) {
|
public void showMessage(String message) {
|
||||||
logger.info("showMessage: " + message);
|
logger.info("showMessage: " + message);
|
||||||
|
|
|
@ -40,6 +40,7 @@ public interface MageClient extends CallbackClient {
|
||||||
MageVersion getVersion();
|
MageVersion getVersion();
|
||||||
void connected(String message);
|
void connected(String message);
|
||||||
void disconnected();
|
void disconnected();
|
||||||
|
void reconnect();
|
||||||
void showMessage(String message);
|
void showMessage(String message);
|
||||||
void showError(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.transport.socket.SocketWrapper;
|
||||||
import org.jboss.remoting.transporter.TransporterClient;
|
import org.jboss.remoting.transporter.TransporterClient;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -1285,7 +1286,10 @@ public class SessionImpl implements Session {
|
||||||
try {
|
try {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
if (!server.ping(sessionId)) {
|
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;
|
return true;
|
||||||
|
|
|
@ -257,6 +257,11 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reconnect() {
|
||||||
|
logger.info("Not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showMessage(final String message) {
|
public void showMessage(final String message) {
|
||||||
if (SwingUtilities.isEventDispatchThread()) {
|
if (SwingUtilities.isEventDispatchThread()) {
|
||||||
|
|
Loading…
Reference in a new issue