API¶
The server speaks plain HTTP on the address set by --host and --port. The default is
http://127.0.0.1:8765. It uses JSON for the control requests and for the frames, and the Server-Sent
Events format for the frame stream. It has no authentication, so it should stay on 127.0.0.1.
GET /¶
Returns the arcade page, index.html. The page loads style.css, logic.js, render.js and
app.js from the same address. Any other path under the static folder is served too. A path that
does not exist returns 404 with the text not found.
GET /healthz¶
{"ok": true, "version": "0.1.0"}
GET /planner¶
Says whether a planner file is loaded for the planner seat. The page reads it each time it connects.
{"loaded": true, "name": "my-planner", "file": "my-planner.npz"}
With no planner file the answer is {"loaded": false}. name is the name in the file's meta
record, or the file's name without its extension when the record gives none. file is the file's
name, without its folder.
Example:
curl http://127.0.0.1:8765/planner
POST /quit¶
Stops the server. It is what the Quit button sends. The server answers 202 with
{"stopping": true}, and then shuts down, so the command that started it ends with exit code 0.
The request must come from the page itself: the Host and Origin headers must name this server, and
the X-Requested-With: chasetag-arena header must be set. Anything else gets 403, and so does a
server that listens on an address other than 127.0.0.1, localhost or ::1.
curl -X POST -H "X-Requested-With: chasetag-arena" http://127.0.0.1:8765/quit
GET /bodies¶
Lists the bodies a game can be played with, and says which one is in use.
{
"bodies": [
{"name": "default", "label": "K/default", "family": "K", "summary": "A person-like walker: ..."}
],
"current": "K/default",
"locked": false
}
locked is true while games are being recorded, because a recorded session keeps one body. The page
reads this list each time it connects, so a body added to the registry shows up without a page change.
GET /ledger¶
Says whether this session is being written to the research store, and why it is not when it is not.
{"recording": true, "error": null}
recording is true only when the server was started with --participant, and the rounds are
being written. If a write fails, the game goes on, recording becomes false, and error says what
failed. A session that has stopped recording is not used for research. See
research logging.
Example:
curl http://127.0.0.1:8765/ledger
GET /events¶
A stream of frames, in the text/event-stream format. The server sends two kinds of event:
snapshot: sent once, when the stream opens. Its data is the latest frame, ornullbefore the first frame exists.frame: sent for each decision after that. Its data is one frame.
Every 15 s of silence, the server sends a comment line, : keepalive, so the connection stays open.
Each event's data is a single line of JSON. A frame looks like this:
{
"seq": 153,
"t_server": 15470.148,
"round": 4,
"phase": "running",
"t_event": 0.3,
"ended_by": null,
"bodies": [
{"seat": 0, "x": -0.007, "y": 1.047, "heading": -2.1408, "height": 0.951, "fallen": false},
{"seat": 1, "x": 0.005, "y": -0.957, "heading": 1.5036, "height": 0.945, "fallen": false}
],
"chaser": 1,
"round_score": [0.0, 0.0],
"match": {"seat0": 1.238, "seat1": 1.763, "tags": 3, "falls": 0, "timeouts": 0},
"selectors": {"seat0": "greedy", "seat1": "greedy", "body": "K/default"},
"paused": false,
"speed": 1.0,
"limit_s": 60
}
| Field | Type | Meaning |
|---|---|---|
seq |
integer | The frame's number. It rises by one for each frame, so a client can skip a duplicate. |
t_server |
number | The server's monotonic clock, in seconds, when the frame was made. |
round |
integer | The round number, from 1. |
phase |
string | running, ended or intermission. |
t_event |
number | The game time in this round when the frame was made, in seconds, to the millisecond. |
ended_by |
string or null | tag, fall or timeout in the ended and intermission phases. null while running. |
bodies |
array | Two objects, one for each seat, in seat order. |
bodies[].seat |
integer | 0 or 1. |
bodies[].x, bodies[].y |
number | Position on the arena in metres, to the millimetre. The arena runs from -6 to 6 on both axes. |
bodies[].heading |
number | Heading in radians, in (-π, π], to four decimals. |
bodies[].height |
number | Pelvis height in metres, to the millimetre. |
bodies[].fallen |
boolean | true once the body has fallen. |
chaser |
integer | The seat that chases in this round. |
round_score |
array | The score of each seat. It is the round's score in the ended phase. In the other phases it is the score of the round that has just ended, or zero while a round runs. |
match |
object | seat0 and seat1 are the summed scores since the last restart. tags, falls and timeouts count the rounds. |
selectors |
object | seat0 and seat1 are the players now in each seat. body is K/default. |
paused |
boolean | true while the game is paused. A viewer shows this flag, not a guess from the frames. |
speed |
number | The speed multiplier now in force, as set by the speed control. |
limit_s |
integer | The longest a round may run now, in game seconds: 20, 60, 180, 300 or 600. |
A pause, a play or a speed change sends the current frame again at once, with the new paused or speed
value, so a paused game still tells its viewers. That repeated frame has the same round, t_event and
phase as the one before it.
Frames are full snapshots, so a viewer that misses one loses nothing once the next one arrives. A slow viewer may miss frames, but it never blocks the game.
Example, to watch the frames for a few seconds:
curl -N http://127.0.0.1:8765/events
POST /control¶
Sends one control. The body is a JSON object, and its kind field names the control:
| Kind | Body | Effect |
|---|---|---|
selector |
{"kind": "selector", "seat": 0, "value": "greedy"} |
Sets who plays a seat. value is one of keyboard, planner, greedy, intercept, wander, idle or fallback. It applies at the next round start. planner plays the loaded planner, or the fallback bot when the server has no planner file (see GET /planner). |
keyboard |
{"kind": "keyboard", "seat": 0, "cmd": [0.0, 1.5]} |
Holds a velocity for a seat, in metres per second, in the world frame. Each component must be within ±1.5. The command expires 0.25 s after it arrives unless it is sent again. |
pause |
{"kind": "pause"} |
Stops decisions. |
play |
{"kind": "play"} |
Resumes decisions. |
step |
{"kind": "step"} |
Makes one decision while paused. |
restart |
{"kind": "restart"} |
Starts a new round and clears the match totals. |
speed |
{"kind": "speed", "value": 2} |
Sets the speed multiplier. value must be above 0 and at most 8. |
body |
{"kind": "body", "value": "dodger"} |
Sets the body both seats play with. value is a body name from GET /bodies. It applies at the next round start. A session that records games refuses it, since its rounds are recorded under one body. |
limit |
{"kind": "limit", "value": 180} |
Sets the longest a round may run, in game seconds. value is one of 20, 60, 180, 300 or 600. It applies at the next round start. A logged session refuses it, since its rounds are recorded under one length. |
seat is 0 or 1. Numbers must be finite, and a boolean is not a number. A field that the kind does
not take is an error, so a typo does not pass silently.
For example, to pause the game, then start it again:
curl -X POST -H "Content-Type: application/json" -d '{"kind": "pause"}' http://127.0.0.1:8765/control
curl -X POST -H "Content-Type: application/json" -d '{"kind": "play"}' http://127.0.0.1:8765/control
Responses:
| Status | Body | When |
|---|---|---|
202 |
{"accepted": true} |
The control is queued. The game applies it on its next decision. |
400 |
{"error": "..."} |
The body is not valid JSON, or the control is not valid. The message says what is wrong. |
411 |
{"error": "Content-Length is required"} |
The request has no Content-Length header. |
413 |
{"error": "body must be at most 4096 bytes"} |
The body is larger than 4096 bytes. |
Other responses:
| Status | When |
|---|---|
405 |
GET /control. The response has Allow: POST. |
404 |
A POST to any other path. |
A 202 means the server took the control. It does not mean the game has applied it yet. The change
shows in the next frame.
GET /contribute¶
Says whether the opt-in contribution mode is on, and its state. See
Community and data. Without --contribute the answer is
{"enabled": false}, and the other /contribute endpoints answer 404.
{
"enabled": true,
"consent": {"status": "draft", "version": "a1b2c3d4e5f6", "text": "..."},
"recording": false,
"contribution_id": null,
"games": 0,
"decisions": 0,
"error": null,
"folder": "/home/you/.local/share/chasetag-arena/contributions"
}
| Field | Meaning |
|---|---|
consent.status |
draft until the consent text has been reviewed, then final. |
consent.version |
A short hash of the text. Consent only counts for the version the player was shown. |
recording |
true while games are being recorded, after the player agreed and until they stop. |
contribution_id |
The random ID in the player's files, or null before consent. |
games, decisions |
What is saved on this computer. |
error |
Why recording stopped, if a write failed. |
GET /contribute/review¶
The recorded games exactly as they would be shared, as JSON Lines text. 409 if nothing has been
recorded.
GET /contribute/package¶
The most recently exported package, as a zip. 409 if none has been exported.
POST /contribute¶
Changes what is recorded. The body is a JSON object with an action:
| Action | Body | Effect |
|---|---|---|
consent |
{"action": "consent", "version": "a1b2c3d4e5f6"} |
Starts recording, from the next round. 409 if version is not the current consent version. |
stop |
{"action": "stop"} |
Stops recording and keeps what was saved. A round in progress is dropped. |
export |
{"action": "export"} |
Writes a package and describes it. 409 if no game has been recorded. |
withdraw |
{"action": "withdraw"} |
Stops recording and deletes the games, the consent record and the packages. |
These requests must come from the page itself. Each POST needs the header
X-Requested-With: chasetag-arena, and every /contribute request needs a Host and, if present, an
Origin that name this server. Anything else gets 403, so a web page on another site cannot start
recording. Other errors: 400 for a body that is not an object with a known action, 411 and
413 as for /control.