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

@mxve/matchmaking

v0.5.0

Published

Create matches or lobbies for two or more players/objects

Downloads

3

Readme

Matchmaking

Matchmaking will help you to create matches!

About

This is a fork of https://github.com/Luifr/matchmaking at commit 3f19ed585f4d326a009ce389cdb833b2dbaadd07.

Changes

  • Made FifoMatchMaker actually First in first out

Installing

npm i @mxve/matchmaking

How to use

LobbyMaker

With this class you can create, list and join lobbies They can have password or be private (joined by name)

const { LobbyMaker } = require('@mxve/matchmaking');

function runGame(players) {
	console.log("Game started with:");
	console.log(players);
}

function getPlayerKey(player){
	return player.id;
}

let lobby = new LobbyMaker(runGame, getPlayerKey);

let player1 = { id:20 }
let player2 = { id:21 }

// Create a room
let id = lobby.createRoom(player1, "Room 0");

// Other player joined the room
lobby.joinRoom(id, player2);

// Start game
lobby.start(id);

// Game started with:
// [ {id:20}, {id:21} ]

FifoMatchMaker

This one is really simple, just push players to the queue, and games will be started automatically!

const { FifoMatchmaker } = require('@mxve/matchmaking');

function runGame(players) {
	console.log("Game started with:");
	console.log(players);
}

function getPlayerKey(player){
	return player.id;
}

let mm = new FifoMatchmaker(runGame, getPlayerKey, { checkInterval: 2000 });

let player1 = { id:1 }
let player2 = { id:2 }

// Players join match queue
mm.push(player1);
mm.push(player2);

// When there are enough players, runGame will be called

// Game started with:
// [ {id:1}, {id:2} ]

Api

Player

  • The player will be mentioned a lot here
  • By player i mean a generic object
    • As use in the example above, just a plain object with an id
    • The player can be anything and depends on your project/game

FifoMatchmaker

  • constructor(resolver, getKey, options)
    • resolver(players) - A function that will be called whenever there are enough players to start a game
      • players - a array with all the players in that game
    • getKey(player) - A function that will extract the id of a player
      • player - The player whose id will be extrected
    • options - [OPTIONAL] - A object with settings for the matchmaker
      • checkInterval - The interval in milliseconds to try to start new games
      • maxMatchSize - Maximum number of players in a room
      • minMatchSize - Minimum number of players in a room
  • push(player)
    • parameters
      • player - The object containing all player information
    • return
      • void
  • leaveQueue(player)
    • parameters
      • player - The player with its ID
    • return
      • void

LobbyMaker

  • constructor(resolver, options)
    • parameters
      • resolver(players) - A function that will be called manualy or automatically when there are enough players to start a game, if this options hass been set
        • players - a array with all the players in that game
      • getKey(player) - A function that given a player, returns its unique identifier (id)
  • createRoom(player, roomName, options)
    • parameters
      • player - The object containing all player information
      • roomName - The name to be displayed in room listing
      • options - [OPTIONAL] - A object with settings for the matchmaker
        • private - Should this lobby appear in public listing?
        • password - If set, players will have to use this password to join the lobby, leavy empty to create a open lobby
        • maxLobbySize - Maximum number of players in a room
        • minLobbySize - Minimum number of players in a room
        • autoStartWithMinSize - If true, the lobby will autostart when MinSize is reached
        • autoStartWithMaxSize - If true, the lobby will autostart when lobby is full is reached
    • return
      • The unique room Identifier (number)
  • leaveRoom = (roomId, player)
    • parameters
      • roomId - The room to be leaved
      • player - The player that will leave the room
  • deleteRoom(roomId)
    • parameters
      • roomId - The room id that will be deleted
    • return
      • void
  • listRooms()
    • return
      • RoomInfo[] - A array of RoomInfo objects, each containing: {id, name, passwordIsRequired, currentPlayers, MaxPlayers}
  • joinRoom(roomId, newPlayer, password)
    • parameters
      • roomId - Room to be joined
      • newPlayer - the player object that will join
      • password - [OPTIONAL] - If the room require password
  • startGame(roomId)
    • parameters
      • roomId - The room to start the game, this will call the resolver function passed in constructor
    • return - void

Error handling

  • All functions that can return error, will do returning e Error object

Authors

  • Lui Franco Rocha
  • mxve

License

This project is licensed under the MIT License - see the LICENSE.md file for details