Skip to content

Commit c6a365d

Browse files
authored
Add basics for bots supports (#78)
Add the basics for bot supports in lobbies. I chose to use a different field for bots instead of cramming them inside the `players` object. Makes the client code a little bit more complex to display the rooms, but I think it'll work better when we evolve players and bots, without running into the same problem of json merge patch + sum type. I also added a concept of ID for bots, that the server generates because otherwise it's not clear how to identify a bot, and we need an ID for remove & lobby/updated
1 parent 4e796e8 commit c6a365d

15 files changed

Lines changed: 1600 additions & 19 deletions

File tree

docs/schema/lobby.md

Lines changed: 721 additions & 17 deletions
Large diffs are not rendered by default.

schema/compiled.json

Lines changed: 384 additions & 1 deletion
Large diffs are not rendered by default.

schema/definitions/lobbyDetails.json

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,52 @@
6666
}
6767
}
6868
},
69+
"bots": {
70+
"type": "object",
71+
"patternProperties": {
72+
"^(.*)$": {
73+
"type": "object",
74+
"properties": {
75+
"id": {
76+
"description": "server assigned unique identifier for the bot",
77+
"type": "string"
78+
},
79+
"hostUserId": {
80+
"$ref": "../definitions/userId.json",
81+
"description": "which player will run the bot. It is the same as the player that added the bot."
82+
},
83+
"allyTeam": { "type": "string" },
84+
"team": { "type": "string" },
85+
"player": { "type": "string" },
86+
"name": {
87+
"description": "name to display in the lobby",
88+
"type": "string",
89+
"maxLength": 20
90+
},
91+
"shortName": {
92+
"description": "short name of the bot. Used to uniquely identify which bot to run",
93+
"type": "string",
94+
"maxLength": 20
95+
},
96+
"version": { "type": "string" },
97+
"options": {
98+
"type": "object",
99+
"patternProperties": {
100+
"^(.*)$": { "type": "string" }
101+
}
102+
}
103+
},
104+
"required": [
105+
"id",
106+
"hostUserId",
107+
"allyTeam",
108+
"team",
109+
"player",
110+
"shortName"
111+
]
112+
}
113+
}
114+
},
69115
"currentBattle": {
70116
"description": "If a battle is currently happening, here are the info",
71117
"type": "object",
@@ -83,6 +129,7 @@
83129
"gameVersion",
84130
"allyTeamConfig",
85131
"players",
86-
"spectators"
132+
"spectators",
133+
"bots"
87134
]
88135
}

schema/lobby/addBot/request.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/addBot/request.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyAddBotRequest",
5+
"tachyon": {
6+
"source": "user",
7+
"target": "server",
8+
"scopes": ["tachyon.lobby"]
9+
},
10+
"type": "object",
11+
"properties": {
12+
"type": { "const": "request" },
13+
"messageId": { "type": "string" },
14+
"commandId": { "const": "lobby/addBot" },
15+
"data": {
16+
"title": "LobbyAddBotRequestData",
17+
"type": "object",
18+
"properties": {
19+
"allyTeam": { "type": "string" },
20+
"name": {
21+
"description": "name to display in the lobby",
22+
"type": "string",
23+
"maxLength": 20
24+
},
25+
"shortName": {
26+
"description": "Short name of the bot. Used to uniquely identify which bot to run",
27+
"type": "string",
28+
"maxLength": 20
29+
},
30+
"version": { "type": "string" },
31+
"options": {
32+
"type": "object",
33+
"patternProperties": { "^(.*)$": { "type": "string" } }
34+
}
35+
},
36+
"required": ["allyTeam", "shortName"]
37+
}
38+
},
39+
"required": ["type", "messageId", "commandId", "data"]
40+
}

schema/lobby/addBot/response.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/addBot/response.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyAddBotResponse",
5+
"tachyon": {
6+
"source": "server",
7+
"target": "user",
8+
"scopes": ["tachyon.lobby"]
9+
},
10+
"anyOf": [
11+
{
12+
"title": "LobbyAddBotOkResponse",
13+
"type": "object",
14+
"properties": {
15+
"type": { "const": "response" },
16+
"messageId": { "type": "string" },
17+
"commandId": { "const": "lobby/addBot" },
18+
"status": { "const": "success" },
19+
"data": {
20+
"title": "LobbyAddBotOkResponseData",
21+
"type": "object",
22+
"properties": {
23+
"id": {
24+
"description": "The id the server generated for this bot",
25+
"type": "string"
26+
}
27+
},
28+
"required": ["id"]
29+
}
30+
},
31+
"required": ["type", "messageId", "commandId", "status", "data"]
32+
},
33+
{
34+
"title": "LobbyAddBotFailResponse",
35+
"type": "object",
36+
"properties": {
37+
"type": { "const": "response" },
38+
"messageId": { "type": "string" },
39+
"commandId": { "const": "lobby/addBot" },
40+
"status": { "const": "failed" },
41+
"reason": {
42+
"enum": [
43+
"not_in_lobby",
44+
"ally_team_full",
45+
"internal_error",
46+
"unauthorized",
47+
"invalid_request",
48+
"command_unimplemented"
49+
]
50+
},
51+
"details": { "type": "string" }
52+
},
53+
"required": ["type", "messageId", "commandId", "status", "reason"]
54+
}
55+
]
56+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/removeBot/request.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyRemoveBotRequest",
5+
"tachyon": {
6+
"source": "user",
7+
"target": "server",
8+
"scopes": ["tachyon.lobby"]
9+
},
10+
"type": "object",
11+
"properties": {
12+
"type": { "const": "request" },
13+
"messageId": { "type": "string" },
14+
"commandId": { "const": "lobby/removeBot" },
15+
"data": {
16+
"title": "LobbyRemoveBotRequestData",
17+
"type": "object",
18+
"properties": { "id": { "type": "string" } },
19+
"required": ["id"]
20+
}
21+
},
22+
"required": ["type", "messageId", "commandId", "data"]
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/removeBot/response.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyRemoveBotResponse",
5+
"tachyon": {
6+
"source": "server",
7+
"target": "user",
8+
"scopes": ["tachyon.lobby"]
9+
},
10+
"anyOf": [
11+
{
12+
"title": "LobbyRemoveBotOkResponse",
13+
"type": "object",
14+
"properties": {
15+
"type": { "const": "response" },
16+
"messageId": { "type": "string" },
17+
"commandId": { "const": "lobby/removeBot" },
18+
"status": { "const": "success" }
19+
},
20+
"required": ["type", "messageId", "commandId", "status"]
21+
},
22+
{
23+
"title": "LobbyRemoveBotFailResponse",
24+
"type": "object",
25+
"properties": {
26+
"type": { "const": "response" },
27+
"messageId": { "type": "string" },
28+
"commandId": { "const": "lobby/removeBot" },
29+
"status": { "const": "failed" },
30+
"reason": {
31+
"enum": [
32+
"not_in_lobby",
33+
"invalid_bot",
34+
"internal_error",
35+
"unauthorized",
36+
"invalid_request",
37+
"command_unimplemented"
38+
]
39+
},
40+
"details": { "type": "string" }
41+
},
42+
"required": ["type", "messageId", "commandId", "status", "reason"]
43+
}
44+
]
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/updateBot/request.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyUpdateBotRequest",
5+
"tachyon": {
6+
"source": "user",
7+
"target": "server",
8+
"scopes": ["tachyon.lobby"]
9+
},
10+
"type": "object",
11+
"properties": {
12+
"type": { "const": "request" },
13+
"messageId": { "type": "string" },
14+
"commandId": { "const": "lobby/updateBot" },
15+
"data": {
16+
"title": "LobbyUpdateBotRequestData",
17+
"type": "object",
18+
"properties": {
19+
"id": { "type": "string" },
20+
"name": {
21+
"description": "name to display in the lobby",
22+
"type": "string",
23+
"maxLength": 20
24+
},
25+
"shortName": {
26+
"description": "short name of the bot. Used to uniquely identify which bot to run",
27+
"type": "string"
28+
},
29+
"version": {
30+
"anyOf": [{ "type": "string" }, { "type": "null" }]
31+
},
32+
"options": {
33+
"type": "object",
34+
"patternProperties": {
35+
"^(.*)$": {
36+
"anyOf": [{ "type": "string" }, { "type": "null" }]
37+
}
38+
}
39+
}
40+
},
41+
"required": ["id"]
42+
}
43+
},
44+
"required": ["type", "messageId", "commandId", "data"]
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/updateBot/response.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyUpdateBotResponse",
5+
"tachyon": {
6+
"source": "server",
7+
"target": "user",
8+
"scopes": ["tachyon.lobby"]
9+
},
10+
"anyOf": [
11+
{
12+
"title": "LobbyUpdateBotOkResponse",
13+
"type": "object",
14+
"properties": {
15+
"type": { "const": "response" },
16+
"messageId": { "type": "string" },
17+
"commandId": { "const": "lobby/updateBot" },
18+
"status": { "const": "success" }
19+
},
20+
"required": ["type", "messageId", "commandId", "status"]
21+
},
22+
{
23+
"title": "LobbyUpdateBotFailResponse",
24+
"type": "object",
25+
"properties": {
26+
"type": { "const": "response" },
27+
"messageId": { "type": "string" },
28+
"commandId": { "const": "lobby/updateBot" },
29+
"status": { "const": "failed" },
30+
"reason": {
31+
"enum": [
32+
"not_in_lobby",
33+
"invalid_bot",
34+
"internal_error",
35+
"unauthorized",
36+
"invalid_request",
37+
"command_unimplemented"
38+
]
39+
},
40+
"details": { "type": "string" }
41+
},
42+
"required": ["type", "messageId", "commandId", "status", "reason"]
43+
}
44+
]
45+
}

schema/lobby/updated/event.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,65 @@
111111
}
112112
}
113113
},
114+
"bots": {
115+
"type": "object",
116+
"patternProperties": {
117+
"^(.*)$": {
118+
"anyOf": [
119+
{
120+
"type": "object",
121+
"properties": {
122+
"id": { "type": "string" },
123+
"allyTeam": { "type": "string" },
124+
"team": { "type": "string" },
125+
"player": { "type": "string" },
126+
"name": {
127+
"anyOf": [
128+
{
129+
"description": "name to display in the lobby",
130+
"type": "string"
131+
},
132+
{ "type": "null" }
133+
]
134+
},
135+
"shortName": {
136+
"description": "Short name of the bot. Used to uniquely identify which bot to run",
137+
"type": "string"
138+
},
139+
"version": {
140+
"anyOf": [
141+
{ "type": "string" },
142+
{ "type": "null" }
143+
]
144+
},
145+
"options": {
146+
"anyOf": [
147+
{
148+
"type": "object",
149+
"patternProperties": {
150+
"^(.*)$": {
151+
"anyOf": [
152+
{
153+
"type": "string"
154+
},
155+
{
156+
"type": "null"
157+
}
158+
]
159+
}
160+
}
161+
},
162+
{ "type": "null" }
163+
]
164+
}
165+
},
166+
"required": ["id", "version", "options"]
167+
},
168+
{ "type": "null" }
169+
]
170+
}
171+
}
172+
},
114173
"currentBattle": {
115174
"anyOf": [
116175
{

0 commit comments

Comments
 (0)