From f4972b339ba28ee83cee08aa090039edfff12e30 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 11 Jun 2011 03:15:13 +0200 Subject: Transmit a whole GameSettings object with game offers git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@410 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/network/ConnectionControl.java | 20 ++++++++------------ src/jrummikub/control/network/NetworkControl.java | 8 +------- .../control/network/NetworkSettingsControl.java | 5 +---- 3 files changed, 10 insertions(+), 23 deletions(-) (limited to 'src/jrummikub/control/network') diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index 171c15d..56dac8c 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -4,6 +4,7 @@ import java.util.UUID; import javax.swing.SwingUtilities; +import jrummikub.model.GameSettings; import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.IEvent; @@ -24,6 +25,7 @@ import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError.Type; +import org.jivesoftware.smack.util.Base64; import org.jivesoftware.smackx.muc.DiscussionHistory; import org.jivesoftware.smackx.muc.MultiUserChat; @@ -120,14 +122,10 @@ class ConnectionControl { host = host.substring(host.indexOf('/') + 1); UUID uuid = UUID.fromString(extension.getValue("uuid")); - int currentPlayerCount = Integer.parseInt(extension - .getValue("currentPlayerCount")); - int maxPlayerCount = Integer.parseInt(extension - .getValue("maxPlayerCount")); - - GameData gameData = new GameData(uuid, host); - gameData.setCurrentPlayerCount(currentPlayerCount); - gameData.setMaxPlayerCount(maxPlayerCount); + GameSettings settings = (GameSettings) Base64.decodeToObject(extension + .getValue("gameSettings")); + + GameData gameData = new GameData(uuid, settings, host); gameOfferEvent.emit(gameData); } else if (messageType.equals("game_withdrawal")) { gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid"))); @@ -143,10 +141,8 @@ class ConnectionControl { extension.setValue("messageType", "game_offer"); extension.setValue("uuid", data.getGameID().toString()); - extension.setValue("currentPlayerCount", - Integer.toString(data.getCurrentPlayerCount())); - extension.setValue("maxPlayerCount", - Integer.toString(data.getMaxPlayerCount())); + extension.setValue("gameSettings", + Base64.encodeObject(data.getGameSettings(), Base64.GZIP)); return createMessage(extension); } diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index b6dc27e..ed2c8e6 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -36,11 +36,6 @@ public class NetworkControl { public void handle() { view.getGameListPanel().setChannelName(loginData.getChannelName()); view.showGameListPanel(true); - - GameData testData = new GameData(UUID.randomUUID(), "NeoRaider"); - testData.setCurrentPlayerCount(2); - testData.setMaxPlayerCount(4); - } })); @@ -63,8 +58,7 @@ public class NetworkControl { game = value; gameMap.put(value.getGameID(), value); } else { - game.setCurrentPlayerCount(value.getCurrentPlayerCount()); - game.setMaxPlayerCount(value.getMaxPlayerCount()); + game.setGameSettings(value.getGameSettings()); } view.getGameListPanel().addGame(game); diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java index d1a56e6..ff62d14 100644 --- a/src/jrummikub/control/network/NetworkSettingsControl.java +++ b/src/jrummikub/control/network/NetworkSettingsControl.java @@ -8,7 +8,7 @@ import jrummikub.view.IGameListPanel.GameData; import jrummikub.view.IView; public class NetworkSettingsControl extends SettingsControl { - private GameData gameData = new GameData(UUID.randomUUID()); + private GameData gameData = new GameData(UUID.randomUUID(), settings); private ConnectionControl connectionControl; public NetworkSettingsControl(ConnectionControl connectionControl, IView view, GameSettings settings) { @@ -24,9 +24,6 @@ public class NetworkSettingsControl extends SettingsControl { @Override protected void update() { super.update(); - - gameData.setMaxPlayerCount(settings.getPlayerList().size()); - connectionControl.offerGame(gameData); } -- cgit v1.2.3