summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/network')
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java30
-rw-r--r--src/jrummikub/control/network/NetworkControl.java18
2 files changed, 31 insertions, 17 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 6ded0f3..0a36ebd 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -32,6 +32,9 @@ import org.jivesoftware.smack.util.Base64;
import org.jivesoftware.smackx.muc.DiscussionHistory;
import org.jivesoftware.smackx.muc.MultiUserChat;
+/**
+ * Connection control managing network connections, essages and events
+ */
public class ConnectionControl implements IConnectionControl {
private final static String ELEMENT_NAME = "rummikub";
private final static String NAMESPACE = "http://home.universe-factory.net/rummikub/";
@@ -59,6 +62,12 @@ public class ConnectionControl implements IConnectionControl {
private volatile GameData offeredGame;
+ /**
+ * Creates new connection control
+ *
+ * @param loginData
+ * player's login data
+ */
public ConnectionControl(LoginData loginData) {
this.loginData = loginData;
}
@@ -222,7 +231,8 @@ 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));
}
});
@@ -248,8 +258,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));
}
});
}
@@ -287,8 +297,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;
}
@@ -304,13 +314,14 @@ 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();
@@ -393,7 +404,8 @@ 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/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index cfb3c14..71000aa 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -37,6 +37,8 @@ public class NetworkControl {
*
* @param loginData
* user's login data
+ * @param connectionControl
+ * current connection for events and messages
* @param view
* for events and handlers
*/
@@ -48,24 +50,24 @@ public class NetworkControl {
addConnectionSetupListeners(loginData, view);
addConnectionControlListeners(view);
- connections.add(view.getGameListPanel().getJoinEvent().add(
- new IListener1<GameData>() {
+ connections.add(view.getGameListPanel().getJoinEvent()
+ .add(new IListener1<GameData>() {
@Override
public void handle(GameData gameData) {
join(gameData);
}
}));
- connections.add(view.getGameListPanel().getOpenNewGameEvent().add(
- new IListener() {
+ connections.add(view.getGameListPanel().getOpenNewGameEvent()
+ .add(new IListener() {
@Override
public void handle() {
createSettingsControl();
}
}));
- connections.add(view.getGameListPanel().getCancelEvent().add(
- new IListener() {
+ connections.add(view.getGameListPanel().getCancelEvent()
+ .add(new IListener() {
@Override
public void handle() {
abort();
@@ -222,8 +224,8 @@ public class NetworkControl {
}
view.showGameListPanel(false);
- settingsControl = new NetworkSettingsControl(connectionControl
- .getNickname(), view, new GameSettings());
+ settingsControl = new NetworkSettingsControl(
+ connectionControl.getNickname(), view, new GameSettings());
settingsControl.getOfferGameEvent().add(new IListener1<GameSettings>() {
@Override
public void handle(GameSettings settings) {