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

versusmaker

v1.0.4

Published

Matchmaking library for multiplayer games

Downloads

22

Readme

 __      ________ _____   _____ _    _  _____ __  __          _  ________ _____
 \ \    / /  ____|  __ \ / ____| |  | |/ ____|  \/  |   /\   | |/ /  ____|  __ \
  \ \  / /| |__  | |__) | (___ | |  | | (___ | \  / |  /  \  | ' /| |__  | |__) |
   \ \/ / |  __| |  _  / \___ \| |  | |\___ \| |\/| | / /\ \ |  < |  __| |  _  /
    \  /  | |____| | \ \ ____) | |__| |____) | |  | |/ ____ \| . \| |____| | \ \
     \/   |______|_|  \_\_____/ \____/|_____/|_|  |_/_/    \_\_|\_\______|_|  \_\

Status npm bundle size GitHub Issues GitHub Pull Requests License


🗒️ Table of Contents

📚 About

versusmaker is a simple matchmaker and easy-to-use nodejs library.

🚀 Getting Started

Install the package with npm

npm install --save versusmaker

Install the package with yarn

yarn add versusmaker

🎬 Usage

  • Create a matchmaking for 1v1
let match = null
// create a queue
const queue = new Queue()
// create a matchmaker instance passing the queue,
// 100 as a threshold (which is the different allowed between the mmr of the players
// that means that a player with 1100 mmr can match with a player with 1000 mmr
// and also a player with 1200 mrr),
// and the number of players per team, 1 for this case
const matchmaker = new Matchmaker(queue, 100, 1)

// create some players with an ID and their mmr
const player1 = new Player('1', 1000)
const player2 = new Player('2', 1070)
// try to find a match by calling `findMatch` passing a player
match = matchmaker.findMatch(player1)
// if the system does not find any match for that player
// it will add it to the queue and return null

// if we call the same function again with another player
// it will check the queue of players and the player passed
// so in this case we will get a match
match = matchmaker.findMatch(player2)
  • Adding players to queue
// players that could not find a match
// are automatically added to the queue
// but maybe for any reason you wanna add player to the queue
// without trying to find a match for them
// you can do that by passing an array of players
const queue = new Queue()
const player1 = new Player('1', 2200)
const player2 = new Player('2', 1400)
queue.addPlayersToQueue([player1, player2])
  • Remove player from queue
// if, for example, a player that was in queue disconnects from your game
// you can remove that player from the queue just by passing an array of player ids
const queue = new Queue()
const matchmaker = new Matchmaker(queue, 100, 5)
const myOwnPlayerId = '1'
const myOwnPlayerMMR = 2102
const player = new Player(myOwnPlayerId, myOwnPlayerMMR)
// we try to find a match for that player
const match = matchmaker.findMatch(player)
// returns null because it didn't find a match for that player
// so the player is automatically added in the queue

// but the player disconnected so we wanna remove it from the queue
queue.removePlayersFromQueue([player.id])
  • Match object The match returned by .findMatch function contains the following structure:
{
	"id": "match-rhdfh2fg34b53", // match id
	"teamA": [], // array of Players
	"teamB": [], // array of Players
	"isReady": true // just a flag to know that the match teams are full filled
}

🚧 Built with

🧑🏻‍💻👩🏻‍💻 Authors