Skip to content

Commit 46fe9d7

Browse files
authored
Add votes to lobby (#86)
This should allow to start having votes in lobby, for start or changing map for example.
1 parent eaf8695 commit 46fe9d7

14 files changed

Lines changed: 1084 additions & 178 deletions

File tree

docs/schema/lobby.md

Lines changed: 626 additions & 176 deletions
Large diffs are not rendered by default.

schema/compiled.json

Lines changed: 190 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,36 @@
204204
"startedAt": { "$ref": "#/definitions/unixTime" }
205205
},
206206
"required": ["startedAt"]
207+
},
208+
"currentVote": {
209+
"type": "object",
210+
"properties": {
211+
"id": { "type": "string" },
212+
"action": { "$ref": "#/definitions/voteActions" },
213+
"initiator": { "$ref": "#/definitions/userId" },
214+
"voters": {
215+
"description": "indexed by the userId. The initiator is also included in this object",
216+
"type": "object",
217+
"patternProperties": {
218+
"^(.*)$": {
219+
"type": "object",
220+
"properties": {
221+
"vote": {
222+
"enum": [
223+
"pending",
224+
"yes",
225+
"no",
226+
"abstain"
227+
]
228+
}
229+
},
230+
"required": ["vote"]
231+
}
232+
}
233+
},
234+
"until": { "$ref": "#/definitions/unixTime" }
235+
},
236+
"required": ["id", "action", "initiator", "voters", "until"]
207237
}
208238
},
209239
"required": [
@@ -503,7 +533,24 @@
503533
"status"
504534
]
505535
},
506-
"userId": { "type": "string", "examples": ["351"] }
536+
"userId": { "type": "string", "examples": ["351"] },
537+
"voteActions": {
538+
"anyOf": [
539+
{
540+
"type": "object",
541+
"properties": { "type": { "const": "start" } },
542+
"required": ["type"]
543+
},
544+
{
545+
"type": "object",
546+
"properties": {
547+
"type": { "const": "changeMap" },
548+
"newMapName": { "type": "string" }
549+
},
550+
"required": ["type", "newMapName"]
551+
}
552+
]
553+
}
507554
},
508555
"anyOf": [
509556
{
@@ -3538,13 +3585,155 @@
35383585
},
35393586
{ "type": "null" }
35403587
]
3588+
},
3589+
"currentVote": {
3590+
"anyOf": [
3591+
{
3592+
"type": "object",
3593+
"properties": {
3594+
"id": { "type": "string" },
3595+
"action": {
3596+
"anyOf": [
3597+
{
3598+
"$ref": "#/definitions/voteActions"
3599+
},
3600+
{ "type": "null" }
3601+
]
3602+
},
3603+
"initiator": {
3604+
"$ref": "#/definitions/userId"
3605+
},
3606+
"voters": {
3607+
"type": "object",
3608+
"patternProperties": {
3609+
"^(.*)$": {
3610+
"type": "object",
3611+
"properties": {
3612+
"vote": {
3613+
"enum": [
3614+
"pending",
3615+
"yes",
3616+
"no",
3617+
"abstain"
3618+
]
3619+
}
3620+
},
3621+
"required": ["vote"]
3622+
}
3623+
}
3624+
},
3625+
"until": {
3626+
"$ref": "#/definitions/unixTime"
3627+
}
3628+
},
3629+
"required": ["id"]
3630+
},
3631+
{ "type": "null" }
3632+
]
35413633
}
35423634
},
35433635
"required": ["id"]
35443636
}
35453637
},
35463638
"required": ["type", "messageId", "commandId", "data"]
35473639
},
3640+
{
3641+
"title": "LobbyVoteEndedEvent",
3642+
"tachyon": {
3643+
"source": "server",
3644+
"target": "user",
3645+
"scopes": ["tachyon.lobby"]
3646+
},
3647+
"type": "object",
3648+
"properties": {
3649+
"type": { "const": "event" },
3650+
"messageId": { "type": "string" },
3651+
"commandId": { "const": "lobby/voteEnded" },
3652+
"data": {
3653+
"title": "LobbyVoteEndedEventData",
3654+
"type": "object",
3655+
"properties": {
3656+
"id": { "type": "string" },
3657+
"outcome": {
3658+
"enum": ["passed", "failed", "cancelled", "timeout"]
3659+
}
3660+
},
3661+
"required": ["id", "outcome"]
3662+
}
3663+
},
3664+
"required": ["type", "messageId", "commandId", "data"]
3665+
},
3666+
{
3667+
"title": "LobbyVoteSubmitRequest",
3668+
"tachyon": {
3669+
"source": "user",
3670+
"target": "server",
3671+
"scopes": ["tachyon.lobby"]
3672+
},
3673+
"type": "object",
3674+
"properties": {
3675+
"type": { "const": "request" },
3676+
"messageId": { "type": "string" },
3677+
"commandId": { "const": "lobby/voteSubmit" },
3678+
"data": {
3679+
"title": "LobbyVoteSubmitRequestData",
3680+
"type": "object",
3681+
"properties": {
3682+
"id": { "type": "string" },
3683+
"vote": { "enum": ["yes", "no", "abstain"] }
3684+
},
3685+
"required": ["id", "vote"]
3686+
}
3687+
},
3688+
"required": ["type", "messageId", "commandId", "data"]
3689+
},
3690+
{
3691+
"title": "LobbyVoteSubmitResponse",
3692+
"tachyon": {
3693+
"source": "server",
3694+
"target": "user",
3695+
"scopes": ["tachyon.lobby"]
3696+
},
3697+
"anyOf": [
3698+
{
3699+
"title": "LobbyVoteSubmitOkResponse",
3700+
"type": "object",
3701+
"properties": {
3702+
"type": { "const": "response" },
3703+
"messageId": { "type": "string" },
3704+
"commandId": { "const": "lobby/voteSubmit" },
3705+
"status": { "const": "success" }
3706+
},
3707+
"required": ["type", "messageId", "commandId", "status"]
3708+
},
3709+
{
3710+
"title": "LobbyVoteSubmitFailResponse",
3711+
"type": "object",
3712+
"properties": {
3713+
"type": { "const": "response" },
3714+
"messageId": { "type": "string" },
3715+
"commandId": { "const": "lobby/voteSubmit" },
3716+
"status": { "const": "failed" },
3717+
"reason": {
3718+
"enum": [
3719+
"internal_error",
3720+
"unauthorized",
3721+
"invalid_request",
3722+
"command_unimplemented"
3723+
]
3724+
},
3725+
"details": { "type": "string" }
3726+
},
3727+
"required": [
3728+
"type",
3729+
"messageId",
3730+
"commandId",
3731+
"status",
3732+
"reason"
3733+
]
3734+
}
3735+
]
3736+
},
35483737
{
35493738
"title": "MatchmakingCancelRequest",
35503739
"tachyon": {

schema/definitions/lobbyDetails.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@
119119
"startedAt": { "$ref": "../definitions/unixTime.json" }
120120
},
121121
"required": ["startedAt"]
122+
},
123+
"currentVote": {
124+
"type": "object",
125+
"properties": {
126+
"id": { "type": "string" },
127+
"action": { "$ref": "../definitions/voteActions.json" },
128+
"initiator": { "$ref": "../definitions/userId.json" },
129+
"voters": {
130+
"description": "indexed by the userId. The initiator is also included in this object",
131+
"type": "object",
132+
"patternProperties": {
133+
"^(.*)$": {
134+
"type": "object",
135+
"properties": {
136+
"vote": {
137+
"enum": ["pending", "yes", "no", "abstain"]
138+
}
139+
},
140+
"required": ["vote"]
141+
}
142+
}
143+
},
144+
"until": { "$ref": "../definitions/unixTime.json" }
145+
},
146+
"required": ["id", "action", "initiator", "voters", "until"]
122147
}
123148
},
124149
"required": [
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/definitions/voteActions.json",
3+
"title": "VoteActions",
4+
"anyOf": [
5+
{
6+
"type": "object",
7+
"properties": { "type": { "const": "start" } },
8+
"required": ["type"]
9+
},
10+
{
11+
"type": "object",
12+
"properties": {
13+
"type": { "const": "changeMap" },
14+
"newMapName": { "type": "string" }
15+
},
16+
"required": ["type", "newMapName"]
17+
}
18+
]
19+
}

schema/lobby/updated/event.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,51 @@
188188
},
189189
{ "type": "null" }
190190
]
191+
},
192+
"currentVote": {
193+
"anyOf": [
194+
{
195+
"type": "object",
196+
"properties": {
197+
"id": { "type": "string" },
198+
"action": {
199+
"anyOf": [
200+
{
201+
"$ref": "../../definitions/voteActions.json"
202+
},
203+
{ "type": "null" }
204+
]
205+
},
206+
"initiator": {
207+
"$ref": "../../definitions/userId.json"
208+
},
209+
"voters": {
210+
"type": "object",
211+
"patternProperties": {
212+
"^(.*)$": {
213+
"type": "object",
214+
"properties": {
215+
"vote": {
216+
"enum": [
217+
"pending",
218+
"yes",
219+
"no",
220+
"abstain"
221+
]
222+
}
223+
},
224+
"required": ["vote"]
225+
}
226+
}
227+
},
228+
"until": {
229+
"$ref": "../../definitions/unixTime.json"
230+
}
231+
},
232+
"required": ["id"]
233+
},
234+
{ "type": "null" }
235+
]
191236
}
192237
},
193238
"required": ["id"]

schema/lobby/voteEnded/event.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/voteEnded/event.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyVoteEndedEvent",
5+
"tachyon": {
6+
"source": "server",
7+
"target": "user",
8+
"scopes": ["tachyon.lobby"]
9+
},
10+
"type": "object",
11+
"properties": {
12+
"type": { "const": "event" },
13+
"messageId": { "type": "string" },
14+
"commandId": { "const": "lobby/voteEnded" },
15+
"data": {
16+
"title": "LobbyVoteEndedEventData",
17+
"type": "object",
18+
"properties": {
19+
"id": { "type": "string" },
20+
"outcome": {
21+
"enum": ["passed", "failed", "cancelled", "timeout"]
22+
}
23+
},
24+
"required": ["id", "outcome"]
25+
}
26+
},
27+
"required": ["type", "messageId", "commandId", "data"]
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$id": "https://schema.beyondallreason.dev/tachyon/lobby/voteSubmit/request.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "LobbyVoteSubmitRequest",
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/voteSubmit" },
15+
"data": {
16+
"title": "LobbyVoteSubmitRequestData",
17+
"type": "object",
18+
"properties": {
19+
"id": { "type": "string" },
20+
"vote": { "enum": ["yes", "no", "abstain"] }
21+
},
22+
"required": ["id", "vote"]
23+
}
24+
},
25+
"required": ["type", "messageId", "commandId", "data"]
26+
}

0 commit comments

Comments
 (0)