Compare commits
1 commit
0b93ef4203
...
831359eea9
Author | SHA1 | Date | |
---|---|---|---|
|
831359eea9 |
3 changed files with 69 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
||||||
|
package de.towerdefence.server.server.channels.match;
|
||||||
|
|
||||||
|
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 TimeMessage extends JsonMessage {
|
||||||
|
private final long time;
|
||||||
|
private final String matchId;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getMessageId() {
|
||||||
|
return "CurrentUnixTime";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, JsonNode> getData(JsonNodeFactory factory) {
|
||||||
|
return Map.of(
|
||||||
|
"time", factory.numberNode(this.time),
|
||||||
|
"matchId", factory.textNode(this.matchId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
17
ws/example/time_channel.sh
Executable file
17
ws/example/time_channel.sh
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
response=$(curl -s -X 'POST' \
|
||||||
|
'http://localhost:8080/api/v1/player/login' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"username": "Player1",
|
||||||
|
"password": "1234"
|
||||||
|
}')
|
||||||
|
|
||||||
|
token=$(echo "$response" | jq -r .token)
|
||||||
|
payload='{"$id": "RequestConnectionToken", "channel": "time"}'
|
||||||
|
response=$(echo "$payload" | websocat ws://localhost:8080/ws/connection -H "Authorization: $token")
|
||||||
|
|
||||||
|
time_token=$(echo "$response" | jq -r .token)
|
||||||
|
websocat ws://localhost:8080/ws/time -H "Authorization: $time_token"
|
25
ws/ws.yml
25
ws/ws.yml
|
@ -160,6 +160,24 @@ channels:
|
||||||
description: |
|
description: |
|
||||||
Channel for managing an active match
|
Channel for managing an active match
|
||||||
messages:
|
messages:
|
||||||
|
CurrentUnixTime:
|
||||||
|
description: The Current time in Unix Time
|
||||||
|
payload:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
$id:
|
||||||
|
type: string
|
||||||
|
format: messageId
|
||||||
|
time:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
matchId:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- $id
|
||||||
|
- time
|
||||||
|
- matchId
|
||||||
RequestTowerPlacing:
|
RequestTowerPlacing:
|
||||||
description: Requesting a placement of a tower
|
description: Requesting a placement of a tower
|
||||||
payload:
|
payload:
|
||||||
|
@ -292,6 +310,13 @@ operations:
|
||||||
$ref: "#/channels/matchmaking"
|
$ref: "#/channels/matchmaking"
|
||||||
messages:
|
messages:
|
||||||
- $ref: "#/channels/matchmaking/messages/MatchEstablished"
|
- $ref: "#/channels/matchmaking/messages/MatchEstablished"
|
||||||
|
matchUpdate:
|
||||||
|
title: MatchUpdate
|
||||||
|
action: receive
|
||||||
|
channel:
|
||||||
|
$ref: "#/channels/match"
|
||||||
|
messages:
|
||||||
|
- $ref: "#/channels/match/messages/CurrentUnixTime"
|
||||||
towerPlacing:
|
towerPlacing:
|
||||||
title: TowerPlacing
|
title: TowerPlacing
|
||||||
action: send
|
action: send
|
||||||
|
|
Loading…
Add table
Reference in a new issue