diff options
Diffstat (limited to 'src/jrummikub/control/network/ConnectionControl.java')
-rw-r--r-- | src/jrummikub/control/network/ConnectionControl.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index 9e8446d..832b067 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -12,6 +12,7 @@ import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.model.GameSettings; import jrummikub.model.IRoundState; import jrummikub.model.ITable; +import jrummikub.model.PlayerSettings; import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.Event2; @@ -74,6 +75,19 @@ public class ConnectionControl implements IConnectionControl { } }; + private void fixGameSettings(GameSettings settings) { + for (PlayerSettings player : settings.getPlayerList()) { + if (player.getType() == PlayerSettings.Type.HUMAN) { + player.setType(PlayerSettings.Type.NETWORK); + } + + if (player.getType() == PlayerSettings.Type.NETWORK + && player.getName().equals(getNickname())) { + player.setType(PlayerSettings.Type.HUMAN); + } + } + } + private final LoginData loginData; private volatile Connection connection; private volatile MultiUserChat muc; @@ -493,6 +507,7 @@ public class ConnectionControl implements IConnectionControl { UUID uuid = UUID.fromString(extension.getValue("uuid")); GameSettings settings = (GameSettings) Base64.decodeToObject(extension .getValue("gameSettings")); + fixGameSettings(settings); GameData gameData = new GameData(uuid, settings, sender); gameOfferEvent.emit(gameData); @@ -527,14 +542,17 @@ public class ConnectionControl implements IConnectionControl { } else if (messageType.equals("round_start")) { roundStartEvent.emit(); } else if (messageType.equals("round_state_update")) { - roundStateUpdateEvent.emit((IRoundState) Base64.decodeToObject(extension - .getValue("state"))); + IRoundState state = (IRoundState) Base64.decodeToObject(extension + .getValue("state")); + fixGameSettings(state.getGameSettings()); + roundStateUpdateEvent.emit(state); } else if (messageType.equals("table_update")) { tableUpdateEvent.emit((ITable) Base64.decodeToObject(extension .getValue("table"))); } else if (messageType.equals("turn_end")) { TurnEndData data = (TurnEndData) Base64.decodeToObject(extension .getValue("data")); + fixGameSettings(data.getRoundState().getGameSettings()); turnEndEvent.emit(data.getRoundState(), data.getInvalidTurnInfo()); } else if (messageType.equals("next_player")) { nextPlayerEvent.emit(); |