2022-03-14 05:33:51 +00:00
|
|
|
# Backend Protocol
|
|
|
|
|
|
|
|
The backend will be available at https://asdm.seodisparate.com/api .
|
2022-04-08 02:05:03 +00:00
|
|
|
The frontend will send http POST requests to the URL with JSON as the body
|
2022-03-14 05:33:51 +00:00
|
|
|
of the request, and the backend will respond with JSON.
|
|
|
|
|
|
|
|
## Requests
|
|
|
|
|
|
|
|
1. Request ID and Pairing
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "pairing_request",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-04-27 02:42:28 +00:00
|
|
|
An optional "phrase" parameter can be sent to match against other players with
|
|
|
|
the same "phrase".
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "pairing_request",
|
|
|
|
"phrase": "user_defined_phrase",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-14 05:33:51 +00:00
|
|
|
2. Check pairing status
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "check_pairing",
|
|
|
|
"id": "id given by backend",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
3. Request Turn action
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"id": "id given by backend",
|
|
|
|
"type": "place_token",
|
|
|
|
"position": 7,
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-18 06:16:27 +00:00
|
|
|
4. Disconnect
|
2022-03-14 05:33:51 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"id": "id given by backend",
|
|
|
|
"type": "disconnect",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-18 06:16:27 +00:00
|
|
|
5. Request Game State:
|
2022-03-14 05:33:51 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"id": "id given by backend",
|
|
|
|
"type": "game_state",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-04-29 06:53:36 +00:00
|
|
|
6. Chat Emote Send:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"id": "id given by backend",
|
|
|
|
"type": "send_emote",
|
|
|
|
"emote": "smile", // or "frown", or "neutral", or "think"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-14 05:33:51 +00:00
|
|
|
## Responses
|
|
|
|
|
|
|
|
1. Request ID Response
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "pairing_response",
|
|
|
|
"id": "id set by backend",
|
|
|
|
"status": "waiting",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "pairing_response",
|
|
|
|
"id": "id set by backend",
|
|
|
|
"status": "paired",
|
|
|
|
"color": "cyan", // or "magenta"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
If there are too many players such that a new game cannot be feasibly started,
|
|
|
|
then the back-end will respond with "too\_many\_players".
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "pairing_response",
|
|
|
|
"status": "too_many_players"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Check pairing status
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
2022-04-06 09:43:17 +00:00
|
|
|
"type": "pairing_status",
|
2022-03-14 05:33:51 +00:00
|
|
|
"status": "waiting", // or "unknown_id"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
2022-04-06 09:43:17 +00:00
|
|
|
"type": "pairing_status",
|
2022-03-14 05:33:51 +00:00
|
|
|
"status": "paired",
|
|
|
|
"color": "magenta", // or "cyan"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
3. Request Turn action Response
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "place_token",
|
|
|
|
"status": "not_paired_yet", // or "accepted", "illegal",
|
2022-04-01 08:17:42 +00:00
|
|
|
// "not_your_turn", "game_ended_draw",
|
|
|
|
// "game_ended_cyan_won",
|
|
|
|
// "game_ended_magenta_won", "unknown_id"
|
|
|
|
"board": "abcdefg..." // see protocol 5 response for details
|
2022-03-14 05:33:51 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-18 06:16:27 +00:00
|
|
|
4. Disconnect Response
|
2022-03-14 05:33:51 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "disconnect",
|
|
|
|
"status": "ok", // or "unknown_id"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-18 06:16:27 +00:00
|
|
|
5. Request Game State Response
|
2022-03-14 05:33:51 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "game_state",
|
2022-03-18 06:16:27 +00:00
|
|
|
"status": "not_paired", // or "unknown_id", "cyan_turn", "magenta_turn",
|
|
|
|
// "cyan_won", "magenta_won", "draw",
|
2022-03-30 11:43:49 +00:00
|
|
|
// "opponent_disconnected", "internal_error"
|
2022-03-18 06:16:27 +00:00
|
|
|
|
|
|
|
// "board" may not be in the response if "unknown_id" is the status
|
2022-04-30 07:27:43 +00:00
|
|
|
"board": "abcdefg...",// 56-char long string with mapping:
|
2022-03-18 06:16:27 +00:00
|
|
|
// a - empty
|
|
|
|
// b - cyan
|
|
|
|
// c - magenta
|
2022-03-31 11:38:22 +00:00
|
|
|
// d - cyan winning piece
|
|
|
|
// e - magenta winning piece
|
|
|
|
// f - cyan placed
|
|
|
|
// g - magenta placed
|
2022-04-06 11:09:22 +00:00
|
|
|
// h - cyan winning and placed piece
|
|
|
|
// i - magenta winning and placed piece
|
2022-04-29 06:53:36 +00:00
|
|
|
// optional "peer_emote" entry is message from opponent
|
2022-04-30 07:27:43 +00:00
|
|
|
"peer_emote": "smile",// or "frown", or "neutral", or "think"
|
|
|
|
|
|
|
|
// should always be available when "board" is available
|
|
|
|
"updated_time": "2022-04-30 12:00:00"
|
2022-03-14 05:33:51 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-04-29 08:16:32 +00:00
|
|
|
6. Send Emote Request Response
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"type": "send_emote",
|
|
|
|
"status": "ok", // or "invalid_emote", "peer_disconnected",
|
|
|
|
// "internal_error"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-14 05:33:51 +00:00
|
|
|
Note that the backend will stop keeping track of the game once both players have
|
|
|
|
successfully requested the Game State once after the game has ended. Thus,
|
|
|
|
future requests may return "unknown\_id" as the "status".
|
|
|
|
|
|
|
|
Note that if a player has disconnected, the other player will receive a "status"
|
|
|
|
of "opponent\_disconnected". Future requests will return "unknown\_id".
|