Colyseus — Minimalist MMO Game Server for Node.js

https://github.com/gamestdio/colyseus

Lucid Sight has acquired Colyseus!

Read the 0.10 update.

Read the 0.5.0 update.

For the last couple of months I’ve been prototyping some multiplayer games in HTML5/JavaScript. I thought it wouldn’t be painful since the community has grown a lot — having a library ready-to-go for everything you want out there. Unfortunately it doesn’t seem to be the case for multiplayer games.

Most people who want a multiplayer game tend to re-implement a lobby system using socket.io or sockjs, which is fine if you want to do a single game. What I wanted was just a lobby system with rooms support, and synching room state without the hassle of managing particular messages back and forth.

So the idea of having a generic game server evolved and Colyseus does just like that. It basically is a match-making system which spawns rooms with custom code and sync its state with all connected clients.

Here’s an overview of how it works:

Match-making cycle:

1. User asks to connect in a specific room, with optional “join” arguments.

2. Server will loop through all spawned room handlers named ‘battle’ and call requestJoin method against that handler.

3. If requestJoin succeeds, a method named onJoin will be called with the client reference and client options given.

4. If requestJoin fails on every available room, a new handler will be spawned if requestJoin succeeds in a fresh handler state. In case it fails again, an ‘error’ event will be dispatched on client room instance.

Room state handling:

Once the player received the room state upon its connection, he only needs to receive the state difference on later broadcasts, called patches.

By default, room handlers will deliver the patched room state to all clients each 50ms.

The array of patches usually look like this: (JSON-Patch format)

You can take a look at patch handling on tanx project to see how it looks like.

Here’s some game prototypes you can play online:

Colyseus’s code base still quite straightforward, which is good for its growth as a library. It doesn’t do much, but it tries to do really well what is meant to.

Thanks for reading until here, and feel free to ask questions on gitter chat channel in case you have any.

Software Engineer & Indie Game Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store