diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-20 06:41:15 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-20 06:41:15 +0200 |
commit | 0c3eb9a28363ae697f984d9413eb187bfe2511a9 (patch) | |
tree | e72cc28d72bd27c0dad9372d3b51274af9ffdeed /src/jrummikub/control/network | |
parent | 74d8205f30732a8afd6aa45f859188b0a3d447e5 (diff) | |
download | JRummikub-0c3eb9a28363ae697f984d9413eb187bfe2511a9.tar JRummikub-0c3eb9a28363ae697f984d9413eb187bfe2511a9.zip |
Fixed a bunch of network synchronization bugs
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@510 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/network')
4 files changed, 55 insertions, 36 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index d791344..871d06b 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -6,15 +6,18 @@ import java.util.UUID; import javax.swing.SwingUtilities; import jrummikub.model.GameSettings; +import jrummikub.model.IHand; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.Event2; +import jrummikub.util.Event3; import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; +import jrummikub.util.IEvent3; import jrummikub.util.LoginData; import jrummikub.view.LoginError; @@ -63,7 +66,7 @@ public class ConnectionControl implements IConnectionControl { private Event roundStartEvent = new Event(); private Event1<ITable> tableUpdateEvent = new Event1<ITable>(); - private Event1<ITable> turnEndEvent = new Event1<ITable>(); + private Event3<IHand, ITable, ITable> turnEndEvent = new Event3<IHand, ITable, ITable>(); private Event1<IRoundState> turnStartEvent = new Event1<IRoundState>(); private GameData currentGame; @@ -163,7 +166,7 @@ public class ConnectionControl implements IConnectionControl { } @Override - public IEvent1<ITable> getTurnEndEvent() { + public IEvent3<IHand, ITable, ITable> getTurnEndEvent() { return turnEndEvent; } @@ -302,14 +305,20 @@ public class ConnectionControl implements IConnectionControl { } @Override - public void endTurn(final ITable table) { + public void endTurn(final IHand oldHand, final ITable oldTable, + final ITable newTable) { final UUID uuid = currentGame.getGameID(); run(new SendRunner() { @Override protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "turn_end"); extension.setValue("uuid", uuid.toString()); - extension.setValue("table", Base64.encodeObject(table, Base64.GZIP)); + 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)); } }); } @@ -438,8 +447,10 @@ public class ConnectionControl implements IConnectionControl { tableUpdateEvent.emit((ITable) Base64.decodeToObject(extension .getValue("table"))); } else if (messageType.equals("turn_end")) { - turnEndEvent.emit((ITable) Base64.decodeToObject(extension - .getValue("table"))); + turnEndEvent.emit( + (IHand) Base64.decodeToObject(extension.getValue("old_hand")), + (ITable) Base64.decodeToObject(extension.getValue("old_table")), + (ITable) Base64.decodeToObject(extension.getValue("new_table"))); } else if (messageType.equals("turn_start")) { turnStartEvent.emit((IRoundState) Base64.decodeToObject(extension .getValue("state"))); diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java index 52c7fd1..38bc05c 100644 --- a/src/jrummikub/control/network/IConnectionControl.java +++ b/src/jrummikub/control/network/IConnectionControl.java @@ -3,12 +3,14 @@ package jrummikub.control.network; import java.awt.Color; import java.util.UUID; +import jrummikub.model.IHand; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; +import jrummikub.util.IEvent3; import jrummikub.view.LoginError; interface IConnectionControl { @@ -41,7 +43,7 @@ interface IConnectionControl { public IEvent1<ITable> getTableUpdateEvent(); - public IEvent1<ITable> getTurnEndEvent(); + public IEvent3<IHand, ITable, ITable> getTurnEndEvent(); public IEvent1<IRoundState> getTurnStartEvent(); @@ -67,7 +69,7 @@ interface IConnectionControl { public void updateTable(ITable table); - public void endTurn(ITable table); + public void endTurn(IHand oldHand, ITable oldTable, ITable newTable); public void startTurn(IRoundState state); }
\ No newline at end of file diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java index a9775b7..81820e7 100644 --- a/src/jrummikub/control/network/NetworkRoundControl.java +++ b/src/jrummikub/control/network/NetworkRoundControl.java @@ -2,9 +2,10 @@ package jrummikub.control.network; import jrummikub.control.RoundControl; import jrummikub.control.turn.ITurnControl; +import jrummikub.model.IHand; import jrummikub.model.IRoundState; import jrummikub.model.ITable; -import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; import jrummikub.util.IListener1; import jrummikub.view.IView; @@ -23,7 +24,8 @@ public class NetworkRoundControl extends RoundControl { new IListener1<IRoundState>() { @Override public void handle(IRoundState state) { - NetworkControl.fixGameSettings(state.getGameSettings(), connectionControl.getNickname()); + NetworkControl.fixGameSettings(state.getGameSettings(), + connectionControl.getNickname()); setRoundState(state); startTurn(); @@ -42,8 +44,8 @@ public class NetworkRoundControl extends RoundControl { } @Override - protected ITurnControl createTurnControl(PlayerSettings playerSettings) { - switch (playerSettings.getType()) { + protected ITurnControl createTurnControl(Type type) { + switch (type) { case HUMAN: currentlyActive = true; break; @@ -56,7 +58,7 @@ public class NetworkRoundControl extends RoundControl { return new NetworkTurnControl(connectionControl); } - return super.createTurnControl(playerSettings); + return super.createTurnControl(type); } @Override @@ -71,11 +73,11 @@ public class NetworkRoundControl extends RoundControl { } @Override - protected void endOfTurn(ITable newTable) { + protected void endOfTurn(IHand oldHand, ITable oldTable, ITable newTable) { if (currentlyActive) { - connectionControl.endTurn(newTable); + connectionControl.endTurn(oldHand, oldTable, newTable); } - super.endOfTurn(newTable); + super.endOfTurn(oldHand, oldTable, newTable); } } diff --git a/src/jrummikub/control/network/NetworkTurnControl.java b/src/jrummikub/control/network/NetworkTurnControl.java index d80c9b3..57851a2 100644 --- a/src/jrummikub/control/network/NetworkTurnControl.java +++ b/src/jrummikub/control/network/NetworkTurnControl.java @@ -1,52 +1,56 @@ package jrummikub.control.network; import jrummikub.control.turn.AbstractTurnControl; +import jrummikub.model.IHand; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.Event1; import jrummikub.util.IEvent1; import jrummikub.util.IListener1; +import jrummikub.util.IListener3; public class NetworkTurnControl extends AbstractTurnControl { private IConnectionControl connectionControl; private Event1<IRoundState> stateUpdateEvent = new Event1<IRoundState>(); - - + public NetworkTurnControl(IConnectionControl connectionControl) { this.connectionControl = connectionControl; } - + public IEvent1<IRoundState> getStateUpdateEvent() { return stateUpdateEvent; } - + @Override public void doStartTurn() { - connections.add(connectionControl.getTableUpdateEvent().add(new IListener1<ITable>() { - @Override - public void handle(ITable table) { - view.getTablePanel().setStoneSets(table); - } - })); - connections.add(connectionControl.getTurnEndEvent().add(new IListener1<ITable>() { - @Override - public void handle(ITable table) { - endOfTurn(table); - } - })); + connections.add(connectionControl.getTableUpdateEvent().add( + new IListener1<ITable>() { + @Override + public void handle(ITable table) { + view.getTablePanel().setStoneSets(table); + } + })); + connections.add(connectionControl.getTurnEndEvent().add( + new IListener3<IHand, ITable, ITable>() { + @Override + public void handle(IHand oldHand, ITable oldTable, ITable newTable) { + endOfTurn(oldHand, oldTable, newTable); + } + })); timer.startTimer(); } - private void endOfTurn(ITable newTable) { + private void endOfTurn(IHand oldHand, ITable oldTable, ITable newTable) { cleanUp(); - endOfTurnEvent.emit(newTable); + + endOfTurnEvent.emit(oldHand, oldTable, newTable); } - + @Override protected void timeOut() { } - + @Override protected void pauseTurn() { } |