Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API endpoint for starting a game #12

Closed
metalalive opened this issue Oct 22, 2023 · 6 comments
Closed

Add API endpoint for starting a game #12

metalalive opened this issue Oct 22, 2023 · 6 comments
Assignees
Labels
backend dev For back-end development related to this codebase feature For those who propose to add new feature or modify existing features software design

Comments

@metalalive
Copy link
Collaborator

metalalive commented Oct 22, 2023

Overview

The endpoint is in current Open API doc :

/games/{gameId}/start , PATCH method , no request body

The backend service will :

  • transition internal state of game model to start-playing , subsequent configuration will be rejected, such as switch to different investigator.
  • forward the same request body , emit game-start event with it to all other players
  • response body of the REST endpoint should be empty

I'll modify request body of the REST endpoint to something like :

{"player_id":"xxyy123456"}

Since the endpoint needs to know which player triggers the start button

Question (Answered / Closed)

what is the effect of the endpoint ? here are 2 options :

  • the game starts immediately as soon as any player in a game calls the API endpoint
  • the game starts ONLY after all players in a game call the API endpoint <-- OK

Then both of the options should trigger event to socket.io server, which notifies other players the game has started.


c.c. @wingtkw,
For those still interested with the game dev, please take a look,
feedback or suggestion are welcome.

I am working on this GitHub Issue ,
It is simply creating new endpoint and a use-case class with empty logic,
left rest of detail to game domain model.

@metalalive metalalive added feature For those who propose to add new feature or modify existing features backend dev For back-end development related to this codebase software design labels Oct 22, 2023
@metalalive metalalive changed the title add API endpoint for showing investigators order add API endpoint for showing investigators order of specific game Oct 22, 2023
@metalalive metalalive changed the title add API endpoint for showing investigators order of specific game Add API endpoint for starting a game Nov 14, 2023
@metalalive
Copy link
Collaborator Author

Is there anyone who can discuss and work on the issue together ?

@wingtkw
Copy link
Collaborator

wingtkw commented Dec 13, 2023

It's better for all the players to call the endpoint to at least they are not afk and will join the game

@metalalive
Copy link
Collaborator Author

OK , I can take this after #37 ,

@metalalive metalalive self-assigned this Feb 7, 2024
@wingtkw
Copy link
Collaborator

wingtkw commented Feb 22, 2024

So you will try to use the player ID to find which room game that you should mark it as start
Is that correct?

@metalalive
Copy link
Collaborator Author

metalalive commented Feb 23, 2024

Hi, wingtkw

Yes , due to the fact custom data like player ID cannot be embedded in authentication token (JWT) provided by the Lobby Platform, I would consider to add the field to the request body.

  • In the Player domain model, there should be a flag indicating whether or not the player is ready to start ,
  • After all players of the same game set that flag the corresponding Game domain model starts initialization other elements such as playing cards, maps (e.g. randomly assign number of cultists), status of players (e.g. sanity point) .
  • Note we can discuss the domain-layer detail in another github issue Domain models for starting a game #13

Also note another REST endpoint /games/{gameId}/investigator in the API doc also has player_id field in its request body.

metalalive added a commit that referenced this issue Feb 23, 2024
- forward the request to relevant socket.io event `game-start`
- the use-case layer simply invokes `Game.start(player-id)`

TODO
- set up ready flag in `Player` model, avoid subsequent configuration
  after the flag is set
- update Open API spec

Signed-off-by: T.H. <[email protected]>
metalalive added a commit that referenced this issue Feb 23, 2024
@metalalive
Copy link
Collaborator Author

Thanks wingtkw for the approval.
Anyone who needs to modify the endpoint can reopen this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend dev For back-end development related to this codebase feature For those who propose to add new feature or modify existing features software design
Projects
None yet
Development

No branches or pull requests

2 participants