Backend for Password game.
Frontend Repo: https://github.com/roerohan/Password
Note:
?paramimpliesparamis optional.
Note: Format: <REQUEST-TYPE> <ROUTE> - <PARAMS>
- All routes return a JSON with the following format:
{
success: boolean,
message: string | object,
}successindicates if a request passed or failed.messageindicates why a request failed, or stores the response if the operation was successful.
POST /room/create - username, ?access, ?rounds- Create a room with creator as
username. accessdetermines the type of room, may beprivateorpublic.roundsimplies the number of rounds in the game.- Returns the
roomIdandcreatorin the response JSON.
- Create a room with creator as
{
success: boolean,
message: {
roomId: string,
creator: string,
players: [
{
username: string,
points: number,
},
],
},
}GET /room/join/:roomId - username- Add user
usernameto the room. - Returns a JSON of the following format:
- Add user
{
success: boolean,
message: {
roomId: string,
creator: string,
hasStarted: boolean,
player: {
username: string,
points: 0,
}
players: [
{
username: string,
points: number,
},
{
username: string,
points: number,
},
],
},
}POST /game/start - username, roomId, ?access, ?roundsusernamemust be the creator of the room.- Modifies access and rounds according to
accessandrounds. - Starts the game for room
roomId. - Returns a JSON of the following format:
{
success: boolean,
message: {
hasStarted: boolean,
rounds: number,
currentRound: number,
players: [
{
username: string,
points: number,
},
{
username: string,
points: number,
},
],
},
}POST /game/next - roomId, username- Generates a new password in the backend for the room, returns the new passwordHolder and the length of the new password.
currentPasswordis sent only when theusernameis the same as thepasswordHolder.- Returns a JSON of the following format:
{
success: boolean,
message: {
currentRound: number,
rounds: number,
passwordHolder: string,
passwordLength: number,
previousPassword: string,
currentPassword: string,
roundEnd: number,
players: [
{
username: string,
points: number,
},
{
username: string,
points: number,
},
],
},
}POST /game/hint - roomId, username, hint- Adds the hint to the
hintsarray for the current round. - Returns a JSON of the format:
- Adds the hint to the
{
success: boolean,
message: {
hints: array,
passwordHolder: string,
},
}
``
- `POST /game/end - roomId`
* Ends the game for `roomId`.
* Deletes data pertaining to `roomId`.
* Returns a JSON of the form:
```typescript
{
success: true,
message: {
players: [
{
username: string,
points: number,
},
{
username: string,
points: number,
},
],
},
}- join
- message
- start
- hint
- disconnect