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.)
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:
15 Content-type: text/event-stream
16 Connection: keep-alive
17 Cache-Control: no-cache
19 and will keep the connection open to return events.
21 The following event types will be returned by the server:
25 WHEN: When a client first connects
27 PURPOSE: Describes all players in the game already
32 data: [{"id":1,"name":"Carl"},{"id":2,"name":"Kevin"}]
36 WHEN: When a player joins the game
41 data: {"id":3,"name":"Richard"}
45 WHEN: When a player leaves the game
54 WHEN: When client first connects and whenever game state changes
56 VALUES: Event gives both the old and new state. Game state
57 Each will be one of the following:
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
67 data: {"old_state":"none","new_state":"join"}
70 data: {"old_state":"join","new_state":"reveal"}
72 TYPE: character-reveal
74 WHEN: Periodically during the "reveal" state of the game
78 event: character-reveal
79 data: {"character":"Albert Einstein"}
83 WHEN: When one player captures another
88 data: {"captor": 2, "captee": 1}
94 Behavior: Adds a new player with "name" and "character" and assigns an id. Also will add a new empire with empty "captured" array
96 Example data: { "name": "Carl", "character: "Elvis" }
102 Behavior: Removes an existing player with the given ID
108 When: Only valid when in game state of JOIN
110 Behavior: Change state to REVEAL; reveal character names to all clienta
116 When: Only valid when in game state of REVEAL
118 Behavior: Change game state to CAPTURE
124 Behavior: Removes all players (bulk deregister)
130 Behavior: Eliminates all current empire ownership so the existing
131 players can start a new game
137 Behavior: Indicate that empire ID1 has now captured ID2
143 Behavior: Indicate that empire ID is no longer captured (undoing a
150 Behavior: Returns a lists of all character names (in alphabetical order)
152 Example data: [ "Einstein", "Elvis", "Fred Flintstone" ]
158 Behavior: Shows which empires have been captured by other empires
160 Example data [ { "id": 1, "captures": [] },
161 { "id": 2, "captures": [1] },
162 { "id": 3, "captures": [4, 5, 6] },
163 { "id": 4, "captures": [2] },
164 { "id": 5, "captures": [] },
165 { "id": 6, "captures": [] } ]
171 Behavior: Gets a list of all the player objects (without their
174 Example data: [ { id: 1, name: "Carl" }, { id: 2, name: "Kevin" } ]
178 There's a sample server available at: https://families.cworth.org/api/
180 We plan to move this to https://empires.cworth.org at some point.