]> git.cworth.org Git - lmno-api/blobdiff - api.text
Clarify that at client connection server may give multiple game-state events
[lmno-api] / api.text
index 91a390cb927e705a6aa7a85aeca8fb05b9189d2a..26f0a4d92f4e40ecf330b1832a5932208434a197 100644 (file)
--- a/api.text
+++ b/api.text
@@ -1,5 +1,98 @@
-Gameplay API endpoints (within a current game)
-==============================================
+Empires Game Protocol
+=====================
+Version: 0.6
+
+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: game-state
+
+       WHEN: When client first connects and whenever game state changes
+
+       VALUES: Event gives both the old and new state.
+               Each will be one of the following:
+
+               none: Pseudo-state used as old_state when game is started
+               join: Players are choosing characters and joining the game
+                reveal: Character names are being revealed to players
+                capture: Players are guessing characters in capture attempts
+
+       NOTE: When a client first connects, it may see multiple
+             game-state transitions, to transition step-by-step from
+             the initial state to the state of the current game. See
+             the example below which would be presented to a client
+             joining a game that is already in the "reveal state.
+
+       EXAMPLES:
+
+               event: game-state
+                data: {"old_state":"none","new_state":"join"}
+
+               event: game-state
+                data: {"old_state":"join","new_state":"reveal"}
+
+       TYPE: character-reveal
+
+       WHEN: Periodically during the "reveal" state of the game
+
+       EXAMPLE:
+
+               event: character-reveal
+                data: {"character":"Albert Einstein"}
+
+       TYPE: capture
+
+       WHEN: When one player captures another
+
+       EXAMPLE:
+
+               event: capture
+               data: {"captor": 2, "captee": 1}
+
 /register
 
     Method: POST
@@ -14,6 +107,22 @@ Gameplay API endpoints (within a current game)
 
     Behavior: Removes an existing player with the given ID
 
+/reveal
+
+    Method: POST
+
+    When: Only valid when in game state of JOIN
+
+    Behavior: Change state to REVEAL; reveal character names to all clienta
+
+/start
+
+    Method: POST
+
+    When: Only valid when in game state of REVEAL
+
+    Behavior: Change game state to CAPTURE
+
 /reset
 
     Method: POST
@@ -33,7 +142,7 @@ Gameplay API endpoints (within a current game)
 
     Behavior: Indicate that empire ID1 has now captured ID2
 
-/escape/<ID>
+/liberate/<ID>
 
     Method: POST
 
@@ -54,12 +163,12 @@ Gameplay API endpoints (within a current game)
 
     Behavior: Shows which empires have been captured by other empires
 
-    Example data [ { "id": 1, "captured": [] },
-                   { "id": 2, "captured": [1] },
-                   { "id": 3, "captured": [4, 5, 6] },
-                   { "id": 4, "captured": [2] },
-                   { "id": 5, "captured": [] },
-                   { "id": 6, "captured": [] } ]
+    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
 
@@ -70,14 +179,8 @@ Gameplay API endpoints (within a current game)
 
     Example data: [ { id: 1, name: "Carl" }, { id: 2, name: "Kevin" } ]
 
-/players/<id>
-
-    Method: GET
-
-    Behavior: Get a single player by its id
-
 Server
 ======
-There's a sample server available at: https://families.cworth.org/
+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.