]> git.cworth.org Git - empires-api/blob - empires.txt
Document player-info, player-enter, and player-update events
[empires-api] / empires.txt
1 Empires Game Protocol
2 =====================
3 Version: 0.9
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-phase
53
54         WHEN: When client first connects and whenever game phase changes
55
56         VALUES: Event gives both the old and new phase.
57                 Each will be one of the following:
58
59                 none: Pseudo-phase used as old_phase 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-phase transitions, to transition step-by-step from
66               the initial phase to the phase 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 phase.
69
70         EXAMPLES:
71
72                 event: game-phase
73                 data: {"old_phase":"none","new_phase":"join"}
74
75                 event: game-phase
76                 data: {"old_phase":"join","new_phase":"reveal"}
77
78         TYPE: character-reveal
79
80         WHEN: Periodically during the "reveal" phase 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
101     assigns an id. Also will add a new empire with empty "captured"
102     array. Returns the numeric ID of the new player.
103
104     Note: If the client supports cookies and has previously set a
105     nickname in the current session via the upper-level /profile API,
106     then the name can be omitted from the data here and the profile
107     nickname will be used instead.
108
109     Example data: { "name": "Carl", "character: "Elvis" }
110
111     Example return data: 2
112
113 /deregister/<ID>
114
115     Method: POST
116
117     Behavior: Removes an existing player with the given ID
118
119 /spectator
120
121     Method: POST
122
123     Behavior: Add a new spectator with the given name, assigning and
124     returning an ID for the spectator.
125
126     Note: If the client supports cookies and has previously set a
127     nickname in the current session via the upper-level /profile API,
128     then the name can be omitted from the data here and the profile
129     nickname will be used instead.
130
131     Example data: { "name": "Carl" }
132
133     Example return data: 23
134
135 /spectator/<ID>
136
137     Method: DELETE
138
139     Behavior: Remove an existing spectator with the given ID
140
141 /reveal
142
143     Method: POST
144
145     When: Only valid when in game phase of JOIN
146
147     Behavior: Change phase to REVEAL; reveal character names to all clienta
148
149 /start
150
151     Method: POST
152
153     When: Only valid when in game phase of REVEAL
154
155     Behavior: Change game phase to CAPTURE
156
157 /reset
158
159     Method: POST
160
161     Behavior: Removes all players (bulk deregister)
162
163 /restart
164
165     Method: POST
166
167     Behavior: Eliminates all current empire ownership so the existing
168     players can start a new game
169
170 /capture/<ID1>/<ID2>
171
172     Method: POST
173
174     Behavior: Indicate that empire ID1 has now captured ID2
175
176 /liberate/<ID>
177
178     Method: POST
179
180     Behavior: Indicate that empire ID is no longer captured (undoing a
181     previous /capture)
182
183 /characters
184
185     Method: GET
186
187     Behavior: Returns a lists of all character names (in alphabetical order)
188
189     Example data: [ "Einstein", "Elvis", "Fred Flintstone" ]
190
191 /empires
192
193     Method: GET
194
195     Behavior: Shows which empires have been captured by other empires
196
197     Example data [ { "id": 1, "captures": [] },
198                    { "id": 2, "captures": [1] },
199                    { "id": 3, "captures": [4, 5, 6] },
200                    { "id": 4, "captures": [2] },
201                    { "id": 5, "captures": [] },
202                    { "id": 6, "captures": [] } ]
203
204 /spectators
205
206     Method: GET
207
208     Behavior: Gets a list of all spectators. A spectator is someone
209     who has started viewing the game (and stated their own
210     name) but isn't directly involved in the game.
211
212     Example data: [ { id: 1, name: "Richard"}, { id: 2, name: "Nancy"} ]
213
214     Note: The IDs of spectators and players are unrelated. If a person
215     initially joins as a spectator and then later joins the game as a
216     player, an unrelated player ID will be generated. From the
217     server's point of view, the events of a spectator leaving and a
218     player joining that happens to have the same name---those two
219     events have nothing to do with each other.
220
221 /players
222
223     Method: GET
224
225     Behavior: Gets a list of all the player objects (without their
226     character names). A player is someone who is registered a
227     character choice to participate in the game.
228
229     Example data: [ { id: 1, name: "Carl" }, { id: 2, name: "Kevin" } ]
230
231 Server
232 ======
233 There's a sample server available at: https://families.cworth.org/api/
234
235 We plan to move this to https://empires.cworth.org at some point.