summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
authorBennet Gerlach <bennet_gerlach@web.de>2011-06-20 03:06:46 +0200
committerBennet Gerlach <bennet_gerlach@web.de>2011-06-20 03:06:46 +0200
commit4df5c0e665991dd19a2f25ee513c3ff85a672c55 (patch)
tree1da402f1c8f98d1a67cfb887f66c2b17d008560a /src/jrummikub/control
parentace7175f1a57f3dc88a861842969e84efacf65ad (diff)
downloadJRummikub-4df5c0e665991dd19a2f25ee513c3ff85a672c55.tar
JRummikub-4df5c0e665991dd19a2f25ee513c3ff85a672c55.zip
Implemented login error messages
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@500 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/ApplicationControl.java76
-rw-r--r--src/jrummikub/control/LoginControl.java18
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java61
-rw-r--r--src/jrummikub/control/network/IConnectionControl.java4
-rw-r--r--src/jrummikub/control/network/NetworkControl.java49
5 files changed, 127 insertions, 81 deletions
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java
index 7a629af..bc16cb4 100644
--- a/src/jrummikub/control/ApplicationControl.java
+++ b/src/jrummikub/control/ApplicationControl.java
@@ -32,7 +32,7 @@ public class ApplicationControl {
* Creates a new application control
*
* @param view
- * the view to use
+ * the view to use
*/
public ApplicationControl(final IView view) {
this.view = view;
@@ -43,15 +43,16 @@ public class ApplicationControl {
public void handle() {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true);
- tempConnection = view.getQuitWarningPanel().getQuitEvent().add(new IListener() {
- @Override
- public void handle() {
- abortControls();
- startApplication();
- view.showQuitWarningPanel(false);
- tempConnection.remove();
- }
- });
+ tempConnection = view.getQuitWarningPanel().getQuitEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ abortControls();
+ startApplication();
+ view.showQuitWarningPanel(false);
+ tempConnection.remove();
+ }
+ });
}
});
view.getMenuQuitEvent().add(new IListener() {
@@ -89,7 +90,7 @@ public class ApplicationControl {
}
}
});
-
+
view.getQuitWarningPanel().getCancelEvent().add(new IListener() {
@Override
public void handle() {
@@ -97,16 +98,22 @@ public class ApplicationControl {
}
});
- addLoginControlListeners();
+ view.getNetworkGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ abortControls();
+
+ createLoginControl();
+ }
+ });
saveControl.getLoadEvent().add(
new IListener3<GameSettings, GameState, IRoundState>() {
@Override
- public void handle(GameSettings settings,
- GameState gameState, IRoundState roundState) {
+ public void handle(GameSettings settings, GameState gameState,
+ IRoundState roundState) {
abortControls();
- gameControl = new GameControl(settings, saveControl,
- view);
+ gameControl = new GameControl(settings, saveControl, view);
addGameControlListeners(gameControl);
gameControl.continueGame(gameState, roundState);
}
@@ -119,28 +126,21 @@ public class ApplicationControl {
});
}
- private void addLoginControlListeners() {
- view.getNetworkGameEvent().add(new IListener() {
+ private void createLoginControl() {
+ loginControl = new LoginControl(view);
+ loginControl.getLoginEvent().add(new IListener1<LoginData>() {
+ @Override
+ public void handle(LoginData loginData) {
+ createNetworkControl(loginData);
+ }
+ });
+ loginControl.getCancelEvent().add(new IListener() {
@Override
public void handle() {
- abortControls();
-
- loginControl = new LoginControl(view);
- loginControl.getLoginEvent().add(new IListener1<LoginData>() {
- @Override
- public void handle(LoginData loginData) {
- createNetworkControl(loginData);
- }
- });
- loginControl.getCancelEvent().add(new IListener() {
- @Override
- public void handle() {
- startApplication();
- }
- });
- loginControl.startLogin();
+ startApplication();
}
});
+ loginControl.startLogin();
}
private void abortControls() {
@@ -215,6 +215,14 @@ public class ApplicationControl {
}
});
+ networkControl.getBackToLoginEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ networkControl = null;
+ createLoginControl();
+ }
+ });
+
networkControl.startNetwork();
}
}
diff --git a/src/jrummikub/control/LoginControl.java b/src/jrummikub/control/LoginControl.java
index 9355220..ccf6e2e 100644
--- a/src/jrummikub/control/LoginControl.java
+++ b/src/jrummikub/control/LoginControl.java
@@ -27,7 +27,7 @@ public class LoginControl {
* Constructor for login Control
*
* @param view
- * for events which need handling
+ * for events which need handling
*/
public LoginControl(final IView view) {
this.view = view;
@@ -36,18 +36,18 @@ public class LoginControl {
@Override
public void handle(LoginData loginData) {
abort();
+ // TODO connectPanel anzeigen
loginEvent.emit(loginData);
}
}));
- connections.add(view.getLoginPanel().getCancelEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- abort();
- cancelEvent.emit();
- }
- }));
+ connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ abort();
+ cancelEvent.emit();
+ }
+ }));
}
/**
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index acccbdc..54c9512 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -16,6 +16,7 @@ import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
import jrummikub.util.LoginData;
+import jrummikub.view.LoginError;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketListener;
@@ -46,7 +47,7 @@ public class ConnectionControl implements IConnectionControl {
private volatile MultiUserChat muc;
private Event connectedEvent = new Event();
- private Event connectionFailedEvent = new Event();
+ private Event1<LoginError> connectionFailedEvent = new Event1<LoginError>();
private Event1<GameData> gameOfferEvent = new Event1<GameData>();
private Event1<UUID> gameWithdrawalEvent = new Event1<UUID>();
@@ -72,7 +73,7 @@ public class ConnectionControl implements IConnectionControl {
* Creates new connection control
*
* @param loginData
- * player's login data
+ * player's login data
*/
public ConnectionControl(LoginData loginData) {
this.loginData = loginData;
@@ -91,7 +92,7 @@ public class ConnectionControl implements IConnectionControl {
@Override
public void disconnect() {
connectedEvent = new Event();
- connectionFailedEvent = new Event();
+ connectionFailedEvent = new Event1<LoginError>();
run(new Runnable() {
@Override
public void run() {
@@ -111,7 +112,7 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
- public IEvent getConnectionFailedEvent() {
+ public IEvent1<LoginError> getConnectionFailedEvent() {
return connectionFailedEvent;
}
@@ -252,8 +253,7 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "change_color");
extension.setValue("uuid", uuid.toString());
- extension.setValue("color",
- Base64.encodeObject(color, Base64.GZIP));
+ extension.setValue("color", Base64.encodeObject(color, Base64.GZIP));
}
});
}
@@ -316,8 +316,8 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "game_offer");
extension.setValue("uuid", data.getGameID().toString());
- extension.setValue("gameSettings", Base64.encodeObject(
- data.getGameSettings(), Base64.GZIP));
+ extension.setValue("gameSettings",
+ Base64.encodeObject(data.getGameSettings(), Base64.GZIP));
}
});
}
@@ -340,6 +340,15 @@ public class ConnectionControl implements IConnectionControl {
});
}
+ private static <T> void emitLater(final Event1<T> event, final T arg) {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ event.emit(arg);
+ }
+ });
+ }
+
private Message createMessage(PacketExtension extension) {
Message message = muc.createMessage();
message.addExtension(extension);
@@ -355,8 +364,8 @@ public class ConnectionControl implements IConnectionControl {
.getExtension(ELEMENT_NAME, NAMESPACE);
if (((Message) packet).getType() == Message.Type.error) {
- System.err.println("Received error message from '"
- + packet.getFrom() + "'");
+ System.err.println("Received error message from '" + packet.getFrom()
+ + "'");
return;
}
@@ -372,14 +381,13 @@ public class ConnectionControl implements IConnectionControl {
String sender, String messageType) {
if (messageType.equals("game_offer")) {
UUID uuid = UUID.fromString(extension.getValue("uuid"));
- GameSettings settings = (GameSettings) Base64
- .decodeToObject(extension.getValue("gameSettings"));
+ GameSettings settings = (GameSettings) Base64.decodeToObject(extension
+ .getValue("gameSettings"));
GameData gameData = new GameData(uuid, settings, sender);
gameOfferEvent.emit(gameData);
} else if (messageType.equals("game_withdrawal")) {
- gameWithdrawalEvent
- .emit(UUID.fromString(extension.getValue("uuid")));
+ gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid")));
} else if (messageType.equals("game_request")) {
if (offeredGame != null) {
sendGameOffer();
@@ -447,10 +455,26 @@ public class ConnectionControl implements IConnectionControl {
connection.disconnect();
connection = null;
- // TODO Auto-generated catch block
+ XMPPError xmppError = e.getXMPPError();
+
+ if (xmppError != null) {
+ int code = xmppError.getCode();
+ if (code == 504) {
+ emitLater(connectionFailedEvent, LoginError.UNKNOWN_HOST);
+ return;
+ } else if (code == 404) {
+ emitLater(connectionFailedEvent, LoginError.UNKNOWN_CHANNEL);
+ return;
+ } else if (code == 503) {
+ emitLater(connectionFailedEvent, LoginError.RESOURCE_CONFLICT);
+ return;
+ } else if (code == 401 || code == 402 || code == 407) {
+ emitLater(connectionFailedEvent, LoginError.AUTHENTICATION_FAILED);
+ return;
+ }
+ }
e.printStackTrace();
-
- emitLater(connectionFailedEvent);
+ emitLater(connectionFailedEvent, LoginError.UNKNOWN_ERROR);
}
}
}
@@ -471,8 +495,7 @@ public class ConnectionControl implements IConnectionControl {
break; // Join was successful, break the loop
} catch (XMPPException e) {
XMPPError error = e.getXMPPError();
- if (error.getType() == Type.CANCEL
- && error.getCode() == 409) {
+ if (error.getType() == Type.CANCEL && error.getCode() == 409) {
// There was a conflict, try again with another
// nickname
nickname += "_";
diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java
index b329b4c..ff23c82 100644
--- a/src/jrummikub/control/network/IConnectionControl.java
+++ b/src/jrummikub/control/network/IConnectionControl.java
@@ -9,6 +9,7 @@ import jrummikub.util.GameData;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
+import jrummikub.view.LoginError;
interface IConnectionControl {
@@ -20,7 +21,7 @@ interface IConnectionControl {
public IEvent getConnectedEvent();
- public IEvent getConnectionFailedEvent();
+ public IEvent1<LoginError> getConnectionFailedEvent();
public IEvent1<GameData> getGameOfferEvent();
@@ -65,5 +66,4 @@ interface IConnectionControl {
public void endTurn(ITable table);
public void startTurn(IRoundState state);
-
} \ No newline at end of file
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index 71000aa..60640db 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -15,6 +15,7 @@ import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.LoginData;
import jrummikub.view.IView;
+import jrummikub.view.LoginError;
/**
* Class dealing with network connection, offering and choice of network games
@@ -24,6 +25,7 @@ public class NetworkControl {
private IView view;
private List<Connection> connections = new ArrayList<Connection>();
private Event stopNetworkEvent = new Event();
+ private Event backToLoginEvent = new Event();
private NetworkSettingsControl settingsControl;
private GameOfferControl gameOfferControl;
@@ -36,11 +38,11 @@ public class NetworkControl {
* Creates a new network control
*
* @param loginData
- * user's login data
+ * user's login data
* @param connectionControl
- * current connection for events and messages
+ * current connection for events and messages
* @param view
- * for events and handlers
+ * for events and handlers
*/
public NetworkControl(final LoginData loginData,
IConnectionControl connectionControl, final IView view) {
@@ -85,7 +87,7 @@ public class NetworkControl {
* Adds the listeners for connection control events
*
* @param view
- * view for events
+ * view for events
*/
public void addConnectionControlListeners(final IView view) {
connections.add(connectionControl.getGameOfferEvent().add(
@@ -133,22 +135,29 @@ public class NetworkControl {
private void addConnectionSetupListeners(final LoginData loginData,
final IView view) {
- connections.add(connectionControl.getConnectedEvent().add(
- new IListener() {
+ connections.add(connectionControl.getConnectedEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ view.getGameListPanel().setChannelName(loginData.getChannelName());
+ view.showGameListPanel(true);
+ }
+ }));
+
+ connections.add(connectionControl.getConnectionFailedEvent().add(
+ new IListener1<LoginError>() {
@Override
- public void handle() {
- view.getGameListPanel().setChannelName(
- loginData.getChannelName());
- view.showGameListPanel(true);
+ public void handle(LoginError error) {
+ view.getConnectPanel().setMode(error);
+ view.showConnectPanel(true);
}
}));
- connections.add(connectionControl.getConnectionFailedEvent().add(
- new IListener() {
+ connections.add(view.getConnectPanel().getCancelEvent()
+ .add(new IListener() {
@Override
public void handle() {
- // TODO Auto-generated method stub
-
+ abort();
+ backToLoginEvent.emit();
}
}));
}
@@ -181,9 +190,11 @@ public class NetworkControl {
}
/**
- * Starts a new network connection with the sepcified data
+ * Starts a new network connection with the specified data
*/
public void startNetwork() {
+ view.showConnectPanel(true);
+ view.getConnectPanel().setMode(null);
connectionControl.connect();
}
@@ -195,6 +206,7 @@ public class NetworkControl {
c.remove();
}
view.showGameListPanel(false);
+ view.showConnectPanel(false);
if (settingsControl != null) {
settingsControl.abort();
@@ -218,6 +230,10 @@ public class NetworkControl {
return stopNetworkEvent;
}
+ public IEvent getBackToLoginEvent() {
+ return backToLoginEvent;
+ }
+
private void createSettingsControl() {
if (settingsControl != null) {
return;
@@ -247,8 +263,7 @@ public class NetworkControl {
if (gameOfferControl != null) {
return;
}
- gameOfferControl = new GameOfferControl(connectionControl, settings,
- view);
+ gameOfferControl = new GameOfferControl(connectionControl, settings, view);
gameOfferControl.getBackEvent().add(new IListener() {
@Override
public void handle() {