This is how data flows through out system from a technological point of view. We have a NextJS frontend, that communicate to AWS Lambda functions via AWS API Gateway. We are utilizing various other AWS services; such as AWS DynamoDB, AWS ElastiCache and AWS Cognito.
Web SocketOnce a game has been created, the user will need to make a request to the WebSocket server that links the gameID to the user’s connection ID (provided by WebSockets, not part of the request body) and marks this user as the host.
//Make sure you match the role capitalization.{ action: "game", type: "createGame", gameID: GameID, role: Host //any role other than 'Host' will return 401 UNAUTHORIZED}
This will then go through the connection table, getting all of the connection ID’s for the provided game ID. It will then broadcast a message out to all those clients saying that the game is about to start.
The game will be managed by the host, so that means all actions will be initiated by the host. All starting round messages will be triggered by the host. The host as well as the web socket server should always remain in sync with the data, but the host is final source of data. That means the host will be the timer of the rounds, as well as triggering the respective messages.There will need to be a timer running on the hosts client that keeps track of how long things are. We could even look at providing toast notifications about how much time is remaining, but that is a QOL for later.The hosts client will be the initator of all the web sockets in relating to the rounds.If the current round is greater than 1, it sound process the already existing games from the ElastiCache. It should process all of them and then do one large batch update to the DynamoDB. Have a look at Process Round.Web SocketA start round message will be sent to all players in the game. It will include the round number (the round that is starting), when the round is starting and the duration of the round (in seconds).
This request will be initated by the game host and broadcast to all players of the game that the round is over and that they should send their data to the server.Web Socket to ClientRequest initated by the game host, indicating that the round has ended. For this, there is X amount of time (represented in seconds), where the player - whatever their role - will do their actions relating to their role. Such as deciding the tax rate, reimbursing roles and handling audits. The player (role B and C) will also have a chance to be audited. That all gets dealt with during this time period.
When a player sends their data in, it is simply just written to an ElastiCache instance, where it will be processed later on by the Process Round RESTful route.
When the game is finished, players should be displayed information and statistics. More information to come.RequestResponseWeb SocketShould broadcast to all connected clients that the game has been finished.
Restful API route to process the previous round. Will fetch all player data from the ElasticCache, process it and then batch update the DynamoDB for the current.RequestGET /process/:gameID/:roundNumberResponse200 OK
Returns the game object as CSVRequestGET /games/:gameID/csvResponseThe game object as CSV with the “Content-Type” as “text/csv”.
"gameID","data","playerID""624764","{""wealth"":[],""income"":[],""role"":"""",""planet"":[],""playerCount"":[],""declaredIncome"":[],""redistributedWealth"":[],""taxRate"":[],""audit"":[],""name"":""Uncle Fred"",""rank"":[],""id"":""c09fbeb1-1b2c-4146-a21d-ba048702cb8e"",""bankrupt"":[]}","c09fbeb1-1b2c-4146-a21d-ba048702cb8e""624764","{""wealth"":[],""income"":[],""role"":"""",""planet"":[],""playerCount"":[],""declaredIncome"":[],""redistributedWealth"":[],""taxRate"":[],""audit"":[],""name"":""Bob is your uncle!"",""rank"":[],""id"":""f11c8ece-9df0-4db8-b91d-2c22d7872e39"",""bankrupt"":[]}","f11c8ece-9df0-4db8-b91d-2c22d7872e39"