This is a realtime network multiplayer demo using Node.js and Websocket.
To see this example running, go to http://wivlaro.com:3001
The demo game is a multiplayer territory game. There are three teams, you click to move, the idea is to dominate the play area with your colour, red, green, or blue.
Make sure you have http://nodejs.org/ installed
git clone https://github.com/wivlaro/syncem.git
cd syncem
npm install
npm start
Navigate to http://localhost:3001
If you want to play around with it, the most interesting bits to change are in bold:
public
- static files served upsrc
- split into three categories, server and client, and common, which is code to run on both server and clientsrc/client/main.js
- File that kicks off the whole process for the client. Hacking around with thefunction renderScene()
is probably most interestingsrc/common/mygame.js
- The core game logic - to be changed depending on the gamesrc/common/player.js
- Contains the player class, also game dependentsrc/common/bserializer.js
- The binary serialization/deserialization componentsrc/common/syncem.js
- The main engine for the network synchronizationsrc/common/bserializer_expansions.js
- Automatically generated on the server dependent on registered classes - don't edit this, as it gets rewritten by the server on startupsrc/common/bserializer-cannon.js
- bindings for the http://cannonjs.org/ physics library so you can include it in your world statesrc/server/main.js
- Hopefully self-explanatorysrc/server/gameserver.js
- Server-side plumbing for syncem for a game, user managementsrc/server/client.js
- Server's model of a user, as connected to it
In theory you can hack around with main.js renderScene() and src/common/mygame.js and be able to make something. After rewriting common code, you will need to restart your server before reconnecting (or you will get out of sync problems).
If the bottom status line says "Out of Sync" it could mean one of these things
- the game logic is not deterministic
- the game state is not completely/properly serialized
- the client/server are not running the same version of the code (maybe restart the server and reconnect)
It is available under the permissive MIT license, so please feel free to take anything you like, but a credit for substantial portions of code is appreciated. Moreover, it's nice to hear of it being used! :)
- More documentation on the core systems: syncem.js and bserializer.js
- Rename _expansions to _generated so it makes more sense
- More commentry in the code documenting what is happening!
- Abstract out the more boring stuff into more of a library
- Make a convenience wrapper for declaring classes and bserializer.registerClass
Enjoy!
-Bill