Weitere Client- und ServerMessages für Verbindungsverlust und VoteCick

main
Johannes Hochwart 3 years ago
parent d037ada8c5
commit c0f309c844

@ -7,7 +7,7 @@ import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@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() public static final Gson GSON = new GsonBuilder()
.registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ClientMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ClientMessage.class, "Message"))
.registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message"))

@ -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;
}

@ -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;
}

@ -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;
}

@ -7,7 +7,7 @@ import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@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() public static final Gson GSON = new GsonBuilder()
.registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ServerMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ServerMessage.class, "Message"))
.registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message"))

@ -9,7 +9,7 @@ import java.util.UUID;
@Getter @Getter
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public final class JoinedSessionMessage extends ServerMessage implements Response { public final class SessionJoinedMessage extends ServerMessage implements Response {
/** /**
* UUID of joined session * UUID of joined session
*/ */
@ -22,10 +22,15 @@ public final class JoinedSessionMessage extends ServerMessage implements Respons
* List of players already in the session * List of players already in the session
*/ */
private final List<PlayerData> players; private final List<PlayerData> 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<PlayerData> players) { public SessionJoinedMessage(UUID session, UUID player, List<PlayerData> players, String secret) {
this.session = session; this.session = session;
this.player = player; this.player = player;
this.players = List.copyOf(players); this.players = List.copyOf(players);
this.secret = secret;
} }
} }

@ -8,8 +8,5 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public final class StartingGameMessage extends ServerMessage { public final class StartingGameMessage extends ServerMessage {
/**
* Time of game start in {@link System#currentTimeMillis() UNIX time}
*/
private final long time;
} }

Loading…
Cancel
Save