Tycho

Real-time multiplayer game framework for Node.js


Project maintained by pbeardshear Hosted on GitHub Pages — Theme by mattgraham

Quick Start

To get started using Tycho:

var tycho = require('tycho'),
	server = tycho.createServer();
	
server.listen(3000);

Create a new .html page and add the following to the header:

<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/tycho/tycho.js"></script>
<script type="text/javascript" src="/tycho/message.js"></script>
<script type="text/javascript">
	tycho.connect();
</script>

Open a browser and navigate to http://localhost:3000. Your page should load and connect to the tycho server.

Documentation

Listed below is the full documenation for Tycho.


tycho.createServer([config])  :  tycho

root [string]

Sets the directory that the server will serve files from. Defaults to: The current directory

maxConnections [int]

Sets the maximum number of concurrent connections allowed. Defaults to: 100

maxInstances [int]

Sets the maximum number of concurrent instances allowed. Defaults to: 10

namedInstances [bool]

True to specify the names of instances when they are created. If using namedInstances, autoCreateInstances must be set to false. Defaults to: false

autoCreateInstances [bool]

True to have the server automatically create new instances. See loadBalance to set the conditions for when a new instance should be created. Defaults to: true

autoAssignConnections [bool]

True to have the server automatically assign a new connection to an instance. Defaults to: true

allowReconnect [bool]

True to have users reconnect to their last instance if they disconnect. Defaults to: true

binding [object]

Set the user-specific objects that should represent instances and connections in an application. The object should be of the form

{ connection: [Function], instance: [Function] }
Defaults to: {}

messages [object]

The messaging system that tycho should use internally. A user-defined messaging interface must define a send method with the following signature:

function send(message, connection) { }
This method must call connection.send(name, data, callback) with the appropriate message name and data when finished. Additionally, a receive method can be defined which will be passed every message sent from the client. The receive method should have the signature:
function receive(message, connection) { }
Defaults to: tycho.messages

routes [object]

Specify the messages and associated handlers that the server accepts from the client. This can be done in two forms:

// Basic route setup, all routes defined on connection
{
	route1: function (message, connection) { },
	route2: function (message) { },
	...
}

// Break routes down by destination
{
	connection: { ... },
	instance: { ... },
	server: { ... } 
}
In the first case, each route will receive (message, connection), with this being bound to the connection binding specified in the config. In the second case, each route will receive (message, target), where target is one of server, instance, or connection, depending on where the route was defined. this will be bound to the binding specified in the config, or the server object, if the destination is the server. Defaults to: {}

Licensing

Tycho is licensed under the MIT license. You are free to use Tycho without restriction for both open-source and closed-source applications. See the repository for the full license.