Jump to content

Colyseus - Minimalistic MMO Game Server


endel
 Share

Recommended Posts

I'd like to announce a tool that helps you to build multiplayer games in JavaScript.

 

logo.png?raw=true

 

Colyseus is a JavaScript server (for Node) and client (for the browser)

It handles WebSocket connections, has multiple room support, handles room state synchronisation and allows clients to create, join and leave rooms.

 

Here's an overview of how it works:

 

Match-making cycle:

- User asks to connect in a specific room, with optional "join" arguments. 

// (client-side)var Colyseus = new Colyseus("ws://localhost:3553");var battleRoom = colyseus.join('battle', {options: 'here'}) 

- Server will loop through all spawned room handlers named 'battle' and call requestJoin method against that handler.

// (server-side)// only accept new users if limit isn't reachedrequestJoin (options) {  return ( this.clients.length < 12 )} 

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

// (server-side)onJoin (client, options) {  // setup new player here}

- 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.

// (client-side)battleRoom.on('error', function(message) {  console.log("error triggered on battle room:", message)})

Room state handling:

Once the player received the room state upon it's 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.

// (client-side)battleRoom.on('update', function(newState, patches) {  console.log(patches)  // array of patches  console.log(newState) // newState with patches applied})

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

[  { "op": "remove", "path": "/players/2" },  { "op": "add", "path": "/players/3", "value": {"x": 10, "y": 10} },  { "op": "replace", "path": "/players/1/x", "value": 5 }]// JSON-Patch Spec - RFC6902

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

 

Here's some prototypes using Colyseus as a game server:

- PlayCanvas tanx fork (original game is here)

- Redneck River Race (made in 72h for LD34)

- CubeClub Soccer

 

Colyseus's code base is quite straightforward, which is good for it's growth as a library, I believe.

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 anything here or on gitter chat channel.

Cheers and happy new year! 

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...