A server for Interactive Frontend Development course project.
game_lobby_server --help
game_lobby_server --delay=500 --port=8081 --failure-percentage=30
./bin/server.js --help
./bin/server.js --delay=500 --port=8081 --failure-percentage=30
or
yarn start
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
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.
- lhs:
- skipsRemaining:
Integer
Additional response fields:
- won:
Boolean
, false - wrongGuessCount:
Integer
, 0 - letters:
Array[String]
, list of letters in the target word, all letters are denoted withnull
Request Body parameters
- guess:
Integer
| "skip"
Response {move, game}
- move:
correct, timeSpentMillis, nextExpression
- timeSpentMillis:
Integer
- correct:
Boolean
- skipped:
Boolean
- timeSpentMillis:
- game: `id, type, status}
- id:
String
- type:
String
(mathemagician) - status:
String
(waiting_for_move | finished) - nextExpression:
null
if game finished or same structure asnextExpression
in POST /games/ endpoint response - skipsRemaining:
Integer
- id:
Request Body Parameters
- guess:
Integer
Response {move, game}
- move:
{comparedToAnswer, guess}
- comparedToAnswer:
String
(LT | GT | EQ) - guess:
Integer
, echo of the submitted guess
- comparedToAnswer:
- game:
{id, type, status}
- id:
String
- type:
String
(guess_number) - status:
String
(waiting_for_move | finished)
- id:
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
- correct:
- game:
{id, type, status}
- id:
String
- type:
String
(guess_word) - status:
String
(waiting_for_move | finished)
- id:
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 withnull
- move:
{matchedLetterCount, guess}
- matchedLetterCount:
Integer
, how many letters of the target word matched the input - guess:
String
, echo of the submitted guess
- matchedLetterCount:
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
- result:
Additional response fields:
- startTimeMillis:
Integer
- tries:
Array[Try]
, list of metronome tries - Try: {miss}`
- miss:
Integer
, number of milliseconds missed from desired frequency
- miss:
No parameters required
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.
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.
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
- playerId:
- 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
- id: