diff --git a/src/backend/autobeerpong/client.py b/src/backend/autobeerpong/client.py index 71e4d21..2c63063 100644 --- a/src/backend/autobeerpong/client.py +++ b/src/backend/autobeerpong/client.py @@ -2,7 +2,7 @@ import json from websockets.asyncio.server import ServerConnection -from autobeerpong.types.raw import MessageRaw_T, ClientRaw_T +from autobeerpong.types.raw import MessageRaw_T, ClientRaw_T, PlayerRaw_T from autobeerpong.states.client import ClientState @@ -21,6 +21,16 @@ class Client: return { "id": self.id, "name": self.name, + } + + def as_raw_player(self) -> PlayerRaw_T: + assert self.state is ClientState.PLAYER + + return { + "client": { + "id": self.id, + "name": self.name, + }, "ready": self.ready, } diff --git a/src/backend/autobeerpong/server.py b/src/backend/autobeerpong/server.py index a94d0fe..607c79c 100644 --- a/src/backend/autobeerpong/server.py +++ b/src/backend/autobeerpong/server.py @@ -43,7 +43,7 @@ class AutobeerpongServer: lobby_state_raw: MessageRaw_T = { "messageType": "lobbyState", "messageContent": { - "players": [player.as_raw() for player in players], + "players": [player.as_raw_player() for player in players], "spectators": [spectator.as_raw() for spectator in spectators], }, } diff --git a/src/backend/autobeerpong/types/raw.py b/src/backend/autobeerpong/types/raw.py index adf34f6..26b3a70 100644 --- a/src/backend/autobeerpong/types/raw.py +++ b/src/backend/autobeerpong/types/raw.py @@ -3,3 +3,4 @@ from typing import Any _Raw_T = dict[str, Any] MessageRaw_T = _Raw_T ClientRaw_T = _Raw_T +PlayerRaw_T = _Raw_T diff --git a/src/backend/tests/test_lobby.py b/src/backend/tests/test_lobby.py index db9d7cb..6763402 100644 --- a/src/backend/tests/test_lobby.py +++ b/src/backend/tests/test_lobby.py @@ -46,7 +46,7 @@ class TestLobby(IsolatedAsyncioTestCase): self.assertEqual(response["messageType"], "lobbyState") self.assertEqual(len(response["messageContent"]["players"]), 2) - player_names = [p["name"] for p in response["messageContent"]["players"]] + player_names = [p["client"]["name"] for p in response["messageContent"]["players"]] self.assertIn("Ruedi", player_names) self.assertIn("Hansi", player_names) @@ -92,9 +92,9 @@ class TestLobby(IsolatedAsyncioTestCase): players = response["messageContent"]["players"] for player in players: - if player["name"] == "Ruedi": + if player["client"]["name"] == "Ruedi": self.assertEqual(player["ready"], True) - elif player["name"] == "Hansi": + elif player["client"]["name"] == "Hansi": self.assertEqual(player["ready"], False) self.assertEqual(client_a_responses[3], client_b_responses[2]) @@ -104,9 +104,9 @@ class TestLobby(IsolatedAsyncioTestCase): players = response["messageContent"]["players"] for player in players: - if player["name"] == "Ruedi": + if player["client"]["name"] == "Ruedi": self.assertEqual(player["ready"], True) - elif player["name"] == "Hansi": + elif player["client"]["name"] == "Hansi": self.assertEqual(player["ready"], True) self.assertEqual(client_a_responses[4], client_b_responses[3]) diff --git a/src/frontend/src/Connection.ts b/src/frontend/src/Connection.ts index 2824a0c..8010d99 100644 --- a/src/frontend/src/Connection.ts +++ b/src/frontend/src/Connection.ts @@ -11,28 +11,32 @@ import { BaseSocket, MessageEvent } from "./sockets/BaseSocket"; import { MockSocket } from "./sockets/MockSocket"; import { Socket } from "./sockets/Socket"; -type Action = "join" | "rejoin" | "toggleRole" | "toggleReady"; +type MessageType = "join" | "rejoin" | "toggleRole" | "toggleReady"; interface Request { - action: Action; + messageType: MessageType; } interface JoinRequest { - action: "join"; - name: string; + messageType: "join"; + messageContent: { + name: string; + }; } interface RejoinRequest { - action: "rejoin"; - id: Id; + messageType: "rejoin"; + messageContent: { + id: Id; + }; } interface ToggleRoleRequest { - action: "toggleRole"; + messageType: "toggleRole"; } interface ToggleReadyRequest { - action: "toggleReady"; + messageType: "toggleReady"; } export class LobbyMessageEvent extends Event { @@ -92,7 +96,7 @@ export class Connection extends Evented { const messageObject = JSON.parse(message.json); if (this._waitForJoin) { - this._client = messageObject.player as Client; + this._client = messageObject.messageContent.client as Client; storeClient(this._client); this._waitForJoin = false; this.emit("joined", new JoinedEvent()); @@ -106,21 +110,17 @@ export class Connection extends Evented { return; } - switch (messageObject.state.stateType) { - case "lobby": + switch (messageObject.messageType) { + case "lobbyState": this.emit( "lobby-message", - new LobbyMessageEvent( - new LobbyState(messageObject.state, this._client), - ), + new LobbyMessageEvent(new LobbyState(messageObject, this._client)), ); break; - case "match": + case "matchState": this.emit( "match-message", - new MatchMessageEvent( - new MatchState(messageObject.state, this._client), - ), + new MatchMessageEvent(new MatchState(messageObject, this._client)), ); } } @@ -165,8 +165,10 @@ export class Connection extends Evented { join(name: string): void { const joinRequest = { - action: "join", - name, + messageType: "join", + messageContent: { + name, + }, } as JoinRequest; this._waitForJoin = true; @@ -175,8 +177,8 @@ export class Connection extends Evented { rejoin(id: Id): void { const rejoinRequest = { - action: "rejoin", - id, + messageType: "rejoin", + messageContent: { id }, } as RejoinRequest; this._waitForJoin = true; @@ -185,7 +187,7 @@ export class Connection extends Evented { toggleRole(): void { const toggleRoleRequest = { - action: "toggleRole", + messageType: "toggleRole", } as ToggleRoleRequest; this._send(toggleRoleRequest); @@ -193,7 +195,7 @@ export class Connection extends Evented { toggleReady(): void { const toggleReadyRequest = { - action: "toggleReady", + messageType: "toggleReady", } as ToggleReadyRequest; this._send(toggleReadyRequest); diff --git a/src/frontend/src/LobbyState.ts b/src/frontend/src/LobbyState.ts index ddd1520..f2b8be9 100644 --- a/src/frontend/src/LobbyState.ts +++ b/src/frontend/src/LobbyState.ts @@ -4,6 +4,7 @@ import { Id, Player, Spectator, + getClient, } from "./jsonTypes"; import { maxPlayers } from "./main"; import { log } from "./utils/debugUtils"; @@ -33,11 +34,11 @@ export class LobbyState { } get players(): Player[] { - return this.lobbyStateRaw.players; + return this.lobbyStateRaw.messageContent.players; } get spectators(): Spectator[] { - return this.lobbyStateRaw.spectators; + return this.lobbyStateRaw.messageContent.spectators; } get isFull(): boolean { @@ -53,7 +54,7 @@ export class LobbyState { } get isSpectator(): boolean { - return this.spectators.map((p) => p.client.id).includes(this.client.id); + return this.spectators.map((p) => getClient(p).id).includes(this.client.id); } getPlayerById(id: Id): Player | undefined { @@ -61,6 +62,6 @@ export class LobbyState { } getSpectatorById(id: Id): Spectator | undefined { - return this.spectators.find((p) => p.client.id === id); + return this.spectators.find((p) => getClient(p).id === id); } } diff --git a/src/frontend/src/ScreenElements/ClientListScreenElement.ts b/src/frontend/src/ScreenElements/ClientListScreenElement.ts index ada3172..4dd755b 100644 --- a/src/frontend/src/ScreenElements/ClientListScreenElement.ts +++ b/src/frontend/src/ScreenElements/ClientListScreenElement.ts @@ -3,7 +3,7 @@ import * as ex from "excalibur"; import { spacingS } from "../utils/formattingUtils"; import { headingFont, paragraphFont } from "../utils/fontUtil"; import { Text } from "./Text"; -import { Client, Player, Spectator } from "../jsonTypes"; +import { Client, getClient, Player, Spectator } from "../jsonTypes"; const clientColor = ex.Color.fromHex("40E0D0"); @@ -51,7 +51,7 @@ export class ClientListScreenElement extends ex.ScreenElement { let y = headingFont.size + spacingS; for (const currentClient of this._clients) { - const isClient = currentClient.client.id === this._client?.id; + const isClient = getClient(currentClient).id === this._client?.id; const label = this.createLabel(currentClient, y, isClient); y += label.font.size + spacingS; @@ -77,7 +77,7 @@ export class ClientListScreenElement extends ex.ScreenElement { isClient: boolean, ): Text { const color = isClient ? clientColor : undefined; - const { name } = client.client; + const { name } = getClient(client); const label = new Text({ text: name, font: paragraphFont, diff --git a/src/frontend/src/jsonTypes.ts b/src/frontend/src/jsonTypes.ts index 5d510a5..809363b 100644 --- a/src/frontend/src/jsonTypes.ts +++ b/src/frontend/src/jsonTypes.ts @@ -1,13 +1,13 @@ export type Id = number; -export interface MessageRaw { - state: LobbyStateRaw | MatchStateRaw; -} +export type MessageRaw = LobbyStateRaw | MatchStateRaw; export interface LobbyStateRaw { - stateType: "lobby"; - players: Player[]; - spectators: Spectator[]; + messageType: "lobbyState"; + messageContent: { + players: Player[]; + spectators: Spectator[]; + }; } export type LobbyStateRawReadonly = Readonly; @@ -17,9 +17,7 @@ export interface Player { ready: boolean; } -export interface Spectator { - client: Client; -} +export type Spectator = Client; export interface Client { id: Id; @@ -27,8 +25,10 @@ export interface Client { } export interface MatchStateRaw { - stateType: "match"; - history: (Table | Action)[]; + messageType: "matchState"; + messageContent: { + history: (Table | Action)[]; + }; } export type MatchStateRawReadonly = Readonly; @@ -52,3 +52,9 @@ export interface Parabola { } export type Vector2 = [number, number]; + +export function getClient(playerOrSpectator: Player | Spectator): Client { + return "client" in playerOrSpectator + ? playerOrSpectator.client + : playerOrSpectator; +} diff --git a/src/frontend/src/schemaValidators.ts b/src/frontend/src/schemaValidators.ts index 0205987..cbff554 100644 --- a/src/frontend/src/schemaValidators.ts +++ b/src/frontend/src/schemaValidators.ts @@ -1,25 +1,36 @@ -import Ajv, { ValidateFunction } from "ajv"; +import Ajv, { ValidateFunction } from "ajv/dist/2020"; import { log } from "./utils/debugUtils"; import { Client, MessageRaw } from "./jsonTypes"; -import messageSchemaFile from "../../schema/message_schema.json"; -import clientSchemaFile from "../../schema/client_schema.json"; -import lobbyStateSchemaFile from "../../schema/lobby_state_schema.json"; -import matchStateSchemaFile from "../../schema/match_state_schema.json"; -import actionSchemaFile from "../../schema/action_schema.json"; -import playerSchemaFile from "../../schema/player_schema.json"; -import spectatorSchemaFile from "../../schema/spectator_schema.json"; -import tableSchemaFile from "../../schema/table_schema.json"; +import messageSchemaFile from "../../schema/message.json"; + +import clientSchemaFile from "../../schema/common/client.json"; +import playerSchemaFile from "../../schema/common/player.json"; + +import joinSchemaFile from "../../schema/lobby/join.json"; +import joinResponseSchemaFile from "../../schema/lobby/join_response.json"; +import rejoinSchemaFile from "../../schema/lobby/rejoin.json"; +import lobbyStateSchemaFile from "../../schema/lobby/state.json"; +import toggleReadySchemaFile from "../../schema/lobby/toggle_ready.json"; +import toggleRoleSchemaFile from "../../schema/lobby/toggle_role.json"; + +// import matchStateSchemaFile from "../../schema//match/state.json"; +// import actionSchemaFile from "../../schema/match/action.json"; +// import tableSchemaFile from "../../schema/match/table_schema.json"; const ajv = new Ajv({ strict: true }); -ajv.addSchema(lobbyStateSchemaFile, "lobby_state_schema.json"); -ajv.addSchema(matchStateSchemaFile, "match_state_schema.json"); -ajv.addSchema(actionSchemaFile, "action_schema.json"); -ajv.addSchema(clientSchemaFile, "client_schema.json"); -ajv.addSchema(playerSchemaFile, "player_schema.json"); -ajv.addSchema(spectatorSchemaFile, "spectator_schema.json"); -ajv.addSchema(tableSchemaFile, "table_schema.json"); +ajv.addSchema(clientSchemaFile, "client.json"); +ajv.addSchema(playerSchemaFile, "player.json"); + +ajv.addSchema(joinSchemaFile, "join.json"); +ajv.addSchema(joinResponseSchemaFile, "join_response.json"); +ajv.addSchema(rejoinSchemaFile, "rejoin.json"); +ajv.addSchema(lobbyStateSchemaFile, "state.json"); +ajv.addSchema(toggleReadySchemaFile, "toggle_ready.json"); +ajv.addSchema(toggleRoleSchemaFile, "toggle_role.json"); + +// TODO: Match schemas const validateMessage = ajv.compile(messageSchemaFile); const validateClient = ajv.compile(clientSchemaFile); diff --git a/src/frontend/src/sockets/MockSocket.ts b/src/frontend/src/sockets/MockSocket.ts index 5f02fe6..b858a0d 100644 --- a/src/frontend/src/sockets/MockSocket.ts +++ b/src/frontend/src/sockets/MockSocket.ts @@ -29,16 +29,16 @@ export class MockSocket export function mockLobbyMessage(): string { const lobbyUpdate = { - state: { - stateType: "lobby", + messageType: "lobbyState", + messageContent: { players: [ { client: { name: "Dubbel", id: 0 }, ready: true }, { client: { name: "Yeah", id: 1 }, ready: false }, ], spectators: [ - { client: { name: "Dubbel", id: 2 } }, - { client: { name: "Cocksucker", id: 3 } }, - { client: { name: "Cocksucker 2", id: 4 } }, + { name: "Dubbel", id: 2 }, + { name: "Cocksucker", id: 3 }, + { name: "Cocksucker 2", id: 4 }, ], }, }; diff --git a/src/schema/archive/action_schema.json b/src/schema/archive/action_schema.json index 00da8c1..882940f 100644 --- a/src/schema/archive/action_schema.json +++ b/src/schema/archive/action_schema.json @@ -1,29 +1,47 @@ { - "title": "Action", - "type": "object", - "properties": { - "parabola": { "$ref": "#/$defs/parabola" }, - "turn": { "$ref": "#/$defs/turn" } - }, - "required": ["parabola", "turn"], - "additionalProperties": false, - "$defs": { - "turn": { - "enum": ["a", "b"] + "title": "Action", + "type": "object", + "properties": { + "parabola": { + "$ref": "#/$defs/parabola" + }, + "turn": { + "$ref": "#/$defs/turn" + } }, - "parabola": { - "type": "object", - "properties": { - "startPosition": { "$ref": "#/$defs/vector2" }, - "startVelocity": { "$ref": "#/$defs/vector2" }, - "stopTime": { "type": "number" } - } - }, - "vector2": { - "type": "array", - "items": { "type": "number" }, - "minItems": 2, - "maxItems": 2 + "required": [ + "parabola", + "turn" + ], + "additionalProperties": false, + "$defs": { + "turn": { + "enum": [ + "a", + "b" + ] + }, + "parabola": { + "type": "object", + "properties": { + "startPosition": { + "$ref": "#/$defs/vector2" + }, + "startVelocity": { + "$ref": "#/$defs/vector2" + }, + "stopTime": { + "type": "number" + } + } + }, + "vector2": { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 2, + "maxItems": 2 + } } - } -} +} \ No newline at end of file diff --git a/src/schema/archive/client_schema.json b/src/schema/archive/client_schema.json index 28b6307..f9c4dc5 100644 --- a/src/schema/archive/client_schema.json +++ b/src/schema/archive/client_schema.json @@ -1,18 +1,18 @@ { - "title": "Client", - "type": "object", - "properties": { - "id": { - "type": "number", - "minimum": 0 + "title": "Client", + "type": "object", + "properties": { + "id": { + "type": "number", + "minimum": 0 + }, + "name": { + "type": "string" + } }, - "name": { - "type": "string" - } - }, - "required": [ - "id", - "name" - ], - "additionalProperties": false + "required": [ + "id", + "name" + ], + "additionalProperties": false } \ No newline at end of file diff --git a/src/schema/archive/join_message_schema.json b/src/schema/archive/join_message_schema.json index 23a14bc..1b1bc77 100644 --- a/src/schema/archive/join_message_schema.json +++ b/src/schema/archive/join_message_schema.json @@ -1,17 +1,17 @@ { - "title": "JoinMessage", - "type": "object", - "properties": { - "type": { - "type": "string" + "title": "JoinMessage", + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "name": { + "type": "string" + } }, - "name": { - "type": "string" - } - }, - "required": [ - "type", - "name" - ], - "additionalProperties": false + "required": [ + "type", + "name" + ], + "additionalProperties": false } \ No newline at end of file diff --git a/src/schema/archive/lobby_state_schema.json b/src/schema/archive/lobby_state_schema.json index 832b0a2..928bbd8 100644 --- a/src/schema/archive/lobby_state_schema.json +++ b/src/schema/archive/lobby_state_schema.json @@ -1,29 +1,29 @@ { - "title": "LobbyState", - "type": "object", - "properties": { - "stateType": { - "enum": [ - "lobby" - ] + "title": "LobbyState", + "type": "object", + "properties": { + "stateType": { + "enum": [ + "lobby" + ] + }, + "players": { + "type": "array", + "items": { + "$ref": "file://localhost/./player_schema.json" + } + }, + "spectators": { + "type": "array", + "items": { + "$ref": "./spectator_schema.json" + } + } }, - "players": { - "type": "array", - "items": { - "$ref": "file://localhost/./player_schema.json" - } - }, - "spectators": { - "type": "array", - "items": { - "$ref": "./spectator_schema.json" - } - } - }, - "required": [ - "stateType", - "players", - "spectators" - ], - "additionalProperties": false + "required": [ + "stateType", + "players", + "spectators" + ], + "additionalProperties": false } \ No newline at end of file diff --git a/src/schema/archive/match_state_schema.json b/src/schema/archive/match_state_schema.json index 4379975..0d0ef9b 100644 --- a/src/schema/archive/match_state_schema.json +++ b/src/schema/archive/match_state_schema.json @@ -1,18 +1,29 @@ { - "title": "MatchState", - "type": "object", - "properties": { - "stateType": { "enum": ["match"]}, - "history": { - "type": "array", - "items": { - "anyOf": [ - { "$ref": "./table_schema.json" }, - { "$ref": "./action_schema.json" } + "title": "MatchState", + "type": "object", + "properties": { + "stateType": { + "enum": [ + "match" ] + }, + "history": { + "type": "array", + "items": { + "anyOf": [ + { + "$ref": "./table_schema.json" + }, + { + "$ref": "./action_schema.json" + } + ] + } } - } - }, - "required": ["stateType", "history"], - "additionalProperties": false -} + }, + "required": [ + "stateType", + "history" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/src/schema/archive/message_schema.json b/src/schema/archive/message_schema.json index 718da3c..a3966d7 100644 --- a/src/schema/archive/message_schema.json +++ b/src/schema/archive/message_schema.json @@ -1,20 +1,20 @@ { - "title": "Message", - "type": "object", - "properties": { - "state": { - "anyOf": [ - { - "$ref": "./lobby_state_schema.json" - }, - { - "$ref": "./match_state_schema.json" + "title": "Message", + "type": "object", + "properties": { + "state": { + "anyOf": [ + { + "$ref": "./lobby_state_schema.json" + }, + { + "$ref": "./match_state_schema.json" + } + ] } - ] - } - }, - "required": [ - "state" - ], - "additionalProperties": false + }, + "required": [ + "state" + ], + "additionalProperties": false } \ No newline at end of file diff --git a/src/schema/archive/player_schema.json b/src/schema/archive/player_schema.json index 63601c6..30c80d4 100644 --- a/src/schema/archive/player_schema.json +++ b/src/schema/archive/player_schema.json @@ -1,14 +1,17 @@ { - "title": "Player", - "type": "object", - "properties": { - "client": { - "$ref": "./client_schema.json" + "title": "Player", + "type": "object", + "properties": { + "client": { + "$ref": "./client_schema.json" + }, + "ready": { + "type": "boolean" + } }, - "ready": { - "type": "boolean" - } - }, - "required": ["client", "ready"], - "additionalProperties": false -} + "required": [ + "client", + "ready" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/src/schema/archive/spectator_schema.json b/src/schema/archive/spectator_schema.json index 4fe7531..5ba4056 100644 --- a/src/schema/archive/spectator_schema.json +++ b/src/schema/archive/spectator_schema.json @@ -1,11 +1,13 @@ { - "title": "Spectator", - "type": "object", - "properties": { - "client": { - "$ref": "./client_schema.json" - } - }, - "required": ["client"], - "additionalProperties": false -} + "title": "Spectator", + "type": "object", + "properties": { + "client": { + "$ref": "./client_schema.json" + } + }, + "required": [ + "client" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/src/schema/archive/table_schema.json b/src/schema/archive/table_schema.json index 5565c20..1f7ecaf 100644 --- a/src/schema/archive/table_schema.json +++ b/src/schema/archive/table_schema.json @@ -1,26 +1,43 @@ { - "title": "Table", - "type": "object", - "properties": { - "cupsA": { "$ref": "#/$defs/cups" }, - "cupsB": { "$ref": "#/$defs/cups" }, - "teamA": { "$ref": "#/$defs/team" }, - "teamB": { "$ref": "#/$defs/team" } - }, - "required": ["cupsA", "cupsB", "teamA", "teamB"], - "additionalProperties": false, - "$defs": { - "cups": { - "type": "array", - "items": { "type": "boolean" }, - "minItems": 3, - "maxItems": 3 + "title": "Table", + "type": "object", + "properties": { + "cupsA": { + "$ref": "#/$defs/cups" + }, + "cupsB": { + "$ref": "#/$defs/cups" + }, + "teamA": { + "$ref": "#/$defs/team" + }, + "teamB": { + "$ref": "#/$defs/team" + } }, - "team": { - "type": "array", - "items": { "type": "number" }, - "minItems": 3, - "maxItems": 3 + "required": [ + "cupsA", + "cupsB", + "teamA", + "teamB" + ], + "additionalProperties": false, + "$defs": { + "cups": { + "type": "array", + "items": { + "type": "boolean" + }, + "minItems": 3, + "maxItems": 3 + }, + "team": { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 3, + "maxItems": 3 + } } - } -} +} \ No newline at end of file diff --git a/src/schema/common/client.json b/src/schema/common/client.json index 7379a4e..d73568d 100644 --- a/src/schema/common/client.json +++ b/src/schema/common/client.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "schema:client", + "$id": "http://localhost/common/client.json", "title": "Client", "type": "object", "properties": { @@ -10,15 +10,11 @@ }, "name": { "type": "string" - }, - "ready": { - "type": "boolean" } }, "required": [ "id", - "name", - "ready" + "name" ], "additionalProperties": false } \ No newline at end of file diff --git a/src/schema/common/player.json b/src/schema/common/player.json new file mode 100644 index 0000000..e85fc26 --- /dev/null +++ b/src/schema/common/player.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost/common/player.json", + "title": "Player", + "type": "object", + "properties": { + "client": { + "$ref": "./client.json" + }, + "ready": { + "type": "boolean" + } + }, + "required": [ + "client", + "ready" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/src/schema/lobby/join.json b/src/schema/lobby/join.json index df4562a..6e7ce23 100644 --- a/src/schema/lobby/join.json +++ b/src/schema/lobby/join.json @@ -1,4 +1,6 @@ { + "$id": "http://localhost/lobby/join.json", + "type": "object", "properties": { "messageType": { "const": "join" diff --git a/src/schema/lobby/join_response.json b/src/schema/lobby/join_response.json index bcba06c..b466671 100644 --- a/src/schema/lobby/join_response.json +++ b/src/schema/lobby/join_response.json @@ -1,4 +1,6 @@ { + "$id": "http://localhost/lobby/join_response.json", + "type": "object", "properties": { "messageType": { "const": "joinResponse" diff --git a/src/schema/lobby/rejoin.json b/src/schema/lobby/rejoin.json index 70d374a..612c53d 100644 --- a/src/schema/lobby/rejoin.json +++ b/src/schema/lobby/rejoin.json @@ -1,4 +1,6 @@ { + "$id": "http://localhost/lobby/rejoin.json", + "type": "object", "properties": { "messageType": { "const": "rejoin" diff --git a/src/schema/lobby/state.json b/src/schema/lobby/state.json index 30a1437..0c92d5b 100644 --- a/src/schema/lobby/state.json +++ b/src/schema/lobby/state.json @@ -1,19 +1,24 @@ { + "$id": "http://localhost/lobby/state.json", + "type": "object", "properties": { "messageType": { "const": "lobbyState" }, "messageContent": { - "players": { - "type": "array", - "items": { - "$ref": "../common/client.json" - } - }, - "spectators": { - "type": "array", - "items": { - "$ref": "../common/client.json" + "type": "object", + "properties": { + "players": { + "type": "array", + "items": { + "$ref": "../common/player.json" + } + }, + "spectators": { + "type": "array", + "items": { + "$ref": "../common/client.json" + } } } } diff --git a/src/schema/lobby/toggle_ready.json b/src/schema/lobby/toggle_ready.json index 8428443..1fec7f6 100644 --- a/src/schema/lobby/toggle_ready.json +++ b/src/schema/lobby/toggle_ready.json @@ -1,4 +1,6 @@ { + "$id": "http://localhost/lobby/toggle_ready.json", + "type": "object", "properties": { "messageType": { "const": "toggleReady" diff --git a/src/schema/lobby/toggle_role.json b/src/schema/lobby/toggle_role.json index 1c34b1d..74a775a 100644 --- a/src/schema/lobby/toggle_role.json +++ b/src/schema/lobby/toggle_role.json @@ -1,4 +1,6 @@ { + "$id": "http://localhost/lobby/toggle_role.json", + "type": "object", "properties": { "messageType": { "const": "toggleRole" diff --git a/src/schema/message.json b/src/schema/message.json index 6cff4d7..968da2c 100644 --- a/src/schema/message.json +++ b/src/schema/message.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "schema:message", + "$id": "http://localhost/message.json", "title": "Message", "type": "object", "properties": {