1.4.0 • Published 3 years ago

game_lobby_server v1.4.0

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

Game Lobby Server

A server for Interactive Frontend Development course project.

Usage

When imported as a library

game_lobby_server --help
game_lobby_server --delay=500 --port=8081 --failure-percentage=30

When used as a stand-alone

./bin/server.js --help
./bin/server.js --delay=500 --port=8081 --failure-percentage=30

or

yarn start

Endpoints

POST /games/

Request Body Parameters

  • type: String(guess_number | guess_word | hangman | rps / metronome / mathemagician)
  • frequency: Integer - Required only when type is metronome
  • rounds: Integer - Required only when type is _mathemagician__

Response {id, type, status}

  • id: String
  • type: String, echo of the submitted type
  • status: String(waiting_for_move)

OR

Response with status code 422 in case input parameters were invalid

Game type: mathemagician

Additional response fields:

  • nextExpression: {lhs, rhs, operator}
    • lhs: Integer
    • rhs: Integer
    • operator: One of '+', '-', '*', '/' (integer division)
    • correctAnswerLength: Integer. When expected answer is "-5" then answerLength is 2.
  • skipsRemaining: Integer

Game type: hangman

Additional response fields:

  • won: Boolean, false
  • wrongGuessCount: Integer, 0
  • letters: Array[String], list of letters in the target word, all letters are denoted with null

POST /games/:gameId/moves

Game type: mathemagician

Request Body parameters

  • guess: Integer | "skip"

Response {move, game}

  • move: correct, timeSpentMillis, nextExpression
    • timeSpentMillis: Integer
    • correct: Boolean
    • skipped: Boolean
  • game: `id, type, status}
    • id: String
    • type: String(mathemagician)
    • status: String(waiting_for_move | finished)
    • nextExpression: null if game finished or same structure as nextExpression in POST /games/ endpoint response
    • skipsRemaining: Integer
Game type: guess_number

Request Body Parameters

  • guess: Integer

Response {move, game}

  • move: {comparedToAnswer, guess}
    • comparedToAnswer: String(LT | GT | EQ)
    • guess: Integer, echo of the submitted guess
  • game: {id, type, status}
    • id: String
    • type: String(guess_number)
    • status: String(waiting_for_move | finished)
Game type: guess_word

Request Body Parameters

  • guess: String

Response {move, game}

  • move: {correct, letterMatches, guess}
    • correct: Boolean
    • letterMatches: Array[Boolean], true if character at position was correct, false otherwise
    • guess: String, echo of the submitted guess
  • game: {id, type, status}
    • id: String
    • type: String(guess_word)
    • status: String(waiting_for_move | finished)
Game type: hangman

Request Body Parameters

  • guess: String

Response:

  • id: String
  • type: String(hangman)
  • status: String(waiting_for_move | finished)
  • won: Boolean, whether the game has finished with a victory
  • wrongGuessCount: Integer, number of invalid guesses thus far
  • letters: Array[String], list of letters that have been already guessed, letters which have not been guessed are denoted with null
  • move: {matchedLetterCount, guess}
    • matchedLetterCount: Integer, how many letters of the target word matched the input
    • guess: String, echo of the submitted guess
Game type: rps

Request Body Parameters

  • guess: String

Response:

  • id: String
  • type: String(rps)
  • status: String(waiting_for_move | finished)
  • won: Boolean, whether the game has finished with a victory
  • move: {result, opposition, guess}
    • result: String(WIN, TIE, LOSS), result of the Rock-Paper-Scissors round
    • opposition: String(ROCK, PAPER, SCISSORS), the opposition for the round
    • guess: String, echo of the submitted guess

Game type: metronome

Additional response fields:

  • startTimeMillis: Integer
  • tries: Array[Try], list of metronome tries
  • Try: {miss}`
    • miss: Integer, number of milliseconds missed from desired frequency

POST /games/:gameId/moves

No parameters required

WebSocket API

Required query parameters

Pass query parameters in the URL when connection to the server, e.g connect to the following URL:

ws://localhost:8081/?playerName=foo

Required parameters:

  • playerName: String, the name the connecting player wants to use.

Error codes

If the connection cannot be accepted for any reason, the connection is closed with

  • code:4000, reason:'player-name-taken', if player is not allowed to connect due to the provided name not being available.

Messages

WebSocket API pushes messages as JSON objects encoded as UTF-8 strings.

The encoded JSON object has the following properties:

  • eventName: String, name of the event
  • payload: Object, payload of the event

Example frame that might be sent to a connection:

'{"eventName":"connection:accepted","payload":{"playerId":"b00e6b69-ae49-431f-8dbd-12d7b5c95153"}}'

The following events might be sent

  • connection:accepted: {playerId}, sent immediately after connection is opened.
    • playerId: String, an unique ID given to the connected player
  • online-players: Array[{id, name}], list of online players, sent whenever a player connects or disconnects.
    • id: String, unique identifier of the player
    • name: String, name of the player
1.4.0

3 years ago

1.3.0

5 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago