Networking Plan - PatrickMalara/battle GitHub Wiki

Questions Answered... hopefully

  • How does a player create a match?
  • How does a player join a match?
  • How does a match progress?
  1. [UI](login screen) User login (through a form)
  2. [UI -> API] uses POST /battle/login
  3. [API] authenticates the user and returns (user_id) of the User who logged in
  4. [UI](login screen -> rooms screen) Retrieves the user_id from the API call and then the [UI] screen changes to a "Waiting Room/Lobby"
  5. [UI](rooms screen) the user will have the option to create a room or join a room (in this user-flow we create a room)
  6. [UI -> API] uses CREATE /battle/match
  7. [API] creates a match in the Database. Then returns the newly created match's id.
  8. [UI](rooms screen -> lobby screen) Retrieved the match_id from the API call and then the screen changes to "Waiting Room/Lobby"
  9. [UI](rooms screen -> lobby screen) Retrieves the user_id from the API call and then the [UI] screen changes to a "Waiting Room/Lobby"
  10. [UI](lobby screen) User waits for an opponent
  1. At this point another User(the anticipated opponent) will have to login, type the room name, and then the use will join the Match
  2. [API] We haven't touched on JOINING a room, just creating. The difference is that we do PATCH battles/match and update the second user_id as well as the status = "In Progress"
  1. [API] in the API... apart of the PATCH battle/match we emit an event. Event matchStarted that returns the match_id.
  2. [UI](lobby screen -> game screen) the UI listens to an event called matchStarted and if the match_id === match_id of the lobby, then the UI transitions the lobby screen to the game screen we know so well :) -> this happens for both players
  3. [UI](game screen) a move is done by calling the API, POST battle/move
  4. [API] on battle/move we emit a 'move' event that returns the match_id, the board, and the user_id who made the move.
  5. [UI] if the user_id returned from the 'move' event is === to your user_id then its NOT youre turn. If !== then it IS your Turn.