]> git.cworth.org Git - lmno-api/blob - tictactoe.txt
Document player-info, player-enter, and player-update events
[lmno-api] / tictactoe.txt
1 Tic Tac Toe Game Protocol
2 =========================
3 Note: All square numbers in the protol below are as follows:
4
5         0|1|2
6         -+-+-
7         3|4|5
8         -+-+-
9         6|7|8
10
11 For a specific game the following API endpoints are defined.
12 (Note: Only the trailing portion of the API URI is provided here.
13  The preceding portions of the path must be determined externally.)
14
15 /events
16
17     This is a server-sent events stream that allows the server to push
18     game-related events to clients. When a client connects to this API
19     endpoint the server will return a header that includes:
20
21         Content-type: text/event-stream
22         Connection: keep-alive
23         Cache-Control: no-cache
24
25     and will keep the connection open to return events.
26
27     The following event types will be returned by the server:
28
29         TYPE: game-info
30
31         WHEN: When a client first connects
32
33         WHAT: Static information about the game (will not change)
34
35         EXAMPLE:
36
37                 event: game-info
38                 data: {"id":"WXYZ","url":"https://lmno.games/WXYZ"}
39
40         TYPE: player-info
41
42         WHEN: When a client first connects
43
44         WHAT: Information about the current player (ID, name, and team)
45
46         NOTE: The player-info event is unique among player-* events in
47               that it only describes the player associated with the
48               current client connection. Meanwhile, player-enter and
49               player-update events can describe the current player or
50               any other. The player-info event is significant because
51               the client may not know its own name other than
52               receiving it here, (such as if the client offers up a
53               pre-existing cookie and the server uses that to return a
54               player name from a server-side session object).
55
56         EXAMPLE:
57
58                 event: player-info
59                 data: {"id":0,"name":"Carl","team":"X"}
60
61         TYPE: player-enter
62
63         WHEN: Whenever a new player enters the game. Also: these
64               events will be streamed out for all existing players
65               when a client first connects
66
67         WHAT: Information about the new player (ID, name, and team)
68
69         EXAMPLE:
70
71                 event: player-enter
72                 data: {"id":1,"name":"Stacy","team":"O"}
73
74         TYPE: player-update
75
76         WHEN: Whenever a player updates their information
77
78         WHAT: All information about the updating player. The ID value
79               cannot be changed, so it can be used by the client to
80               know which player object to update. Player may change
81               either their name, their team, or both.
82
83         EXAMPLE:
84
85                 event: player-update
86                 data: {"id":0,"name":"Carl Worth","team":"O"}
87
88         TYPE: game-state
89
90         WHEN: When a client first connects
91
92         WHAT: Snapshot of the current dynamic game state
93
94         EXAMPLE:
95
96                 event: game-state
97                 data: {"moves":[0,8],"board":["X","","","","","","","","O"],"next_player":"X"}
98
99         TYPE: move
100
101         WHEN: When a client (maybe yourself) issues a legal move
102
103         EXAMPLE:
104
105                 event: move
106                 data: 4
107
108 /move
109
110     Method: POST
111
112     Behavior: Adds a new move to the game
113
114     Example data: { "move": 1 }