From 72a16316dc44aaae68530c0f57d342fd919526da Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 20 Jun 2011 15:46:01 +0200 Subject: Fix transmission of turn_end messages git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@512 72836036-5685-4462-b002-a69064685172 --- .../control/network/ConnectionControl.java | 43 +++++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src/jrummikub/control') diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index 871d06b..7c3ed77 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -1,6 +1,7 @@ package jrummikub.control.network; import java.awt.Color; +import java.io.Serializable; import java.util.UUID; import javax.swing.SwingUtilities; @@ -42,6 +43,32 @@ import org.jivesoftware.smackx.muc.MultiUserChat; * Connection control managing network connections, essages and events */ public class ConnectionControl implements IConnectionControl { + private static class TurnEndData implements Serializable { + private static final long serialVersionUID = -3800572117130220737L; + + private IHand oldHand; + private ITable oldTable; + private ITable newTable; + + TurnEndData(IHand oldHand, ITable oldTable, ITable newTable) { + this.oldHand = oldHand; + this.oldTable = oldTable; + this.newTable = newTable; + } + + IHand getOldHand() { + return oldHand; + } + + ITable getOldTable() { + return oldTable; + } + + ITable getNewTable() { + return newTable; + } + } + private final static String ELEMENT_NAME = "rummikub"; private final static String NAMESPACE = "http://home.universe-factory.net/rummikub/"; @@ -313,12 +340,8 @@ public class ConnectionControl implements IConnectionControl { protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "turn_end"); extension.setValue("uuid", uuid.toString()); - extension.setValue("old_hand", - Base64.encodeObject(oldHand, Base64.GZIP)); - extension.setValue("old_table", - Base64.encodeObject(oldTable, Base64.GZIP)); - extension.setValue("new_table", - Base64.encodeObject(newTable, Base64.GZIP)); + extension.setValue("data", Base64.encodeObject(new TurnEndData(oldHand, + oldTable, newTable), Base64.GZIP)); } }); } @@ -447,10 +470,10 @@ public class ConnectionControl implements IConnectionControl { tableUpdateEvent.emit((ITable) Base64.decodeToObject(extension .getValue("table"))); } else if (messageType.equals("turn_end")) { - turnEndEvent.emit( - (IHand) Base64.decodeToObject(extension.getValue("old_hand")), - (ITable) Base64.decodeToObject(extension.getValue("old_table")), - (ITable) Base64.decodeToObject(extension.getValue("new_table"))); + TurnEndData data = (TurnEndData) Base64.decodeToObject(extension + .getValue("data")); + turnEndEvent.emit(data.getOldHand(), data.getOldTable(), + data.getNewTable()); } else if (messageType.equals("turn_start")) { turnStartEvent.emit((IRoundState) Base64.decodeToObject(extension .getValue("state"))); -- cgit v1.2.3