From 72bef7143ae4914821b852b5a478d385d342ff4a Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 25 Nov 2024 02:05:56 +0100 Subject: [PATCH] serialize messages --- .../message/server/BuyPropertyResponse.java | 14 +++++++++++--- .../pp/monopoly/message/server/DiceResult.java | 8 ++++++++ .../monopoly/message/server/EventDrawCard.java | 10 +++++++++- .../pp/monopoly/message/server/GameOver.java | 10 +++++++++- .../pp/monopoly/message/server/GameStart.java | 10 +++++++++- .../pp/monopoly/message/server/JailEvent.java | 10 +++++++++- .../monopoly/message/server/NextPlayerTurn.java | 10 +++++++++- .../message/server/PlayerStatusUpdate.java | 14 +++++++++++--- .../monopoly/message/server/TimeOutWarning.java | 10 +++++++++- .../pp/monopoly/message/server/TradeReply.java | 8 ++++++++ .../pp/monopoly/message/server/TradeRequest.java | 8 ++++++++ .../message/server/ViewAssetsResponse.java | 16 ++++++++++++---- .../java/pp/monopoly/server/MonopolyServer.java | 7 +++++++ 13 files changed, 119 insertions(+), 16 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java index e926317..39e1e24 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java @@ -1,12 +1,20 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + /** * Represents the server's response to a player's request to buy a property. */ +@Serializable public class BuyPropertyResponse extends ServerMessage{ - private final boolean successful; - private final String propertyName; - private final String reason; // Reason for failure, if any + private boolean successful; + private String propertyName; + private String reason; // Reason for failure, if any + + /** + * Default constructor for serialization purposes. + */ + private BuyPropertyResponse() { /* empty */ } public BuyPropertyResponse(boolean successful, String propertyName, String reason) { this.successful = successful; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java index 65a8223..4d63f91 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java @@ -2,10 +2,18 @@ package pp.monopoly.message.server; import java.util.List; +import com.jme3.network.serializing.Serializable; + +@Serializable public class DiceResult extends ServerMessage{ private List rollResult; + /** + * Default constructor for serialization purposes. + */ + private DiceResult() { /* empty */ } + public DiceResult(List rollResult) { this.rollResult = rollResult; } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java index 968f2bb..929ac6e 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java @@ -1,7 +1,15 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + +@Serializable public class EventDrawCard extends ServerMessage{ - private final String cardDescription; + private String cardDescription; + + /** + * Default constructor for serialization purposes. + */ + private EventDrawCard() { /* empty */ } public EventDrawCard(String cardDescription) { this.cardDescription = cardDescription; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java index e91041e..91de2fc 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java @@ -1,7 +1,15 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + +@Serializable public class GameOver extends ServerMessage{ - private final boolean isWinner; + private boolean isWinner; + + /** + * Default constructor for serialization purposes. + */ + private GameOver() { /* empty */ } public GameOver(boolean isWinner) { this.isWinner = isWinner; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java index 17679e5..f01e553 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java @@ -1,10 +1,18 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.game.server.PlayerHandler; +@Serializable public class GameStart extends ServerMessage{ - private final PlayerHandler ph; + private PlayerHandler ph; + + /** + * Default constructor for serialization purposes. + */ + private GameStart() { /* empty */ } public GameStart(PlayerHandler ph) { this.ph = ph; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java index 485a7fd..9996545 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java @@ -1,8 +1,16 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + +@Serializable public class JailEvent extends ServerMessage{ - private final boolean goingToJail; + private boolean goingToJail; + + /** + * Default constructor for serialization purposes. + */ + private JailEvent() { /* empty */ } public JailEvent(boolean goingToJail) { this.goingToJail = goingToJail; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/NextPlayerTurn.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/NextPlayerTurn.java index f047f90..d0f5a18 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/NextPlayerTurn.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/NextPlayerTurn.java @@ -1,10 +1,18 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.game.server.Player; +@Serializable public class NextPlayerTurn extends ServerMessage{ - private final Player player; + private Player player; + + /** + * Default constructor for serialization purposes. + */ + private NextPlayerTurn() { /* empty */ } public NextPlayerTurn(Player player) { this.player = player; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java index c876108..0a84661 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java @@ -1,12 +1,20 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.game.server.PlayerColor; +@Serializable public class PlayerStatusUpdate extends ServerMessage{ - private final String playerName; - private final String status; - private final PlayerColor color; + private String playerName; + private String status; + private PlayerColor color; + + /** + * Default constructor for serialization purposes. + */ + private PlayerStatusUpdate() { /* empty */ } public PlayerStatusUpdate(String playerName, String status, PlayerColor color) { this.playerName = playerName; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java index b862170..684ee2a 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java @@ -1,8 +1,16 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + +@Serializable public class TimeOutWarning extends ServerMessage{ - private final int remainingTime; + private int remainingTime; + + /** + * Default constructor for serialization purposes. + */ + private TimeOutWarning() { /* empty */ } public TimeOutWarning(int remainingTime) { this.remainingTime = remainingTime; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeReply.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeReply.java index 6535906..38ef4ec 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeReply.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeReply.java @@ -1,14 +1,22 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.model.TradeHandler; /** * Represents a response to a trade offer. */ +@Serializable public class TradeReply extends ServerMessage{ private int initiatorId; private TradeHandler tradeHandler; + /** + * Default constructor for serialization purposes. + */ + private TradeReply() { /* empty */ } + /** * Constructs a TradeResponse with the specified response details. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeRequest.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeRequest.java index 5320953..7afeb34 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeRequest.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TradeRequest.java @@ -1,15 +1,23 @@ package pp.monopoly.message.server; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.model.TradeHandler; /** * Represents a trade Request message from one player to another. */ +@Serializable public class TradeRequest extends ServerMessage{ private int receiverId; private TradeHandler tradehandler; + /** + * Default constructor for serialization purposes. + */ + private TradeRequest() { /* empty */ } + /** * Constructs a TradeRequest with the specified details. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java index be75108..5c944f4 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java @@ -2,18 +2,26 @@ package pp.monopoly.message.server; import java.util.List; +import com.jme3.network.serializing.Serializable; + import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.PropertyField; /** * Represents a response containing the player's assets. */ +@Serializable public class ViewAssetsResponse extends ServerMessage{ - private final List properties; - private final BoardManager board; - private final int accountBalance; - private final int jailCards; + private List properties; + private BoardManager board; + private int accountBalance; + private int jailCards; + + /** + * Default constructor for serialization purposes. + */ + private ViewAssetsResponse() { /* empty */ } /** * Constructs a ViewAssetsResponse with the specified properties and account balance. diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java index 479c36c..6033ec5 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java @@ -122,6 +122,13 @@ public class MonopolyServer implements MessageListener, Connec } private void registerListeners() { + myServer.addMessageListener(this, BuyPropertyRequest.class); + myServer.addMessageListener(this, EndTurn.class); + myServer.addMessageListener(this, PlayerReady.class); + myServer.addMessageListener(this, RollDice.class); + myServer.addMessageListener(this, TradeOffer.class); + myServer.addMessageListener(this, TradeResponse.class); + myServer.addMessageListener(this, ViewAssetsRequest.class); myServer.addConnectionListener(this); }