npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

game_lobby_server

v1.4.0

Published

Server for Game Lobby practice project

Downloads

3

Readme

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