]> git.cworth.org Git - lmno-api/blob - api.text
Clarify that at client connection server may give multiple game-state events
[lmno-api] / api.text
1 Empires Game Protocol
2 =====================
3 Version: 0.6
4
5 For a specific game the following API endpoints are defined.
6 (Note: Only the trailing portion of the API URI is provided here.
7  The preceding portions of the path must be determined externally.)
8
9 /events
10
11     This is a server-sent events stream that allows the server to push
12     game-related events to clients. When a client connects to this API
13     endpoint the server will return a header that includes:
14
15         Content-type: text/event-stream
16         Connection: keep-alive
17         Cache-Control: no-cache
18
19     and will keep the connection open to return events.
20
21     The following event types will be returned by the server:
22
23         TYPE: players
24
25         WHEN: When a client first connects
26
27         PURPOSE: Describes all players in the game already
28
29         EXAMPLE:
30
31                 event: players
32                 data: [{"id":1,"name":"Carl"},{"id":2,"name":"Kevin"}]
33
34         TYPE: player-join
35
36         WHEN: When a player joins the game
37
38         EXAMPLE:
39
40                 event: player-join
41                 data: {"id":3,"name":"Richard"}
42
43         TYPE: player-leave
44
45         WHEN: When a player leaves the game
46
47         EXAMPLE:
48
49                 event: player-leave
50                 data: {"id":3}
51
52         TYPE: game-state
53
54         WHEN: When client first connects and whenever game state changes
55
56         VALUES: Event gives both the old and new state.
57                 Each will be one of the following:
58
59                 none: Pseudo-state used as old_state when game is started
60                 join: Players are choosing characters and joining the game
61                 reveal: Character names are being revealed to players
62                 capture: Players are guessing characters in capture attempts
63
64         NOTE: When a client first connects, it may see multiple
65               game-state transitions, to transition step-by-step from
66               the initial state to the state of the current game. See
67               the example below which would be presented to a client
68               joining a game that is already in the "reveal state.
69
70         EXAMPLES:
71
72                 event: game-state
73                 data: {"old_state":"none","new_state":"join"}
74
75                 event: game-state
76                 data: {"old_state":"join","new_state":"reveal"}
77
78         TYPE: character-reveal
79
80         WHEN: Periodically during the "reveal" state of the game
81
82         EXAMPLE:
83
84                 event: character-reveal
85                 data: {"character":"Albert Einstein"}
86
87         TYPE: capture
88
89         WHEN: When one player captures another
90
91         EXAMPLE:
92
93                 event: capture
94                 data: {"captor": 2, "captee": 1}
95
96 /register
97
98     Method: POST
99
100     Behavior: Adds a new player with "name" and "character" and assigns an id. Also will add a new empire with empty "captured" array
101
102     Example data: { "name": "Carl", "character: "Elvis" }
103
104 /deregister/<ID>
105
106     Method: POST
107
108     Behavior: Removes an existing player with the given ID
109
110 /reveal
111
112     Method: POST
113
114     When: Only valid when in game state of JOIN
115
116     Behavior: Change state to REVEAL; reveal character names to all clienta
117
118 /start
119
120     Method: POST
121
122     When: Only valid when in game state of REVEAL
123
124     Behavior: Change game state to CAPTURE
125
126 /reset
127
128     Method: POST
129
130     Behavior: Removes all players (bulk deregister)
131
132 /restart
133
134     Method: POST
135
136     Behavior: Eliminates all current empire ownership so the existing
137     players can start a new game
138
139 /capture/<ID1>/<ID2>
140
141     Method: POST
142
143     Behavior: Indicate that empire ID1 has now captured ID2
144
145 /liberate/<ID>
146
147     Method: POST
148
149     Behavior: Indicate that empire ID is no longer captured (undoing a
150     previous /capture)
151
152 /characters
153
154     Method: GET
155
156     Behavior: Returns a lists of all character names (in alphabetical order)
157
158     Example data: [ "Einstein", "Elvis", "Fred Flintstone" ]
159
160 /empires
161
162     Method: GET
163
164     Behavior: Shows which empires have been captured by other empires
165
166     Example data [ { "id": 1, "captures": [] },
167                    { "id": 2, "captures": [1] },
168                    { "id": 3, "captures": [4, 5, 6] },
169                    { "id": 4, "captures": [2] },
170                    { "id": 5, "captures": [] },
171                    { "id": 6, "captures": [] } ]
172
173 /players
174
175     Method: GET
176
177     Behavior: Gets a list of all the player objects (without their
178     character names)
179
180     Example data: [ { id: 1, name: "Carl" }, { id: 2, name: "Kevin" } ]
181
182 Server
183 ======
184 There's a sample server available at: https://families.cworth.org/api/
185
186 We plan to move this to https://empires.cworth.org at some point.