TankWar has online mode again: This time on Opera Unite

Tags:

You may recall an earlier post about TankWar, my 100% JavaScript cannons-game. Back when I wrote it, I included online play, but the server went down with a hard disk failure.

Now, I have rewritten the online mode – this time that part is also all JavaScript – continue reading to find out what makes it tick.

The original server

I wrote the original server for TankWar using Python and the Twisted library. Now, since I had nothing left, I had to reverse-engineer how the server used to work from the client’s code.

It proved to be a bit tricky, but eventually I succeeded

The new 100% JavaScript implementation

I decided I wanted to write the server as an Opera Unite application, and Opera was conveniently running a competition for Unite apps too.

The latest version of the application uses Bayeux as the protocol. It’s a straightforward JSON-based protocol for Comet, supported by the Dojo Foundation, and with client libraries available for both Dojo and jQuery.

I decided to put the Bayeux protocol related server code on GitHub under project JavaScript bayeux server. The code doesn’t support all of the Bayeux protocol yet, but it can be used to implement applications already as I have done. I plan to continue working on some new features for the library, but if you want to contribute, feel free.

I call the application itself TankWar on Unite. As mentioned, it uses Opera Unite as its base. I hadn’t developed Unite applications before, but it turned out to be a relatively simple job, thanks to the fact that Unite uses JavaScript with few custom APIs.

Unite applications also have the ability to keep persistent state, so it was perfect for a game where I needed to keep things together over multiple requests.

In closing

I’m planning on doing some more stuff for the game, such as improving the engine itself as it’s a little bit glitchy. Perhaps also improving the graphics, maybe by using bitmap sprites with canvas.

If you want to check out the Unite application’s source code, simply download it from the mentioned site and rename the file to .zip. It should at least serve as a good example on how to use the Bayeux server for writing your own Comet-based Unite apps.

The Bayeux server itself might also work with other JavaScript runtimes like Rhino. You would most likely need to implement a custom RhinoConnection object though, as I have only used it with Unite so far.