Client- und Server-Nachrichten implementiert(#9)

main
Johannes Hochwart 3 years ago
parent b98d25599b
commit daa64e0393

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

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

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

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

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

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

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

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

@ -4,4 +4,5 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public final class JugglingMessage extends ObserverMessage {
}

@ -0,0 +1,5 @@
package eu.jonahbauer.wizard.common.messages.server;
public final class AckMessage extends ServerMessage {
}

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

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

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

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

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

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

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

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

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

@ -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;
}
Loading…
Cancel
Save