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.java22
-rw-r--r--src/jrummikub/control/network/GameJoinControl.java8
-rw-r--r--src/jrummikub/control/network/NetworkControl.java14
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java2
-rw-r--r--src/jrummikub/control/network/NetworkTurnControl.java3
5 files changed, 21 insertions, 28 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();
diff --git a/src/jrummikub/control/network/GameJoinControl.java b/src/jrummikub/control/network/GameJoinControl.java
index d846ebc..cbdc4de 100644
--- a/src/jrummikub/control/network/GameJoinControl.java
+++ b/src/jrummikub/control/network/GameJoinControl.java
@@ -2,7 +2,6 @@ package jrummikub.control.network;
import java.util.UUID;
-import jrummikub.model.GameSettings;
import jrummikub.util.Event;
import jrummikub.util.GameData;
import jrummikub.util.IEvent;
@@ -31,7 +30,6 @@ public class GameJoinControl extends AbstractGameBeginControl {
final GameData gameData, final IView view) {
super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN);
- NetworkControl.fixGameSettings(gameData.getGameSettings(), connectionControl.getNickname());
updateSettingsPanel();
connections.add(connectionControl.getGameOfferEvent().add(
@@ -39,11 +37,7 @@ public class GameJoinControl extends AbstractGameBeginControl {
@Override
public void handle(GameData data) {
if (data.getGameID().equals(gameData.getGameID())) {
- GameSettings settings = data.getGameSettings();
-
- NetworkControl.fixGameSettings(settings, connectionControl.getNickname());
-
- gameData.setGameSettings(settings);
+ gameData.setGameSettings(data.getGameSettings());
updateSettingsPanel();
}
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index b76c42a..a9b889f 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -8,8 +8,6 @@ import java.util.UUID;
import jrummikub.control.SaveControl;
import jrummikub.model.GameSettings;
-import jrummikub.model.PlayerSettings;
-import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.Connection;
import jrummikub.util.Event;
import jrummikub.util.GameData;
@@ -43,18 +41,6 @@ public class NetworkControl {
private List<UUID> games = new ArrayList<UUID>();
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
- public static void fixGameSettings(GameSettings settings, String nickname) {
- for (PlayerSettings player : settings.getPlayerList()) {
- if (player.getType() == Type.HUMAN) {
- player.setType(Type.NETWORK);
- }
-
- if (player.getType() == Type.NETWORK && player.getName().equals(nickname)) {
- player.setType(Type.HUMAN);
- }
- }
- }
-
/**
* Creates a new network control
*
diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java
index 95b5885..934abf0 100644
--- a/src/jrummikub/control/network/NetworkRoundControl.java
+++ b/src/jrummikub/control/network/NetworkRoundControl.java
@@ -24,8 +24,6 @@ public class NetworkRoundControl extends RoundControl {
new IListener1<IRoundState>() {
@Override
public void handle(IRoundState state) {
- NetworkControl.fixGameSettings(state.getGameSettings(),
- connectionControl.getNickname());
setRoundState(state);
}
}));
diff --git a/src/jrummikub/control/network/NetworkTurnControl.java b/src/jrummikub/control/network/NetworkTurnControl.java
index a884fda..dacc892 100644
--- a/src/jrummikub/control/network/NetworkTurnControl.java
+++ b/src/jrummikub/control/network/NetworkTurnControl.java
@@ -34,9 +34,6 @@ public class NetworkTurnControl extends AbstractTurnControl {
new IListener2<IRoundState, InvalidTurnInfo>() {
@Override
public void handle(IRoundState state, InvalidTurnInfo invalidTurnInfo) {
- NetworkControl.fixGameSettings(state.getGameSettings(),
- connectionControl.getNickname());
-
endOfTurn(state, invalidTurnInfo);
}
}));