Giter Site home page Giter Site logo

passwordgame's Introduction

PasswordGame-Backend

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

Environment Variables

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

Deployment

To deploy this project, first install packages using

  npm i

Then start the server with

  npm start

API

Note: ?param implies param 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.

/room

  • POST /room/create - username, ?access, ?rounds
    • Create a room with creator as username.
    • access determines the type of room, may be private or public.
    • rounds implies the number of rounds in the game.
    • Returns the roomId and creator in the response JSON.
{
    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:
{
    success: boolean,
    message: {
        roomId: string,
        creator: string,
        hasStarted: boolean,
        players: [
            {
                username: string,
                points: string,
            },
            {
                username: string,
                points: string,
            },
        ],
    },
}

/game

  • POST /game/start - username, roomId, ?access, ?rounds
    • username must be the creator of the room.
    • Modifies access and rounds according to access and rounds.
    • 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 room roomId.
    • 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:
{
    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:
{
    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:
{
    success: true,
    message: {
        players: [
            {
                username: string,
                points: string,
            },
            {
                username: string,
                points: string,
            },
        ],
    },
}

passwordgame's People

Contributors

roerohan avatar aj1479 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.