summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/network/ConnectionControl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/network/ConnectionControl.java')
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 6cd3fc0..1844922 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -136,6 +136,10 @@ class ConnectionControl {
new Thread(new SendGameOfferRunner(offeredGame)).start();
}
+ private void sendChangeColor(Color color) {
+ new Thread(new SendChangeColorRunner(color)).start();
+ }
+
private static void emitLater(final Event event) {
SwingUtilities.invokeLater(new Runnable() {
@Override
@@ -160,8 +164,8 @@ class ConnectionControl {
.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;
}
@@ -172,27 +176,31 @@ class ConnectionControl {
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();
}
} else if (messageType.equals("game_join")) {
- gameJoinEvent.emit(UUID.fromString(extension.getValue("uuid")), sender);
+ gameJoinEvent.emit(UUID.fromString(extension.getValue("uuid")),
+ sender);
} else if (messageType.equals("game_leave")) {
- gameLeaveEvent.emit(UUID.fromString(extension.getValue("uuid")), sender);
+ gameLeaveEvent.emit(UUID.fromString(extension.getValue("uuid")),
+ sender);
} else if (messageType.equals("game_join_ack")) {
gameJoinAckEvent.emit(UUID.fromString(extension.getValue("uuid")),
Boolean.valueOf(extension.getValue("ack")));
} else if (messageType.equals("changeColor")) {
changeColorEvent.emit(UUID.fromString(extension.getValue("uuid")),
- sender, (Color) Base64.decodeToObject(extension.getValue("color")));
+ sender, (Color) Base64.decodeToObject(extension
+ .getValue("color")));
} else {
System.err.println("Received unrecognized message of type '"
+ messageType + "'");
@@ -204,8 +212,8 @@ class ConnectionControl {
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));
return createMessage(extension);
}
@@ -246,7 +254,8 @@ class ConnectionControl {
return createMessage(extension);
}
- private Message createGameAckMessage(UUID uuid, String recipient, boolean ack) {
+ private Message createGameAckMessage(UUID uuid, String recipient,
+ boolean ack) {
DefaultPacketExtension extension = createJRummikubExtension();
extension.setValue("messageType", "game_join_ack");
@@ -317,7 +326,8 @@ class ConnectionControl {
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 += "_";
@@ -446,7 +456,8 @@ class ConnectionControl {
public void run() {
synchronized (ConnectionControl.this) {
if (connection != null) {
- connection.sendPacket(createGameAckMessage(uuid, recipient, ack));
+ connection.sendPacket(createGameAckMessage(uuid, recipient,
+ ack));
}
}
}