]> git.cworth.org Git - lmno-api/blob - api.text
Add "/reveal","/start" endpoints and "game-state","character-reveal" events
[lmno-api] / api.text
1 Empires Game Protocol
2 =====================
3 Version: 0.4
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: Game state will be one of the following:
57
58                 JOIN: Players are choosing characters and joining the game
59                 REVEAL: Character names are being revealed to players
60                 CAPTURE: Players are guessing characters in capture attempts
61
62         EXAMPLE:
63
64                 event: game-state
65                 data: {"state":"REVEAL"}
66
67         TYPE: character-reveal
68
69         WHEN: Periodically during the REVEAL state of the game
70
71         EXAMPLE:
72
73                 event: character-reveal
74                 data: {"character":"Albert Einstein"}
75
76         TYPE: capture
77
78         WHEN: When one player captures another
79
80         EXAMPLE:
81
82                 event: capture
83                 data: {"captor": 2, "captee": 1}
84
85 /register
86
87     Method: POST
88
89     Behavior: Adds a new player with "name" and "character" and assigns an id. Also will add a new empire with empty "captured" array
90
91     Example data: { "name": "Carl", "character: "Elvis" }
92
93 /deregister/<ID>
94
95     Method: POST
96
97     Behavior: Removes an existing player with the given ID
98
99 /reveal
100
101     Method: POST
102
103     When: Only valid when in game state of JOIN
104
105     Behavior: Change state to REVEAL; reveal character names to all clienta
106
107 /start
108
109     Method: POST
110
111     When: Only valid when in game state of REVEAL
112
113     Behavior: Change game state to CAPTURE
114
115 /reset
116
117     Method: POST
118
119     Behavior: Removes all players (bulk deregister)
120
121 /restart
122
123     Method: POST
124
125     Behavior: Eliminates all current empire ownership so the existing
126     players can start a new game
127
128 /capture/<ID1>/<ID2>
129
130     Method: POST
131
132     Behavior: Indicate that empire ID1 has now captured ID2
133
134 /liberate/<ID>
135
136     Method: POST
137
138     Behavior: Indicate that empire ID is no longer captured (undoing a
139     previous /capture)
140
141 /characters
142
143     Method: GET
144
145     Behavior: Returns a lists of all character names (in alphabetical order)
146
147     Example data: [ "Einstein", "Elvis", "Fred Flintstone" ]
148
149 /empires
150
151     Method: GET
152
153     Behavior: Shows which empires have been captured by other empires
154
155     Example data [ { "id": 1, "captures": [] },
156                    { "id": 2, "captures": [1] },
157                    { "id": 3, "captures": [4, 5, 6] },
158                    { "id": 4, "captures": [2] },
159                    { "id": 5, "captures": [] },
160                    { "id": 6, "captures": [] } ]
161
162 /players
163
164     Method: GET
165
166     Behavior: Gets a list of all the player objects (without their
167     character names)
168
169     Example data: [ { id: 1, name: "Carl" }, { id: 2, name: "Kevin" } ]
170
171 Server
172 ======
173 There's a sample server available at: https://families.cworth.org/api/
174
175 We plan to move this to https://empires.cworth.org at some point.