Backend repository for Password game, a real-time password guessing game written in Node.js and Socket.io.
Frontend repository: https://github.com/roerohan/Password
To run this project, you will need to add the following environment variables to your .env file
PORT
MONGO_URL
PASSWORD_DB
ROUNDS
DURATION
NODE_ENV
To deploy this project, first install packages using
npm i
Then start the server with
npm start
Note:
?param
impliesparam
is optional.
Note: Format: <REQUEST-TYPE> <ROUTE> - <PARAMS>
- All routes return a JSON with the following format:
{
success: boolean,
message: string | object,
}
success
indicates if a request passed or failed.message
indicates 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
. access
determines the type of room, may beprivate
orpublic
.rounds
implies the number of rounds in the game.- Returns the
roomId
andcreator
in the response JSON.
- Create a room with creator as
{
success: boolean,
message: {
roomId: string,
creator: string,
},
}
GET /room/join/:roomId - username
- Add user
username
to the room. - Returns a JSON of the following format:
- Add user
{
success: boolean,
message: {
roomId: string,
creator: string,
hasStarted: boolean,
players: [
{
username: string,
points: string,
},
{
username: string,
points: string,
},
],
},
}
POST /game/start - username, roomId, ?access, ?rounds
username
must be the creator of the room.- Modifies access and rounds according to
access
androunds
. - 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: string,
},
{
username: string,
points: string,
},
],
},
}
POST /game/next - roomId
- Generates a new password in the backend for the room, returns the new passwordHolder and the length of the new password.
- Returns a JSON of the following format:
{
success: boolean,
message: {
currentRound: number,
passwordHolder: string,
passwordLength: number,
previousPassword: string,
players: [
{
username: string,
points: string,
},
{
username: string,
points: string,
},
],
},
}
POST /game/attempt - roomId, username, password
- Matches the requested
password
with the current password for the roomroomId
. - If they don't match, returns
{ success: true, message: incorrect }
. - Otherwise, adds user to list of solvers for the current password and awards the user with points.
- Returns a JSON of the format:
- Matches the requested
{
success: boolean,
message: {
passwordHolder: string,
passwordLength: number,
solvedBy: string[],
players: [
{
username: string,
points: string,
},
{
username: string,
points: string,
},
],
},
}
POST /game/hint - roomId, username, hint
- Adds the hint to the
hints
array 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:
- Ends the game for
{
success: true,
message: {
players: [
{
username: string,
points: string,
},
{
username: string,
points: string,
},
],
},
}