Move ready outside client into player and fix frontend schema validation (#39)
This commit is contained in:
1 parent
d88fb1d6f9
commit
1ea5786ecd
28 files changed
+357
-245
No files matched your search
@@ -2,7 +2,7 @@ import json
|
|||||||
|
|
||||||
from websockets.asyncio.server import ServerConnection
|
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
|
from autobeerpong.states.client import ClientState
|
||||||
|
|
||||||
|
|
||||||
@@ -21,6 +21,16 @@ class Client:
|
|||||||
return {
|
return {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
"name": self.name,
|
"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,
|
"ready": self.ready,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class AutobeerpongServer:
|
|||||||
lobby_state_raw: MessageRaw_T = {
|
lobby_state_raw: MessageRaw_T = {
|
||||||
"messageType": "lobbyState",
|
"messageType": "lobbyState",
|
||||||
"messageContent": {
|
"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],
|
"spectators": [spectator.as_raw() for spectator in spectators],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ from typing import Any
|
|||||||
_Raw_T = dict[str, Any]
|
_Raw_T = dict[str, Any]
|
||||||
MessageRaw_T = _Raw_T
|
MessageRaw_T = _Raw_T
|
||||||
ClientRaw_T = _Raw_T
|
ClientRaw_T = _Raw_T
|
||||||
|
PlayerRaw_T = _Raw_T
|
||||||
@@ -46,7 +46,7 @@ class TestLobby(IsolatedAsyncioTestCase):
|
|||||||
self.assertEqual(response["messageType"], "lobbyState")
|
self.assertEqual(response["messageType"], "lobbyState")
|
||||||
self.assertEqual(len(response["messageContent"]["players"]), 2)
|
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("Ruedi", player_names)
|
||||||
self.assertIn("Hansi", player_names)
|
self.assertIn("Hansi", player_names)
|
||||||
@@ -92,9 +92,9 @@ class TestLobby(IsolatedAsyncioTestCase):
|
|||||||
players = response["messageContent"]["players"]
|
players = response["messageContent"]["players"]
|
||||||
|
|
||||||
for player in players:
|
for player in players:
|
||||||
if player["name"] == "Ruedi":
|
if player["client"]["name"] == "Ruedi":
|
||||||
self.assertEqual(player["ready"], True)
|
self.assertEqual(player["ready"], True)
|
||||||
elif player["name"] == "Hansi":
|
elif player["client"]["name"] == "Hansi":
|
||||||
self.assertEqual(player["ready"], False)
|
self.assertEqual(player["ready"], False)
|
||||||
|
|
||||||
self.assertEqual(client_a_responses[3], client_b_responses[2])
|
self.assertEqual(client_a_responses[3], client_b_responses[2])
|
||||||
@@ -104,9 +104,9 @@ class TestLobby(IsolatedAsyncioTestCase):
|
|||||||
players = response["messageContent"]["players"]
|
players = response["messageContent"]["players"]
|
||||||
|
|
||||||
for player in players:
|
for player in players:
|
||||||
if player["name"] == "Ruedi":
|
if player["client"]["name"] == "Ruedi":
|
||||||
self.assertEqual(player["ready"], True)
|
self.assertEqual(player["ready"], True)
|
||||||
elif player["name"] == "Hansi":
|
elif player["client"]["name"] == "Hansi":
|
||||||
self.assertEqual(player["ready"], True)
|
self.assertEqual(player["ready"], True)
|
||||||
|
|
||||||
self.assertEqual(client_a_responses[4], client_b_responses[3])
|
self.assertEqual(client_a_responses[4], client_b_responses[3])
|
||||||
|
|||||||
@@ -11,28 +11,32 @@ import { BaseSocket, MessageEvent } from "./sockets/BaseSocket";
|
|||||||
import { MockSocket } from "./sockets/MockSocket";
|
import { MockSocket } from "./sockets/MockSocket";
|
||||||
import { Socket } from "./sockets/Socket";
|
import { Socket } from "./sockets/Socket";
|
||||||
|
|
||||||
type Action = "join" | "rejoin" | "toggleRole" | "toggleReady";
|
type MessageType = "join" | "rejoin" | "toggleRole" | "toggleReady";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
action: Action;
|
messageType: MessageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JoinRequest {
|
interface JoinRequest {
|
||||||
action: "join";
|
messageType: "join";
|
||||||
name: string;
|
messageContent: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RejoinRequest {
|
interface RejoinRequest {
|
||||||
action: "rejoin";
|
messageType: "rejoin";
|
||||||
id: Id;
|
messageContent: {
|
||||||
|
id: Id;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ToggleRoleRequest {
|
interface ToggleRoleRequest {
|
||||||
action: "toggleRole";
|
messageType: "toggleRole";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ToggleReadyRequest {
|
interface ToggleReadyRequest {
|
||||||
action: "toggleReady";
|
messageType: "toggleReady";
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LobbyMessageEvent extends Event {
|
export class LobbyMessageEvent extends Event {
|
||||||
@@ -92,7 +96,7 @@ export class Connection extends Evented<typeof ConnectionEvents> {
|
|||||||
const messageObject = JSON.parse(message.json);
|
const messageObject = JSON.parse(message.json);
|
||||||
|
|
||||||
if (this._waitForJoin) {
|
if (this._waitForJoin) {
|
||||||
this._client = messageObject.player as Client;
|
this._client = messageObject.messageContent.client as Client;
|
||||||
storeClient(this._client);
|
storeClient(this._client);
|
||||||
this._waitForJoin = false;
|
this._waitForJoin = false;
|
||||||
this.emit("joined", new JoinedEvent());
|
this.emit("joined", new JoinedEvent());
|
||||||
@@ -106,21 +110,17 @@ export class Connection extends Evented<typeof ConnectionEvents> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (messageObject.state.stateType) {
|
switch (messageObject.messageType) {
|
||||||
case "lobby":
|
case "lobbyState":
|
||||||
this.emit(
|
this.emit(
|
||||||
"lobby-message",
|
"lobby-message",
|
||||||
new LobbyMessageEvent(
|
new LobbyMessageEvent(new LobbyState(messageObject, this._client)),
|
||||||
new LobbyState(messageObject.state, this._client),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "match":
|
case "matchState":
|
||||||
this.emit(
|
this.emit(
|
||||||
"match-message",
|
"match-message",
|
||||||
new MatchMessageEvent(
|
new MatchMessageEvent(new MatchState(messageObject, this._client)),
|
||||||
new MatchState(messageObject.state, this._client),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,8 +165,10 @@ export class Connection extends Evented<typeof ConnectionEvents> {
|
|||||||
|
|
||||||
join(name: string): void {
|
join(name: string): void {
|
||||||
const joinRequest = {
|
const joinRequest = {
|
||||||
action: "join",
|
messageType: "join",
|
||||||
name,
|
messageContent: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
} as JoinRequest;
|
} as JoinRequest;
|
||||||
|
|
||||||
this._waitForJoin = true;
|
this._waitForJoin = true;
|
||||||
@@ -175,8 +177,8 @@ export class Connection extends Evented<typeof ConnectionEvents> {
|
|||||||
|
|
||||||
rejoin(id: Id): void {
|
rejoin(id: Id): void {
|
||||||
const rejoinRequest = {
|
const rejoinRequest = {
|
||||||
action: "rejoin",
|
messageType: "rejoin",
|
||||||
id,
|
messageContent: { id },
|
||||||
} as RejoinRequest;
|
} as RejoinRequest;
|
||||||
|
|
||||||
this._waitForJoin = true;
|
this._waitForJoin = true;
|
||||||
@@ -185,7 +187,7 @@ export class Connection extends Evented<typeof ConnectionEvents> {
|
|||||||
|
|
||||||
toggleRole(): void {
|
toggleRole(): void {
|
||||||
const toggleRoleRequest = {
|
const toggleRoleRequest = {
|
||||||
action: "toggleRole",
|
messageType: "toggleRole",
|
||||||
} as ToggleRoleRequest;
|
} as ToggleRoleRequest;
|
||||||
|
|
||||||
this._send(toggleRoleRequest);
|
this._send(toggleRoleRequest);
|
||||||
@@ -193,7 +195,7 @@ export class Connection extends Evented<typeof ConnectionEvents> {
|
|||||||
|
|
||||||
toggleReady(): void {
|
toggleReady(): void {
|
||||||
const toggleReadyRequest = {
|
const toggleReadyRequest = {
|
||||||
action: "toggleReady",
|
messageType: "toggleReady",
|
||||||
} as ToggleReadyRequest;
|
} as ToggleReadyRequest;
|
||||||
|
|
||||||
this._send(toggleReadyRequest);
|
this._send(toggleReadyRequest);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
Id,
|
Id,
|
||||||
Player,
|
Player,
|
||||||
Spectator,
|
Spectator,
|
||||||
|
getClient,
|
||||||
} from "./jsonTypes";
|
} from "./jsonTypes";
|
||||||
import { maxPlayers } from "./main";
|
import { maxPlayers } from "./main";
|
||||||
import { log } from "./utils/debugUtils";
|
import { log } from "./utils/debugUtils";
|
||||||
@@ -33,11 +34,11 @@ export class LobbyState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get players(): Player[] {
|
get players(): Player[] {
|
||||||
return this.lobbyStateRaw.players;
|
return this.lobbyStateRaw.messageContent.players;
|
||||||
}
|
}
|
||||||
|
|
||||||
get spectators(): Spectator[] {
|
get spectators(): Spectator[] {
|
||||||
return this.lobbyStateRaw.spectators;
|
return this.lobbyStateRaw.messageContent.spectators;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isFull(): boolean {
|
get isFull(): boolean {
|
||||||
@@ -53,7 +54,7 @@ export class LobbyState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get isSpectator(): boolean {
|
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 {
|
getPlayerById(id: Id): Player | undefined {
|
||||||
@@ -61,6 +62,6 @@ export class LobbyState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSpectatorById(id: Id): Spectator | undefined {
|
getSpectatorById(id: Id): Spectator | undefined {
|
||||||
return this.spectators.find((p) => p.client.id === id);
|
return this.spectators.find((p) => getClient(p).id === id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import * as ex from "excalibur";
|
|||||||
import { spacingS } from "../utils/formattingUtils";
|
import { spacingS } from "../utils/formattingUtils";
|
||||||
import { headingFont, paragraphFont } from "../utils/fontUtil";
|
import { headingFont, paragraphFont } from "../utils/fontUtil";
|
||||||
import { Text } from "./Text";
|
import { Text } from "./Text";
|
||||||
import { Client, Player, Spectator } from "../jsonTypes";
|
import { Client, getClient, Player, Spectator } from "../jsonTypes";
|
||||||
|
|
||||||
const clientColor = ex.Color.fromHex("40E0D0");
|
const clientColor = ex.Color.fromHex("40E0D0");
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ export class ClientListScreenElement extends ex.ScreenElement {
|
|||||||
let y = headingFont.size + spacingS;
|
let y = headingFont.size + spacingS;
|
||||||
|
|
||||||
for (const currentClient of this._clients) {
|
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);
|
const label = this.createLabel(currentClient, y, isClient);
|
||||||
|
|
||||||
y += label.font.size + spacingS;
|
y += label.font.size + spacingS;
|
||||||
@@ -77,7 +77,7 @@ export class ClientListScreenElement extends ex.ScreenElement {
|
|||||||
isClient: boolean,
|
isClient: boolean,
|
||||||
): Text {
|
): Text {
|
||||||
const color = isClient ? clientColor : undefined;
|
const color = isClient ? clientColor : undefined;
|
||||||
const { name } = client.client;
|
const { name } = getClient(client);
|
||||||
const label = new Text({
|
const label = new Text({
|
||||||
text: name,
|
text: name,
|
||||||
font: paragraphFont,
|
font: paragraphFont,
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
export type Id = number;
|
export type Id = number;
|
||||||
|
|
||||||
export interface MessageRaw {
|
export type MessageRaw = LobbyStateRaw | MatchStateRaw;
|
||||||
state: LobbyStateRaw | MatchStateRaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LobbyStateRaw {
|
export interface LobbyStateRaw {
|
||||||
stateType: "lobby";
|
messageType: "lobbyState";
|
||||||
players: Player[];
|
messageContent: {
|
||||||
spectators: Spectator[];
|
players: Player[];
|
||||||
|
spectators: Spectator[];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LobbyStateRawReadonly = Readonly<LobbyStateRaw>;
|
export type LobbyStateRawReadonly = Readonly<LobbyStateRaw>;
|
||||||
@@ -17,9 +17,7 @@ export interface Player {
|
|||||||
ready: boolean;
|
ready: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Spectator {
|
export type Spectator = Client;
|
||||||
client: Client;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Client {
|
export interface Client {
|
||||||
id: Id;
|
id: Id;
|
||||||
@@ -27,8 +25,10 @@ export interface Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MatchStateRaw {
|
export interface MatchStateRaw {
|
||||||
stateType: "match";
|
messageType: "matchState";
|
||||||
history: (Table | Action)[];
|
messageContent: {
|
||||||
|
history: (Table | Action)[];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MatchStateRawReadonly = Readonly<MatchStateRaw>;
|
export type MatchStateRawReadonly = Readonly<MatchStateRaw>;
|
||||||
@@ -52,3 +52,9 @@ export interface Parabola {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Vector2 = [number, number];
|
export type Vector2 = [number, number];
|
||||||
|
|
||||||
|
export function getClient(playerOrSpectator: Player | Spectator): Client {
|
||||||
|
return "client" in playerOrSpectator
|
||||||
|
? playerOrSpectator.client
|
||||||
|
: playerOrSpectator;
|
||||||
|
}
|
||||||
@@ -1,25 +1,36 @@
|
|||||||
import Ajv, { ValidateFunction } from "ajv";
|
import Ajv, { ValidateFunction } from "ajv/dist/2020";
|
||||||
|
|
||||||
import { log } from "./utils/debugUtils";
|
import { log } from "./utils/debugUtils";
|
||||||
import { Client, MessageRaw } from "./jsonTypes";
|
import { Client, MessageRaw } from "./jsonTypes";
|
||||||
import messageSchemaFile from "../../schema/message_schema.json";
|
import messageSchemaFile from "../../schema/message.json";
|
||||||
import clientSchemaFile from "../../schema/client_schema.json";
|
|
||||||
import lobbyStateSchemaFile from "../../schema/lobby_state_schema.json";
|
import clientSchemaFile from "../../schema/common/client.json";
|
||||||
import matchStateSchemaFile from "../../schema/match_state_schema.json";
|
import playerSchemaFile from "../../schema/common/player.json";
|
||||||
import actionSchemaFile from "../../schema/action_schema.json";
|
|
||||||
import playerSchemaFile from "../../schema/player_schema.json";
|
import joinSchemaFile from "../../schema/lobby/join.json";
|
||||||
import spectatorSchemaFile from "../../schema/spectator_schema.json";
|
import joinResponseSchemaFile from "../../schema/lobby/join_response.json";
|
||||||
import tableSchemaFile from "../../schema/table_schema.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 });
|
const ajv = new Ajv({ strict: true });
|
||||||
|
|
||||||
ajv.addSchema(lobbyStateSchemaFile, "lobby_state_schema.json");
|
ajv.addSchema(clientSchemaFile, "client.json");
|
||||||
ajv.addSchema(matchStateSchemaFile, "match_state_schema.json");
|
ajv.addSchema(playerSchemaFile, "player.json");
|
||||||
ajv.addSchema(actionSchemaFile, "action_schema.json");
|
|
||||||
ajv.addSchema(clientSchemaFile, "client_schema.json");
|
ajv.addSchema(joinSchemaFile, "join.json");
|
||||||
ajv.addSchema(playerSchemaFile, "player_schema.json");
|
ajv.addSchema(joinResponseSchemaFile, "join_response.json");
|
||||||
ajv.addSchema(spectatorSchemaFile, "spectator_schema.json");
|
ajv.addSchema(rejoinSchemaFile, "rejoin.json");
|
||||||
ajv.addSchema(tableSchemaFile, "table_schema.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 validateMessage = ajv.compile(messageSchemaFile);
|
||||||
const validateClient = ajv.compile(clientSchemaFile);
|
const validateClient = ajv.compile(clientSchemaFile);
|
||||||
|
|||||||
@@ -29,16 +29,16 @@ export class MockSocket
|
|||||||
|
|
||||||
export function mockLobbyMessage(): string {
|
export function mockLobbyMessage(): string {
|
||||||
const lobbyUpdate = {
|
const lobbyUpdate = {
|
||||||
state: {
|
messageType: "lobbyState",
|
||||||
stateType: "lobby",
|
messageContent: {
|
||||||
players: [
|
players: [
|
||||||
{ client: { name: "Dubbel", id: 0 }, ready: true },
|
{ client: { name: "Dubbel", id: 0 }, ready: true },
|
||||||
{ client: { name: "Yeah", id: 1 }, ready: false },
|
{ client: { name: "Yeah", id: 1 }, ready: false },
|
||||||
],
|
],
|
||||||
spectators: [
|
spectators: [
|
||||||
{ client: { name: "Dubbel", id: 2 } },
|
{ name: "Dubbel", id: 2 },
|
||||||
{ client: { name: "Cocksucker", id: 3 } },
|
{ name: "Cocksucker", id: 3 },
|
||||||
{ client: { name: "Cocksucker 2", id: 4 } },
|
{ name: "Cocksucker 2", id: 4 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,29 +1,47 @@
|
|||||||
{
|
{
|
||||||
"title": "Action",
|
"title": "Action",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"parabola": { "$ref": "#/$defs/parabola" },
|
"parabola": {
|
||||||
"turn": { "$ref": "#/$defs/turn" }
|
"$ref": "#/$defs/parabola"
|
||||||
},
|
},
|
||||||
"required": ["parabola", "turn"],
|
"turn": {
|
||||||
"additionalProperties": false,
|
"$ref": "#/$defs/turn"
|
||||||
"$defs": {
|
}
|
||||||
"turn": {
|
|
||||||
"enum": ["a", "b"]
|
|
||||||
},
|
},
|
||||||
"parabola": {
|
"required": [
|
||||||
"type": "object",
|
"parabola",
|
||||||
"properties": {
|
"turn"
|
||||||
"startPosition": { "$ref": "#/$defs/vector2" },
|
],
|
||||||
"startVelocity": { "$ref": "#/$defs/vector2" },
|
"additionalProperties": false,
|
||||||
"stopTime": { "type": "number" }
|
"$defs": {
|
||||||
}
|
"turn": {
|
||||||
},
|
"enum": [
|
||||||
"vector2": {
|
"a",
|
||||||
"type": "array",
|
"b"
|
||||||
"items": { "type": "number" },
|
]
|
||||||
"minItems": 2,
|
},
|
||||||
"maxItems": 2
|
"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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"title": "Client",
|
"title": "Client",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"minimum": 0
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"name": {
|
"required": [
|
||||||
"type": "string"
|
"id",
|
||||||
}
|
"name"
|
||||||
},
|
],
|
||||||
"required": [
|
"additionalProperties": false
|
||||||
"id",
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
{
|
{
|
||||||
"title": "JoinMessage",
|
"title": "JoinMessage",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"name": {
|
"required": [
|
||||||
"type": "string"
|
"type",
|
||||||
}
|
"name"
|
||||||
},
|
],
|
||||||
"required": [
|
"additionalProperties": false
|
||||||
"type",
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,29 @@
|
|||||||
{
|
{
|
||||||
"title": "LobbyState",
|
"title": "LobbyState",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"stateType": {
|
"stateType": {
|
||||||
"enum": [
|
"enum": [
|
||||||
"lobby"
|
"lobby"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"players": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "file://localhost/./player_schema.json"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spectators": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "./spectator_schema.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"players": {
|
"required": [
|
||||||
"type": "array",
|
"stateType",
|
||||||
"items": {
|
"players",
|
||||||
"$ref": "file://localhost/./player_schema.json"
|
"spectators"
|
||||||
}
|
],
|
||||||
},
|
"additionalProperties": false
|
||||||
"spectators": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "./spectator_schema.json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"stateType",
|
|
||||||
"players",
|
|
||||||
"spectators"
|
|
||||||
],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,29 @@
|
|||||||
{
|
{
|
||||||
"title": "MatchState",
|
"title": "MatchState",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"stateType": { "enum": ["match"]},
|
"stateType": {
|
||||||
"history": {
|
"enum": [
|
||||||
"type": "array",
|
"match"
|
||||||
"items": {
|
|
||||||
"anyOf": [
|
|
||||||
{ "$ref": "./table_schema.json" },
|
|
||||||
{ "$ref": "./action_schema.json" }
|
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"history": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"$ref": "./table_schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "./action_schema.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
"required": [
|
||||||
"required": ["stateType", "history"],
|
"stateType",
|
||||||
"additionalProperties": false
|
"history"
|
||||||
}
|
],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"title": "Message",
|
"title": "Message",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"state": {
|
"state": {
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
"$ref": "./lobby_state_schema.json"
|
"$ref": "./lobby_state_schema.json"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$ref": "./match_state_schema.json"
|
"$ref": "./match_state_schema.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
"required": [
|
||||||
},
|
"state"
|
||||||
"required": [
|
],
|
||||||
"state"
|
"additionalProperties": false
|
||||||
],
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"title": "Player",
|
"title": "Player",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"client": {
|
"client": {
|
||||||
"$ref": "./client_schema.json"
|
"$ref": "./client_schema.json"
|
||||||
|
},
|
||||||
|
"ready": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"ready": {
|
"required": [
|
||||||
"type": "boolean"
|
"client",
|
||||||
}
|
"ready"
|
||||||
},
|
],
|
||||||
"required": ["client", "ready"],
|
"additionalProperties": false
|
||||||
"additionalProperties": false
|
}
|
||||||
}
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"title": "Spectator",
|
"title": "Spectator",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"client": {
|
"client": {
|
||||||
"$ref": "./client_schema.json"
|
"$ref": "./client_schema.json"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["client"],
|
"required": [
|
||||||
"additionalProperties": false
|
"client"
|
||||||
}
|
],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -1,26 +1,43 @@
|
|||||||
{
|
{
|
||||||
"title": "Table",
|
"title": "Table",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"cupsA": { "$ref": "#/$defs/cups" },
|
"cupsA": {
|
||||||
"cupsB": { "$ref": "#/$defs/cups" },
|
"$ref": "#/$defs/cups"
|
||||||
"teamA": { "$ref": "#/$defs/team" },
|
},
|
||||||
"teamB": { "$ref": "#/$defs/team" }
|
"cupsB": {
|
||||||
},
|
"$ref": "#/$defs/cups"
|
||||||
"required": ["cupsA", "cupsB", "teamA", "teamB"],
|
},
|
||||||
"additionalProperties": false,
|
"teamA": {
|
||||||
"$defs": {
|
"$ref": "#/$defs/team"
|
||||||
"cups": {
|
},
|
||||||
"type": "array",
|
"teamB": {
|
||||||
"items": { "type": "boolean" },
|
"$ref": "#/$defs/team"
|
||||||
"minItems": 3,
|
}
|
||||||
"maxItems": 3
|
|
||||||
},
|
},
|
||||||
"team": {
|
"required": [
|
||||||
"type": "array",
|
"cupsA",
|
||||||
"items": { "type": "number" },
|
"cupsB",
|
||||||
"minItems": 3,
|
"teamA",
|
||||||
"maxItems": 3
|
"teamB"
|
||||||
|
],
|
||||||
|
"additionalProperties": false,
|
||||||
|
"$defs": {
|
||||||
|
"cups": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"minItems": 3,
|
||||||
|
"maxItems": 3
|
||||||
|
},
|
||||||
|
"team": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"minItems": 3,
|
||||||
|
"maxItems": 3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
"$id": "schema:client",
|
"$id": "http://localhost/common/client.json",
|
||||||
"title": "Client",
|
"title": "Client",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -10,15 +10,11 @@
|
|||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
|
||||||
"ready": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"name"
|
||||||
"ready"
|
|
||||||
],
|
],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"$id": "http://localhost/lobby/join.json",
|
||||||
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"messageType": {
|
"messageType": {
|
||||||
"const": "join"
|
"const": "join"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"$id": "http://localhost/lobby/join_response.json",
|
||||||
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"messageType": {
|
"messageType": {
|
||||||
"const": "joinResponse"
|
"const": "joinResponse"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"$id": "http://localhost/lobby/rejoin.json",
|
||||||
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"messageType": {
|
"messageType": {
|
||||||
"const": "rejoin"
|
"const": "rejoin"
|
||||||
|
|||||||
+15
-10
@@ -1,19 +1,24 @@
|
|||||||
{
|
{
|
||||||
|
"$id": "http://localhost/lobby/state.json",
|
||||||
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"messageType": {
|
"messageType": {
|
||||||
"const": "lobbyState"
|
"const": "lobbyState"
|
||||||
},
|
},
|
||||||
"messageContent": {
|
"messageContent": {
|
||||||
"players": {
|
"type": "object",
|
||||||
"type": "array",
|
"properties": {
|
||||||
"items": {
|
"players": {
|
||||||
"$ref": "../common/client.json"
|
"type": "array",
|
||||||
}
|
"items": {
|
||||||
},
|
"$ref": "../common/player.json"
|
||||||
"spectators": {
|
}
|
||||||
"type": "array",
|
},
|
||||||
"items": {
|
"spectators": {
|
||||||
"$ref": "../common/client.json"
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "../common/client.json"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"$id": "http://localhost/lobby/toggle_ready.json",
|
||||||
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"messageType": {
|
"messageType": {
|
||||||
"const": "toggleReady"
|
"const": "toggleReady"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"$id": "http://localhost/lobby/toggle_role.json",
|
||||||
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"messageType": {
|
"messageType": {
|
||||||
"const": "toggleRole"
|
"const": "toggleRole"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
"$id": "schema:message",
|
"$id": "http://localhost/message.json",
|
||||||
"title": "Message",
|
"title": "Message",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
Reference in new issue
Block a user