From c0f309c84421fd7834c1b1ebcc79e04c64d1cf45 Mon Sep 17 00:00:00 2001 From: Johannes Hochwart Date: Thu, 11 Nov 2021 13:06:08 +0100 Subject: [PATCH] =?UTF-8?q?Weitere=20Client-=20und=20ServerMessages=20f?= =?UTF-8?q?=C3=BCr=20Verbindungsverlust=20und=20VoteCick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/messages/client/ClientMessage.java | 2 +- .../common/messages/client/RejoinMessage.java | 25 +++++++++++++++++++ .../messages/server/KickVotedMessage.java | 25 +++++++++++++++++++ .../common/messages/server/KickedMessage.java | 17 +++++++++++++ .../common/messages/server/ServerMessage.java | 2 +- ...Message.java => SessionJoinedMessage.java} | 9 +++++-- .../messages/server/StartingGameMessage.java | 5 +--- 7 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java create mode 100644 wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java create mode 100644 wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.java rename wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/{JoinedSessionMessage.java => SessionJoinedMessage.java} (66%) 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 index e544518..ea8c352 100644 --- 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 @@ -7,7 +7,7 @@ import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory; import lombok.EqualsAndHashCode; @EqualsAndHashCode -public abstract sealed class ClientMessage permits CreateSessionMessage, InteractionMessage, JoinSessionMessage, LeaveSessionMessage, ReadyMessage { +public abstract sealed class ClientMessage permits CreateSessionMessage, InteractionMessage, JoinSessionMessage, LeaveSessionMessage, ReadyMessage, RejoinMessage { public static final Gson GSON = new GsonBuilder() .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ClientMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java new file mode 100644 index 0000000..256177d --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/RejoinMessage.java @@ -0,0 +1,25 @@ +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 RejoinMessage extends ClientMessage { + /** + * UUID of the session + */ + private final UUID session; + /** + * UUID of the rejoining player + */ + private final UUID player; + /** + * Secret in order to assure that no malicious user wants to join the message + */ + private final String secret; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java new file mode 100644 index 0000000..0a5937b --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickVotedMessage.java @@ -0,0 +1,25 @@ +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 KickVotedMessage extends ServerMessage { + /** + * UUID of the voting player + */ + private final UUID voter; + /** + * UUID of player who is supposed to be kicked + */ + private final UUID player; + /** + * Time until the vote ends in {@link System#currentTimeMillis() UNIX time} + */ + private final long timeout; +} diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.java new file mode 100644 index 0000000..a7ce2d7 --- /dev/null +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/KickedMessage.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 KickedMessage extends ServerMessage { + /** + * UUID of player who was kicked + */ + 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 index 62e90ea..d38f53a 100644 --- 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 @@ -7,7 +7,7 @@ import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory; import lombok.EqualsAndHashCode; @EqualsAndHashCode -public abstract sealed class ServerMessage permits AckMessage, GameMessage, JoinedSessionMessage, NackMessage, PlayerLeftMessage, PlayerModifiedMessage, SessionListMessage, SessionModifiedMessage, SessionRemovedMessage, StartingGameMessage { +public abstract sealed class ServerMessage permits AckMessage, GameMessage, KickVotedMessage, KickedMessage, NackMessage, PlayerLeftMessage, PlayerModifiedMessage, SessionJoinedMessage, SessionListMessage, SessionModifiedMessage, SessionRemovedMessage, StartingGameMessage { public static final Gson GSON = new GsonBuilder() .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ServerMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) 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/SessionJoinedMessage.java similarity index 66% rename from wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/JoinedSessionMessage.java rename to wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/SessionJoinedMessage.java index 5a4af70..e43c74e 100644 --- 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/SessionJoinedMessage.java @@ -9,7 +9,7 @@ import java.util.UUID; @Getter @EqualsAndHashCode(callSuper = true) -public final class JoinedSessionMessage extends ServerMessage implements Response { +public final class SessionJoinedMessage extends ServerMessage implements Response { /** * UUID of joined session */ @@ -22,10 +22,15 @@ public final class JoinedSessionMessage extends ServerMessage implements Respons * List of players already in the session */ private final List players; + /** + * Secret notified to player in order to ensure that if necessary the correct player rejoins + */ + private final String secret; - public JoinedSessionMessage(UUID session, UUID player, List players) { + public SessionJoinedMessage(UUID session, UUID player, List players, String secret) { this.session = session; this.player = player; this.players = List.copyOf(players); + this.secret = secret; } } 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 index fbf8e30..5621c07 100644 --- 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 @@ -8,8 +8,5 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @EqualsAndHashCode(callSuper = true) public final class StartingGameMessage extends ServerMessage { - /** - * Time of game start in {@link System#currentTimeMillis() UNIX time} - */ - private final long time; + }