diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ClientMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ClientMessage.java new file mode 100644 index 0000000..e544518 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ClientMessage.java @@ -0,0 +1,20 @@ +package eu.jonahbauer.wizard.common.messages.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage; +import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode +public abstract sealed class ClientMessage permits CreateSessionMessage, InteractionMessage, JoinSessionMessage, LeaveSessionMessage, ReadyMessage { + public static final Gson GSON = new GsonBuilder() + .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ClientMessage.class, "Message")) + .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) + .create(); + + @Override + public String toString() { + return GSON.toJson(this, ClientMessage.class); + } +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/CreateSessionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/CreateSessionMessage.java new file mode 100644 index 0000000..697afc8 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/CreateSessionMessage.java @@ -0,0 +1,32 @@ +package eu.jonahbauer.wizard.common.messages.client; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.Range; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class CreateSessionMessage extends ClientMessage { + /** + * Name of session + */ + private final String name; + /** + * Name of creating and joining player + */ + private final String playerName; + /** + * Choose of Deck + */ + private final String deck; + /** + * Choose if exact predictions are allowed + */ + private final boolean exactPrediction; + /** + * timout in milliseconds + */ + private final @Range(from = 30*1000, to = 10* 60*1000) long timeout; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/InteractionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/InteractionMessage.java new file mode 100644 index 0000000..9dd8869 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/InteractionMessage.java @@ -0,0 +1,16 @@ +package eu.jonahbauer.wizard.common.messages.client; + +import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class InteractionMessage extends ClientMessage { + /** + * Reference to wrapped {@link PlayerMessage} + */ + private final PlayerMessage playerMessage; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/JoinSessionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/JoinSessionMessage.java new file mode 100644 index 0000000..9d59286 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/JoinSessionMessage.java @@ -0,0 +1,21 @@ +package eu.jonahbauer.wizard.common.messages.client; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.UUID; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class JoinSessionMessage extends ClientMessage { + /** + * uuid of joining session + */ + private final UUID session; + /** + * Name of joining player + */ + private final String playerName; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/LeaveSessionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/LeaveSessionMessage.java new file mode 100644 index 0000000..80ff354 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/LeaveSessionMessage.java @@ -0,0 +1,12 @@ +package eu.jonahbauer.wizard.common.messages.client; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class LeaveSessionMessage extends ClientMessage { + +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ReadyMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ReadyMessage.java new file mode 100644 index 0000000..4a0de94 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ReadyMessage.java @@ -0,0 +1,15 @@ +package eu.jonahbauer.wizard.common.messages.client; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class ReadyMessage extends ClientMessage { + /** + * State of ready + */ + private final boolean ready; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/PlayerData.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/PlayerData.java new file mode 100644 index 0000000..a178760 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/PlayerData.java @@ -0,0 +1,25 @@ +package eu.jonahbauer.wizard.common.messages.data; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.UUID; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode +public class PlayerData { + /** + * UUID of corresponding player + */ + private final UUID id; + /** + * name of corresponding player + */ + private final String name; + /** + * readyState of corresponding player + */ + private final boolean ready; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/SessionData.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/SessionData.java new file mode 100644 index 0000000..1cea59b --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/data/SessionData.java @@ -0,0 +1,25 @@ +package eu.jonahbauer.wizard.common.messages.data; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.UUID; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode +public class SessionData { + /** + * uuid of corresponding session + */ + private final UUID uuid; + /** + * name of corresponding session + */ + private final String name; + /** + * number of players in the corresponding session + */ + private final int playerCount; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/JugglingMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/JugglingMessage.java index 20823fd..22ffc2b 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/JugglingMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/JugglingMessage.java @@ -4,4 +4,5 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) public final class JugglingMessage extends ObserverMessage { + } diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/AckMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/AckMessage.java new file mode 100644 index 0000000..7fee56e --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/AckMessage.java @@ -0,0 +1,5 @@ +package eu.jonahbauer.wizard.common.messages.server; + +public final class AckMessage extends ServerMessage { + +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/GameMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/GameMessage.java new file mode 100644 index 0000000..9429525 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/GameMessage.java @@ -0,0 +1,16 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class GameMessage extends ServerMessage { + /** + * Reference to wrapped {@link ObserverMessage} + */ + private final ObserverMessage observerMessage; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/JoinedSessionMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/JoinedSessionMessage.java new file mode 100644 index 0000000..50cb1df --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/JoinedSessionMessage.java @@ -0,0 +1,22 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import eu.jonahbauer.wizard.common.messages.data.PlayerData; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.UUID; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class JoinedSessionMessage extends ServerMessage { + /** + * uuid of joined session + */ + private final UUID session; + /** + * Reference to data of joined player + */ + private final PlayerData playerData; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/NackMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/NackMessage.java new file mode 100644 index 0000000..1d2e94b --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/NackMessage.java @@ -0,0 +1,13 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class NackMessage extends ServerMessage { + private final int code; + private final String message; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinMessage.java new file mode 100644 index 0000000..964fdb5 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerJoinMessage.java @@ -0,0 +1,16 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import eu.jonahbauer.wizard.common.messages.data.PlayerData; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class PlayerJoinMessage extends ServerMessage { + /** + * Reference to data of left player + */ + private final PlayerData playerData; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeaveMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeaveMessage.java new file mode 100644 index 0000000..19758ca --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/PlayerLeaveMessage.java @@ -0,0 +1,17 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.UUID; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class PlayerLeaveMessage extends ServerMessage { + /** + * {@link java.util.UUID} of leaving player + */ + private final UUID player; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java new file mode 100644 index 0000000..f2570fd --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java @@ -0,0 +1,20 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage; +import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode +public abstract sealed class ServerMessage permits AckMessage, GameMessage, JoinedSessionMessage, NackMessage, PlayerJoinMessage, PlayerLeaveMessage, SessionCreatedMessage, SessionListMessage, SessionRemovedMessage, StartingGameMessage { + public static final Gson GSON = new GsonBuilder() + .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ServerMessage.class, "Message")) + .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) + .create(); + + @Override + public String toString() { + return GSON.toJson(this, ServerMessage.class); + } +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionCreatedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionCreatedMessage.java new file mode 100644 index 0000000..2a1140a --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionCreatedMessage.java @@ -0,0 +1,16 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import eu.jonahbauer.wizard.common.messages.data.SessionData; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class SessionCreatedMessage extends ServerMessage { + /** + * Reference to data of created Session + */ + private final SessionData sessionData; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionListMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionListMessage.java new file mode 100644 index 0000000..80aa9d1 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionListMessage.java @@ -0,0 +1,16 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import eu.jonahbauer.wizard.common.messages.data.SessionData; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class SessionListMessage extends ServerMessage { + /** + * Reference to data of existing Sessions + */ + private final SessionData[] sessionData; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionRemovedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionRemovedMessage.java new file mode 100644 index 0000000..cfc589f --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionRemovedMessage.java @@ -0,0 +1,17 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.UUID; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class SessionRemovedMessage extends ServerMessage { + /** + * {@link UUID} of leaving player + */ + private final UUID player; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/StartingGameMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/StartingGameMessage.java new file mode 100644 index 0000000..0dab3bf --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/StartingGameMessage.java @@ -0,0 +1,16 @@ +package eu.jonahbauer.wizard.common.messages.server; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +public final class StartingGameMessage extends ServerMessage { + /** + * Time of game start in + * {@link System#currentTimeMillis() UNIX time} + */ + private final long time; +}