64 lines
2.8 KiB
Java
64 lines
2.8 KiB
Java
package uulm.teamname.marvelous.gamelibrary.messages;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
|
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
import uulm.teamname.marvelous.gamelibrary.messages.client.*;
|
|
import uulm.teamname.marvelous.gamelibrary.messages.server.*;
|
|
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* The basic message from the standard, containing all possible expansion keys. In other words, one needs to check the
|
|
* messageType, as fields that aren't sent are null. Note that most messages are not deserialized into the {@link
|
|
* BasicMessage}, but instead into messages such as the {@link EventMessage} or {@link GameAssignmentMessage}.
|
|
*/
|
|
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "messageType")
|
|
@JsonSubTypes({
|
|
@Type(value = HelloClientMessage.class, name = "HELLO_CLIENT"),
|
|
@Type(value = HelloServerMessage.class, name = "HELLO_SERVER"),
|
|
@Type(value = ErrorMessage.class, name = "ERROR"),
|
|
@Type(value = PlayerReadyMessage.class, name = "PLAYER_READY"),
|
|
@Type(value = ReconnectMessage.class, name = "RECONNECT"),
|
|
@Type(value = GameAssignmentMessage.class, name = "GAME_ASSIGNMENT"),
|
|
@Type(value = GeneralAssignmentMessage.class, name = "GENERAL_ASSIGNMENT"),
|
|
@Type(value = CharacterSelectionMessage.class, name = "CHARACTER_SELECTION"),
|
|
@Type(value = ConfirmSelectionMessage.class, name = "CONFIRM_SELECTION"),
|
|
@Type(value = GameStructureMessage.class, name = "GAME_STRUCTURE"),
|
|
@Type(value = EventMessage.class, name = "EVENTS"),
|
|
@Type(value = RequestMessage.class, name = "REQUESTS"),
|
|
@Type(value = GoodbyeClientMessage.class, name = "GOODBYE_CLIENT")
|
|
})
|
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
public class BasicMessage {
|
|
|
|
/* The messageType describes the type of message that might be sent. Override this with the local MessageType. */
|
|
public MessageType messageType;
|
|
|
|
/** I have no idea what this might be used for, even less the boolean in the answer */
|
|
public String optionals;
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
BasicMessage that = (BasicMessage) o;
|
|
return messageType == that.messageType && Objects.equals(optionals, that.optionals);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(messageType, optionals);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "BasicMessage{" +
|
|
"messageType=" + messageType +
|
|
", optionals='" + optionals + '\'' +
|
|
'}';
|
|
}
|
|
}
|
|
// @JsonDeserialize(using = MessageDeserializer.class)
|