Thursday, April 2nd, 2009

Q42 Multiplayer Game Engine Open Sourced

Category: Chat, Games

<>p>Martin Kool of Q42 let us know that his company decided to open source the Q42 multiplayer engine which is “a lightweight, generic multi-user solution, allowing developers to create their own browser-based application or game over port 80.”

The engine is written in C# on the backend, and of course, JavaScript on the front end.

You can check out the sample chat client that leads you to the following code:

javascript
< view plain text >
  1. /// <reference path="Multiplayer.js" />
  2. var ChatClient =
  3. {
  4.   users: {},
  5.   join: function() {    
  6.     ChatClient.name = document.getElementById("name").value;
  7.     document.getElementById("joinForm").style.display = "none";
  8.     document.getElementById("chat").style.display = "block";
  9.     Multiplayer.init("ping.aspx", 2000, ChatClient.handleEvent, { "name": true, "say": false });
  10.     var roomName = document.location.search.replace(/.*?room=(.*)/g, '$1');
  11.     roomName = (roomName == document.location.search) ? 0 : roomName;
  12.     Multiplayer.connect({ "name": ChatClient.name }, roomName);
  13.     ChatClient.writeLog("* " + ChatClient.name + " joined.");
  14.   },
  15.   handleEvent: function(userId, name, value) {
  16.     if (!ChatClient.users[userId]) ChatClient.users[userId] = {};
  17.     var user = ChatClient.users[userId];
  18.     user[name] = value;
  19.     if (name == "disconnect") ChatClient.writeLog("* " + user.name + " disconnected.");
  20.     if (name == "name") ChatClient.writeLog("* " + value + " joined.");
  21.     if (name == "say") ChatClient.writeLog((user.name ? user.name : userId) + ": " + value);
  22.   },
  23.   sendMessage: function() {
  24.     var text = document.getElementById("msg").value;
  25.     if (text.indexOf("room") == 0)
  26.       Multiplayer.send({ "room": text.substr(5) });
  27.     else
  28.       Multiplayer.send({ "say": text });
  29.     ChatClient.writeLog(ChatClient.name + ": " + text);
  30.     document.getElementById("msg").value = "";
  31.   },
  32.   writeLog: function(msg) {
  33.     document.getElementById("log").value += msg + "\n";
  34.     document.getElementById("log").scrollTop = document.getElementById("log").scrollHeight;
  35.   }
  36. };

Each user asynchronously pings a url on the central server at a given interval, sending its changes and retrieving changes of other visitors. The retrieved changes are dispatched through the javascript library, so the clientside application may act upon it.

The client consists of a single 5k javascript file, and the server is a single C# class library that can be embedded as source, or as a dll.

Focus of the q42 multiplayer engine was to give developers full control and not come up with any restrictions to the type of application that is being developed.

Features

  • Easy customization and full control. Example project included
  • Easy grouping of users that can see eachother by means of virtual “rooms”
  • Automatic room upscaling when a certain amount of users is reached
  • Automatic cleanup of empty rooms and idle users
  • Persistent user properties (for example: name, x or y position)
  • Nonpersistent user events, such as chat messages
  • Full control over rooms, names, properties, events and its values
  • Moderating features can be implemented easily
  • Optionally allowing multiple users per session, so each browser-tab can represent a new user.

Related Content:

Posted by Dion Almaer at 5:33 am
2 Comments

+++--
3.4 rating from 37 votes

2 Comments »

Comments feed TrackBack URI

I’ve already finished about 35% of my Javascript RTS engine (see deepcommand.com) which communicates over realtime Flash-based sockets.

Currently building, health and vehicles are properly synchronised, and the game is able to receive updates from the server approximately 20 per second, and renders at around 40fps. :D

My server system already way surpasses this, and it’s just a daemon written in CLI PHP :P

Comment by Darkimmortal — April 2, 2009

Can someone direct me in the right direction, i’m trying to compile the project in visual studio 2010 express in C# but i just havent been able to do this… :S

Comment by dante8000 — December 28, 2010

Leave a comment

You must be logged in to post a comment.