WebSocket Documentation
- Values determined by the Server Stack are referred to as
[from METHOD /endpoint] - Values determined by the player are referred to as
[from client] - Send requests to:
wss://w1ws57hjh0.execute-api.eu-central-1.amazonaws.com/prod/
If at any point you need to see what a given player’s object looks like, you can always send this query:
{"action":"check","type":"redis","method":"player","pid":"00001","gid":"18062024-2210"} where pid is playerID and gid is gameID.createGame
createGame creates an object in the elasticache-tax-game cache, with the key${gameID}. It also creates the first empty planet in the planets array (in the elasticache-tax-game cache with the key planets).
Required data
{"action":"game","type":"createGame","gameID":"18062024-1845","stageTime":20,"auditChance":0.25,"finePercent":0.15,"planetCollectionMultiplier":1.7,"taxRate":0.30, "declaredIncomePercent": 0.40, "incomeMax":1200, "incomeMin":600, "bankruptcyThreshold": 0, "generateNewIncomeEachRound": false}
Elasticache
Returns
joinGame
joinGame creates an object in the elasticache-tax-game cache, with the key${gameID}---${playerID}. It will return a generated role and planet to each connection (once the planet is established), and update the host with the new player (playerID and name).
When WebSockets receives the request, it scans
DynamoDBStack-WebsocketConnections87C62C57-1H8H09K1YWXHY table. If there is a record in the table with the same connectionId & gameID, it gets that object from Elasticache and returns the full item to the user.Required data
{"action":"game","type":"joinGame","gameID":"game-c3b4i7ybc","playerID":"001a","name":"Emma"}
New Connection
Elasticache: Role A
Role B
Role C
Returns
Each time a player sends a joinGame request, the host will receive the following string: {"type":"startGame","message":[{"planetID":"planet1","planetName":"Terralus","players":[{"connectionID":"ZqGUhc8pliACFpw=","playerID":"00001","playerName":"Emma","role":"A"},{"connectionID":"ZqGWHc1-FiACETQ=","playerID":"00002","playerName":"Jules","role":"B"},{"connectionID":"ZqGXndKyFiACEXA=","playerID":"00003","playerName":"Stevie","role":"C"}]}]}
Existing Connection DEPRECIATED
startGame
startGame goes through all of the planets in the elasticache-tax-game cache, ensures that there are no planets with an awkward amount of players (checks the last planet), and then sends each player their planet (name and ID) and role.- If there are two or less players, startGame reassigns each of them to an existing planet with the “B” role
- The existing planets are determined by the player’s position in the player array:
planetsObject[newestPlanet.players.indexOf(player)].players.push
- The existing planets are determined by the player’s position in the player array:
Required data
Each player receives:
The players array includes this player{"type":"startGame","message":{{"planetID":"planet1","planetName":"Soralia","playerRole":"C","players":["Emma","Jules","Steve","Thomas","Kelvin","Dana"]}}
startRound
It should be sent by the Host. Creates an array of items inDynamoDBStack-WebsocketConnections87C62C57-1H8H09K1YWXHY with the given gameID, and then sends each connection the response message.
Required data
Returns
To Host
To Players
stageChanges, handleStage, & startStage
stageChangesis sent by a player that needed to make an action during that stage:- At the end of stage 1, all “A” players should send a
stageChangesrequest - At the end of stage 2, all “B” and “C” players should send a
stageChangesrequest - At the end of stage 3, all players should send a
stageChangesrequest - At the end of stage 4, “C” players should send a
stageChangesrequest
- At the end of stage 1, all “A” players should send a
handleStageshould be sent by the Host when the stage is up (stageDuration has elapsed). All players will be alerted that they must send theirstageChangesrequest- This way, only one system is managing the time, and the WebSockets aren’t using up a massive amount of processing power while each connection waits for stageDuration to elapse before sending a response.
stageChanges
Response:{"type":"stageChanges","message":"OK"}
Stage 1
Stage 2
Stage 3
Stage 4
{"action":"game","type":"stageChanges","gameID":"18062024-2210","round":1,"stage":1,"playerID":"00001","planetID":"planet1","taxRate":0.7}
handleStage
Required Data
Returns to Host
Returns to Client
{"type":"handleStage","message":{"value":"TIME UP"}}
startStage
Required Data
To Host
After the last stage of the round (automatically calls endRound)
To Players - after stage 1
{"type":"startStage","message":{"round":1,"stage":2,"stageStartTime":"19/06/2024, 12:11:11","stageDuration":20,"taxRate":0.15}}
To Players - after stage 2
{"type":"startStage","message":{"round":1,"stage":3,"stageStartTime":"19/06/2024, 16:21:12","stageDuration":20,"bankrupt":false,"declared":[800,1100,600,600],"redistributable":3689}}
A Players | Bankrupt
{"type":"startStage","message":{"round":1,"stage":3,"stageStartTime":"19/06/2024, 16:21:12","stageDuration":20,"bankrupt":true}}
Other Players
{"type":"startStage","message":{"round":1,"stage":3,"stageStartTime":"19/06/2024, 16:21:12","stageDuration":20}}
To Players - after stage 3
A Players{"type":"startStage","message":{"round":1,"stage":4,"stageStartTime":"20/06/2024, 12:04:48","stageDuration":20,"updatedWealth":3850,"auditPool":850}}
B+C Players
{"type":"startStage","message":{"round":1,"stage":4,"stageStartTime":"20/06/2024, 12:04:48","stageDuration":20,"updatedWealth":137.8,"rebate":137.8}}

