Empires Game Protocol ===================== Version: 0.3 For a specific game the following API endpoints are defined. (Note: Only the trailing portion of the API URI is provided here. The preceding portions of the path must be determined externally.) /events This is a server-sent events stream that allows the server to push game-related events to clients. When a client connects to this API endpoint the server will return a header that includes: Content-type: text/event-stream Connection: keep-alive Cache-Control: no-cache and will keep the connection open to return events. The following event types will be returned by the server: TYPE: players WHEN: When a client first connects PURPOSE: Describes all players in the game already EXAMPLE: event: players data: [{"id":1,"name":"Carl"},{"id":2,"name":"Kevin"}] TYPE: player-join WHEN: When a player joins the game EXAMPLE: event: player-join data: {"id":3,"name":"Richard"} TYPE: player-leave WHEN: When a player leaves the game EXAMPLE: event: player-leave data: {"id":3} TYPE: capture WHEN: When one player captures another EXAMPLE: event: capture data: {"captor": 2, "captee": 1} /register Method: POST Behavior: Adds a new player with "name" and "character" and assigns an id. Also will add a new empire with empty "captured" array Example data: { "name": "Carl", "character: "Elvis" } /deregister/ Method: POST Behavior: Removes an existing player with the given ID /reset Method: POST Behavior: Removes all players (bulk deregister) /restart Method: POST Behavior: Eliminates all current empire ownership so the existing players can start a new game /capture// Method: POST Behavior: Indicate that empire ID1 has now captured ID2 /liberate/ Method: POST Behavior: Indicate that empire ID is no longer captured (undoing a previous /capture) /characters Method: GET Behavior: Returns a lists of all character names (in alphabetical order) Example data: [ "Einstein", "Elvis", "Fred Flintstone" ] /empires Method: GET Behavior: Shows which empires have been captured by other empires Example data [ { "id": 1, "captures": [] }, { "id": 2, "captures": [1] }, { "id": 3, "captures": [4, 5, 6] }, { "id": 4, "captures": [2] }, { "id": 5, "captures": [] }, { "id": 6, "captures": [] } ] /players Method: GET Behavior: Gets a list of all the player objects (without their character names) Example data: [ { id: 1, name: "Carl" }, { id: 2, name: "Kevin" } ] Server ====== There's a sample server available at: https://families.cworth.org/api/ We plan to move this to https://empires.cworth.org at some point.