summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java33
-rw-r--r--src/jrummikub/control/network/IConnectionControl.java2
-rw-r--r--src/jrummikub/control/network/NetworkControl.java25
3 files changed, 59 insertions, 1 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 7491938..0de8776 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -25,6 +25,7 @@ import jrummikub.view.LoginError;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
@@ -117,6 +118,7 @@ public class ConnectionControl implements IConnectionControl {
private Event turnStartEvent = new Event();
private Event1<String> participantLeftEvent = new Event1<String>();
+ private Event connectionLostEvent = new Event();
private GameData currentGame;
@@ -262,6 +264,11 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
+ public IEvent getConnectionLostEvent() {
+ return connectionLostEvent;
+ }
+
+ @Override
public void offerGame(GameData data) {
offeredGame = data;
currentGame = data;
@@ -612,6 +619,7 @@ public class ConnectionControl implements IConnectionControl {
config.setSendPresence(false);
config.setRosterLoadedAtLogin(false);
config.setCompressionEnabled(true);
+ config.setReconnectionAllowed(false);
connection = new XMPPConnection(config);
@@ -651,6 +659,7 @@ public class ConnectionControl implements IConnectionControl {
private LoginError doConnect() {
try {
connection.connect();
+ connection.addConnectionListener(new DisconnectListener());
return null;
} catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
@@ -714,6 +723,30 @@ public class ConnectionControl implements IConnectionControl {
return null;
}
+ private class DisconnectListener implements ConnectionListener {
+ @Override
+ public void connectionClosed() {
+ emitLater(connectionLostEvent);
+ }
+
+ @Override
+ public void connectionClosedOnError(Exception arg0) {
+ connectionClosed();
+ }
+
+ @Override
+ public void reconnectingIn(int arg0) {
+ }
+
+ @Override
+ public void reconnectionFailed(Exception arg0) {
+ }
+
+ @Override
+ public void reconnectionSuccessful() {
+ }
+ }
+
private class LeaveListener implements ParticipantStatusListener {
@Override
public void voiceRevoked(String arg0) {
diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java
index 9307ce0..f9f5edd 100644
--- a/src/jrummikub/control/network/IConnectionControl.java
+++ b/src/jrummikub/control/network/IConnectionControl.java
@@ -54,6 +54,8 @@ interface IConnectionControl {
public IEvent1<String> getParticipantLeftEvent();
+ public IEvent getConnectionLostEvent();
+
public void offerGame(GameData data);
public void withdrawGame();
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index cd0f66f..5e38d1e 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -15,7 +15,6 @@ import jrummikub.util.IEvent;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.LoginData;
-import jrummikub.view.IQuitWarningPanel.QuitMode;
import jrummikub.view.IView;
import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.LoginError;
@@ -141,6 +140,23 @@ public class NetworkControl {
}
}
}));
+ connections.add(connectionControl.getConnectionLostEvent().add(
+ new IListener() {
+ @Override
+ public void handle() {
+ abort();
+ view.setBottomPanel(BottomPanelType.NETWORK_SERVER_CONNECTION_LOST_PANEL);
+ connections.add(view.getAcknowledgeConnectionLostEvent().add(
+ new IListener() {
+ @Override
+ public void handle() {
+ abort();
+ view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
+ backToLoginEvent.emit();
+ }
+ }));
+ }
+ }));
}
private void addOfferUpdateListener() {
@@ -342,6 +358,13 @@ public class NetworkControl {
view.showGameListPanel(true);
}
});
+ gameControl.getEndOfGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
+ view.showGameListPanel(true);
+ }
+ });
gameControl.startGame();
}