Coder Social home page Coder Social logo

matchmaking's Introduction

Matchmaking

Matchmaking will help you to create matches in games, chats or anything else you can imagine!

Installing

npm i matchmaking

How to use

Api reference

LobbyMaker

Create, list and join lobbies They can have password or be private (joined by name or id) With the third argument in the constructor you can customize the lobby settings

const { LobbyMaker } = require('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.createLobby(player1, "Room 0");

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

// Lets start the 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('matchmaking');

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

let mm = new FifoMatchmaker(runGame, { 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} ]

Author

  • Lui Franco Rocha

License

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

matchmaking's People

Contributors

luifr avatar luipronto avatar

Stargazers

zero avatar  avatar  avatar Jhonata Costa avatar Arilson avatar Robert Veloso avatar Leonardo Mauro avatar

Watchers

James Cloos avatar  avatar

matchmaking's Issues

[Feature Request] Empty Lobbies.

There should be function to create empty lobbies without any players in the beginning. Currently there needs to be player object passed in createRoom.

So when i try to use the fifomm one it just crashes when adding a player to the queue

So basically when a player gets pushed into the matchmaking class thingy it crashes with this error

`C:\Users-\Desktop\Ecard server\node_modules\matchmaking\javascript\matchMaker.js:15 let playerKey = this.getKey(player);
^

TypeError: this.getKey is not a function
at FifoMatchmaker.Matchmaker.indexOnQueue (C:\Users-\Desktop\Ecard server\node_modules\matchmaking\javascript\matchMaker.js:15:34)
at FifoMatchmaker.Matchmaker.push (C:\Users-\Desktop\Ecard server\node_modules\matchmaking\javascript\matchMaker.js:10:22)
at Socket. (C:\Users-\Desktop\Ecard server\server.js:25:21)
at Socket.emit (events.js:210:5)
at C:\Users-\Desktop\Ecard server\node_modules\socket.io\lib\socket.js:528:12
at processTicksAndRejections (internal/process/task_queues.js:75:11)`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.