X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=api.text;h=b1a8f798175a7e89d644c2165a8225c7ff75a62c;hb=d25316422d7d9069626b9f09f630155f30534938;hp=f4ea703d3cd33d49f30845a5646eb54bae3f04d1;hpb=9e13e7ccf1313d83e3d253a2c490988ff3d2b833;p=empires-api diff --git a/api.text b/api.text index f4ea703..b1a8f79 100644 --- a/api.text +++ b/api.text @@ -1,5 +1,92 @@ -Gameplay API endpoints (within a current game) -============================================== +Empires Game Protocol +===================== +Version: 0.5 + +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. Game 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 + + 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 +101,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