Giter Club home page Giter Club logo

space-trader's Introduction

Space Trader

Student project - single player game with Node.js.

Setup

Docker setup

docker-compose up

Standard setup

npm install && npm run all

Requires connection with PostgreSQL database. Connection parameters can be passed in environment variables.

DBUSER - username, defaults to postgres
DBNAME - database name, defaults to postgres
DBPASS - password, defaults to postgres
DBHOST - PostgreSQL instance hostname, defaults to localhost
DBPORT - PostgreSQL instance port, defaults to 5432

This application requires tables st_user and st_game. Creates them, if they are not present in the schema.

API

POST /api/auth/login

Body schema:

{
  "type": "object",
  "properties": {
    "username": {"type": "string", "minLength": 1},
    "password": {"type": "string", "minLength": 1}
  },
  "additionalProperties": false,
  "required": ["username", "password"]
}

Authenticates request with given username and password. On success returns JSON object containing user uuid, user username and fresh JWT token. Example:

{
  "uuid": "958216fd-ae95-4de6-8d7a-df8c403153db",
  "username": "username",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiYjgwMWRhZDMtOWU4NC00MTIyLTgyNTQtZGRhZmM0MmQ2MDQ5IiwidXNlcm5hbWUiOiJvcmRkZW8iLCJpYXQiOjE1NjA1MjYxNTYsImV4cCI6MTU2MDk1ODE1Nn0.rppY8A2pbX0tthfzqxp9C-vAQYS_pzfyCzLwT4nOHeg"
}

In case of authentication failure returns 401.

POST /api/auth/register

Body schema same as above. Creates new user account with given username and password. On success returns JSON object containing user uuid and username.

{
  "uuid": "958216fd-ae95-4de6-8d7a-df8c403153db",
  "username": "username"
}

If given username is taken, returns 403.

GET /api/auth/check

Verifies JWT token sent in Authorizaton header. On failure returns 401.

GET /api/games

Returns list of all available games. For example:

[
  {
    "uuid": "958216fd-ae95-4de6-8d7a-df8c403153db",
    "name": "game1"
  },
  {
    "uuid": "1aede299-4ec2-40b2-9fd5-8bfad819b294",
    "name": "game2"
  }
]

POST /api/games

Creates new game. Requires multipart/form-data body format and fields name and state. Field name is used as the name of the new game. Contents of JSON file sent in field state is verified and saved as the initial state of the new game. Requires valid JWT token in Authorization header. In case of authentication failure returns 401.

GET /api/games/top

Returns at most 5 top scores (top score is tracked for each game independently). Records are ordered by scores descending. Example response:

[
  {
    "name": "game1",
    "player": "player1",
    "score": 56
  },
  {
    "name": "game2",
    "player": "player2",
    "score": 34
  },
  {
    "name": "game3",
    "player": "player3",
    "score": 23
  },
  {
    "name": "game3",
    "player": "player3",
    "score": 11
  },
  {
    "name": "game4",
    "player": "player4",
    "score": 4
  }
]

GET /api/games/:gameUUID

Returns initial state of the game.

POST /api/games/:gameUUID

Body schema:

{
  "type": "object",
  "properties": {
    "username": {"type": "string", "minLength": 1},
    "score": {"type": "integer", "minimum": 0}
  },
  "required": ["username", "score"],
  "additionalProperties": false
}

Preserves user score if it's a new top score for this game.

space-trader's People

Contributors

razz4780 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.