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
This commit is contained in:
parent
dbd57d4218
commit
f4972b339b
5 changed files with 22 additions and 41 deletions
|
@ -4,6 +4,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.util.Event;
|
import jrummikub.util.Event;
|
||||||
import jrummikub.util.Event1;
|
import jrummikub.util.Event1;
|
||||||
import jrummikub.util.IEvent;
|
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.PacketExtension;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.packet.XMPPError.Type;
|
import org.jivesoftware.smack.packet.XMPPError.Type;
|
||||||
|
import org.jivesoftware.smack.util.Base64;
|
||||||
import org.jivesoftware.smackx.muc.DiscussionHistory;
|
import org.jivesoftware.smackx.muc.DiscussionHistory;
|
||||||
import org.jivesoftware.smackx.muc.MultiUserChat;
|
import org.jivesoftware.smackx.muc.MultiUserChat;
|
||||||
|
|
||||||
|
@ -120,14 +122,10 @@ class ConnectionControl {
|
||||||
host = host.substring(host.indexOf('/') + 1);
|
host = host.substring(host.indexOf('/') + 1);
|
||||||
|
|
||||||
UUID uuid = UUID.fromString(extension.getValue("uuid"));
|
UUID uuid = UUID.fromString(extension.getValue("uuid"));
|
||||||
int currentPlayerCount = Integer.parseInt(extension
|
GameSettings settings = (GameSettings) Base64.decodeToObject(extension
|
||||||
.getValue("currentPlayerCount"));
|
.getValue("gameSettings"));
|
||||||
int maxPlayerCount = Integer.parseInt(extension
|
|
||||||
.getValue("maxPlayerCount"));
|
|
||||||
|
|
||||||
GameData gameData = new GameData(uuid, host);
|
GameData gameData = new GameData(uuid, settings, host);
|
||||||
gameData.setCurrentPlayerCount(currentPlayerCount);
|
|
||||||
gameData.setMaxPlayerCount(maxPlayerCount);
|
|
||||||
gameOfferEvent.emit(gameData);
|
gameOfferEvent.emit(gameData);
|
||||||
} else if (messageType.equals("game_withdrawal")) {
|
} else if (messageType.equals("game_withdrawal")) {
|
||||||
gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid")));
|
gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid")));
|
||||||
|
@ -143,10 +141,8 @@ class ConnectionControl {
|
||||||
|
|
||||||
extension.setValue("messageType", "game_offer");
|
extension.setValue("messageType", "game_offer");
|
||||||
extension.setValue("uuid", data.getGameID().toString());
|
extension.setValue("uuid", data.getGameID().toString());
|
||||||
extension.setValue("currentPlayerCount",
|
extension.setValue("gameSettings",
|
||||||
Integer.toString(data.getCurrentPlayerCount()));
|
Base64.encodeObject(data.getGameSettings(), Base64.GZIP));
|
||||||
extension.setValue("maxPlayerCount",
|
|
||||||
Integer.toString(data.getMaxPlayerCount()));
|
|
||||||
|
|
||||||
return createMessage(extension);
|
return createMessage(extension);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,6 @@ public class NetworkControl {
|
||||||
public void handle() {
|
public void handle() {
|
||||||
view.getGameListPanel().setChannelName(loginData.getChannelName());
|
view.getGameListPanel().setChannelName(loginData.getChannelName());
|
||||||
view.showGameListPanel(true);
|
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;
|
game = value;
|
||||||
gameMap.put(value.getGameID(), value);
|
gameMap.put(value.getGameID(), value);
|
||||||
} else {
|
} else {
|
||||||
game.setCurrentPlayerCount(value.getCurrentPlayerCount());
|
game.setGameSettings(value.getGameSettings());
|
||||||
game.setMaxPlayerCount(value.getMaxPlayerCount());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view.getGameListPanel().addGame(game);
|
view.getGameListPanel().addGame(game);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import jrummikub.view.IGameListPanel.GameData;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
public class NetworkSettingsControl extends SettingsControl {
|
public class NetworkSettingsControl extends SettingsControl {
|
||||||
private GameData gameData = new GameData(UUID.randomUUID());
|
private GameData gameData = new GameData(UUID.randomUUID(), settings);
|
||||||
private ConnectionControl connectionControl;
|
private ConnectionControl connectionControl;
|
||||||
|
|
||||||
public NetworkSettingsControl(ConnectionControl connectionControl, IView view, GameSettings settings) {
|
public NetworkSettingsControl(ConnectionControl connectionControl, IView view, GameSettings settings) {
|
||||||
|
@ -24,9 +24,6 @@ public class NetworkSettingsControl extends SettingsControl {
|
||||||
@Override
|
@Override
|
||||||
protected void update() {
|
protected void update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
gameData.setMaxPlayerCount(settings.getPlayerList().size());
|
|
||||||
|
|
||||||
connectionControl.offerGame(gameData);
|
connectionControl.offerGame(gameData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package jrummikub.view;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
|
|
||||||
|
@ -9,33 +10,25 @@ public interface IGameListPanel {
|
||||||
public static class GameData {
|
public static class GameData {
|
||||||
private UUID gameID;
|
private UUID gameID;
|
||||||
private String host;
|
private String host;
|
||||||
private int currentPlayerCount = 0;
|
private GameSettings gameSettings;
|
||||||
private int maxPlayerCount = 0;
|
|
||||||
|
|
||||||
public GameData(UUID gameID) {
|
public GameData(UUID gameID, GameSettings settings) {
|
||||||
this.gameID = gameID;
|
this(gameID, settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameData(UUID gameID, String host) {
|
public GameData(UUID gameID, GameSettings settings, String host) {
|
||||||
this.gameID = gameID;
|
this.gameID = gameID;
|
||||||
|
this.gameSettings = settings;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentPlayerCount(int i) {
|
public void setGameSettings(GameSettings settings) {
|
||||||
currentPlayerCount = i;
|
gameSettings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentPlayerCount() {
|
public GameSettings getGameSettings() {
|
||||||
return currentPlayerCount;
|
return gameSettings;
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxPlayerCount(int i) {
|
|
||||||
maxPlayerCount = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxPlayerCount() {
|
|
||||||
return maxPlayerCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
|
|
|
@ -191,8 +191,9 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
GameData gameData = (GameData) value;
|
GameData gameData = (GameData) value;
|
||||||
|
|
||||||
host = gameData.getHost();
|
host = gameData.getHost();
|
||||||
playerCount = gameData.getCurrentPlayerCount() + "/"
|
/*playerCount = gameData.getCurrentPlayerCount() + "/"
|
||||||
+ gameData.getMaxPlayerCount();
|
+ gameData.getMaxPlayerCount();*/
|
||||||
|
playerCount = String.valueOf(gameData.getGameSettings().getPlayerList().size());
|
||||||
} else {
|
} else {
|
||||||
host = String.valueOf(value);
|
host = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue