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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mission-game-server

v0.0.0

Published

Web service/module for a mission-based deception game

Downloads

8

Readme

mission-game-server

Web service/module for a mission-based deception game

Installation

npm install --save mission-game-server

If running as a microservice with default options, install globally instead

npm install -g mission-game-server

Usage

Standalone Web Service

mission-game-server --port=XXXX

Module

You can configure your own server instance by importing the package

const { ConnectionController, GameService, LobbyService } = require('mission-game-server');

ConnectionController manages Web Socket connections and responds to user actions. If used, it will also instantiate GameService and LobbyService. Use this approach if you want to use a different logger or a custom UserService.

const socketIO = require('socket.io');
const { ConnectionController } = require('mission-game-server');
const io = socketIO(myExpressServer);

ConnectionController.listen(io, {
    logger: myLogger,
    UserService: myUserService
});

If writing your own controller (e.g. if not using Web Sockets), instantiate GameService and (possibly) LobbyService. You must pass a UserService and a logger to each.

const gameService = GameService(myUserService, myLogger);
const lobbyService = LobbyService(myUserService, myLogger);

gameService.addEventListener('eventType', ...);
lobbyService.addEventListener('eventType', ...);

ConnectionController API

The ConnectionController creates a unique "account" for each connection. It manages user actions and periodicall sends lobby and game updates through the appropriate users' connections. "Request" payloads and "response" payloads are documented separately, as not all user actions will generate a response and not all responses are caused by a specific user action

Actions

Change Username

socket.emit('userdata', {username: 'New Name'});

Update Global Position

The LobbyService uses GPS for local matchmaking

geolocation.getCurrentPosition(coords => {
    socket.emit('userdata', {coords});
});

Host a Game

Hosts have 3 options for creating a game:

  • Local: Only players within a small geographic radius of the host will see the game in the lobby listing. Clients must provide the game ID to join
  • Password: Anyone with the password may join through the lobby
  • Link: The game ID is exposed in a link. Clients must provide the game ID to join.
socket.emit('lobby', {
    action: 'host',
    room: {
        type: 'local' | 'password' | 'link',
        password: 'required only for password games'
    }
});

Join a Game

socket.emit('lobby', {
    action: 'join',
    id: 'A23FDX',
    password: 'required only for password games'
});

Start Hosted Game

socket.emit('lobby', {
    action: 'start'
});

Only the host of a game may do this

Leave a Lobby Room

socket.emit('lobby', {
    action: 'leave'
});

Make a Move In-Game

Depending on the phase of the game, a player can make one of three moves:

socket.emit('game', {
    action: 'move',
    // nominations is an array of lookup indices.
    // The ordering of the player array in the game
    // state is preserved, so putting 0 in the nomination
    // array means to nominate the first player
    nominations: [0, 2, 3]
});
socket.emit('game', {
    action: 'move',
    // All players must vote on the nominations
    approve: true | false
});
socket.emit('game', {
    action: 'move',
    // In the mission phase, successfully nominated
    // players secretly choose whether the mission
    // is successful
    succeed: true | false
});

Payloads

User Data

The user data is sent to its user on connection and whenever it changes

socket.on('userdata', ({
    username,
    coords
}) => {
    ...
});

Lobby Listing

The lobby listing is periodically sent to all users if any update to the lobby has occurred

socket.on('lobby', ({
    type, // 'listing'
    rooms
}) => {
    ...
});

rooms is an array containing objects of the following form:

{
    id: '3ZBF21',
    players: ['Alice', 'Bob'] // Alice is the host
}

Lobby Room

If the user is currently in a lobby room (waiting to play), they will be sent the room data anytime it changes

socket.on('lobby', ({
    type, // 'room-update'
    room
}));

room is an object of the form:

{
    id: 'QF2341',
    players: ['Alice', 'Bob', 'Claire'],
    isUserHost: true | false
}

This is identical to a lobby listing entry except that the user may be indicated as the host

Room Cancelled

If the host leaves a room, the room is cancelled

socket.on('lobby', ({
    type, // 'room-cancelled'
    room
}));

Errors

Service error messages are sent back with 'service-error' events.

socket.on('service-error', error => {
    console.error(error);
});