From ada41d334050789cd528034689a5cf37db5acee6 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Wed, 19 Feb 2025 11:38:00 +0100 Subject: [PATCH] TD-18: Add Specification of Matchmaking Channel and Creation of Type --- .../matchmaking/in/MatchAcceptedMessage.java | 15 ++ .../in/MatchSetSearchStateMessage.java | 14 ++ .../matchmaking/out/MatchAbortedMessage.java | 25 ++++ .../out/MatchEstablishedMessage.java | 27 ++++ .../matchmaking/out/MatchFoundMessage.java | 29 ++++ ws/ws.yml | 137 +++++++++++++++++- 6 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchAcceptedMessage.java create mode 100644 src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchSetSearchStateMessage.java create mode 100644 src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchAbortedMessage.java create mode 100644 src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchEstablishedMessage.java create mode 100644 src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchFoundMessage.java diff --git a/src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchAcceptedMessage.java b/src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchAcceptedMessage.java new file mode 100644 index 0000000..a870392 --- /dev/null +++ b/src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchAcceptedMessage.java @@ -0,0 +1,15 @@ +package de.towerdefence.server.server.channels.matchmaking.in; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +@NotNull +public class MatchAcceptedMessage { + public static final String MESSAGE_ID = "MatchAccepted"; + @JsonProperty("$id") + private String messageId; + private String matchId; + private boolean accepted; +} diff --git a/src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchSetSearchStateMessage.java b/src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchSetSearchStateMessage.java new file mode 100644 index 0000000..9e53b09 --- /dev/null +++ b/src/main/java/de/towerdefence/server/server/channels/matchmaking/in/MatchSetSearchStateMessage.java @@ -0,0 +1,14 @@ +package de.towerdefence.server.server.channels.matchmaking.in; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +@NotNull +public class MatchSetSearchStateMessage { + public static final String MESSAGE_ID = "MatchSetSearchState"; + @JsonProperty("$id") + private String messageId; + private boolean searching; +} \ No newline at end of file diff --git a/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchAbortedMessage.java b/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchAbortedMessage.java new file mode 100644 index 0000000..731c2b0 --- /dev/null +++ b/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchAbortedMessage.java @@ -0,0 +1,25 @@ +package de.towerdefence.server.server.channels.matchmaking.out; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import de.towerdefence.server.server.JsonMessage; +import lombok.AllArgsConstructor; + +import java.util.Map; + +@AllArgsConstructor +public class MatchAbortedMessage extends JsonMessage { + private String matchId; + + @Override + protected String getMessageId() { + return "MatchAborted"; + } + + @Override + protected Map getData(JsonNodeFactory factory) { + return Map.of( + "matchId", factory.textNode(this.matchId) + ); + } +} diff --git a/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchEstablishedMessage.java b/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchEstablishedMessage.java new file mode 100644 index 0000000..01d2980 --- /dev/null +++ b/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchEstablishedMessage.java @@ -0,0 +1,27 @@ +package de.towerdefence.server.server.channels.matchmaking.out; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import de.towerdefence.server.server.JsonMessage; +import lombok.AllArgsConstructor; + +import java.util.Map; + +@AllArgsConstructor +public class MatchEstablishedMessage extends JsonMessage { + private String matchId; + private String opponentName; + + @Override + protected String getMessageId() { + return "MatchEstablished"; + } + + @Override + protected Map getData(JsonNodeFactory factory) { + return Map.of( + "matchId", factory.textNode(this.matchId), + "opponentName", factory.textNode(this.opponentName) + ); + } +} diff --git a/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchFoundMessage.java b/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchFoundMessage.java new file mode 100644 index 0000000..4869295 --- /dev/null +++ b/src/main/java/de/towerdefence/server/server/channels/matchmaking/out/MatchFoundMessage.java @@ -0,0 +1,29 @@ +package de.towerdefence.server.server.channels.matchmaking.out; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import de.towerdefence.server.server.JsonMessage; +import lombok.AllArgsConstructor; + +import java.util.Map; + +@AllArgsConstructor +public class MatchFoundMessage extends JsonMessage { + private String matchId; + private long created; + private long ttl; + + @Override + protected String getMessageId() { + return "MatchFound"; + } + + @Override + protected Map getData(JsonNodeFactory factory) { + return Map.of( + "matchId", factory.textNode(this.matchId), + "created", factory.numberNode(this.created), + "ttl", factory.numberNode(this.ttl) + ); + } +} diff --git a/ws/ws.yml b/ws/ws.yml index af35b47..5503e26 100644 --- a/ws/ws.yml +++ b/ws/ws.yml @@ -39,9 +39,7 @@ channels: type: string format: messageId channel: - type: string - enum: - - time + $ref: "#/components/schemas/Channel" required: - $id - channel @@ -58,15 +56,102 @@ channels: type: string format: messageId channel: - type: string - enum: - - time + $ref: "#/components/schemas/Channel" token: $ref: "#/components/schemas/JWT" required: - $id - channel - token + + matchmaking: + title: Matchmaking + description: | + A Channel used to search for a match and + to receive one + messages: + MatchSetSearchState: + payload: + type: object + additionalProperties: false + properties: + $id: + type: string + format: messageId + searching: + type: boolean + required: + - $id + - searching + MatchFound: + payload: + type: object + additionalProperties: false + properties: + $id: + type: string + format: messageId + matchId: + type: string + created: + description: "Unix Timestamp describing when this Match was found" + type: integer + format: int64 + ttl: + description: "Time in Milliseconds, how long this Match is open for accepting" + type: integer + format: int64 + required: + - $id + - matchId + - created + - ttl + MatchAccepted: + payload: + type: object + additionalProperties: false + properties: + $id: + type: string + format: messageId + matchId: + type: string + accepted: + type: boolean + required: + - $id + - matchId + - accepted + MatchAborted: + payload: + type: object + additionalProperties: false + properties: + $id: + type: string + format: messageId + matchId: + type: string + required: + - $id + - matchId + MatchEstablished: + payload: + type: object + additionalProperties: false + properties: + $id: + type: string + format: messageId + matchId: + type: string + opponentName: + type: string + required: + - $id + - matchId + - opponentName + time: title: Time description: | @@ -102,6 +187,39 @@ operations: $ref: "#/channels/connection" messages: - $ref: "#/channels/connection/messages/ProvidedConnectionToken" + searchMatch: + title: SearchMatch + action: send + channel: + $ref: "#/channels/matchmaking" + messages: + - $ref: "#/channels/matchmaking/messages/MatchSetSearchState" + foundMatch: + title: FoundGame + action: receive + channel: + $ref: "#/channels/matchmaking" + messages: + - $ref: "#/channels/matchmaking/messages/MatchFound" + reply: + channel: + $ref: "#/channels/matchmaking" + messages: + - $ref: "#/channels/matchmaking/messages/MatchAccepted" + abortedMatch: + title: AbortedMatch + action: receive + channel: + $ref: "#/channels/matchmaking" + messages: + - $ref: "#/channels/matchmaking/messages/MatchAborted" + establishedMatch: + title: EstablishedMatch + action: receive + channel: + $ref: "#/channels/matchmaking" + messages: + - $ref: "#/channels/matchmaking/messages/MatchEstablished" updateTime: title: Updates of the current Unix Time action: receive @@ -124,3 +242,10 @@ components: JWT: type: string format: jwt + Channel: + type: string + enum: + - connection + - matchmaking + - time +