The online racing simulator
XI4N - eXtensible Insim client 4 Nodejs
Ladies and gents,

I present the first stable-ish, but not-yet-complete, version of the eXtensible InSim client 4 Nodejs. As usual I'm throwing it out there early partly incase any other ****er has been working on it, and partly because it may be interesting to someone else.

It maybe used as a standalone "executable" (still requires nodejs) or as a library. Theoretically if the node sockets are swapped out, for socket.io it could also be used within a web browser - altho that would mean it leaks your admin password in a very public way.

Call it a "developer preview" rather than a finished product.

It was my 2 days off between Christmas and New Year project, but it's kinda grown a bit

I still plan on working on it for a bit as it's proving to be a useful distraction from work in the evenings at the moment.

As a bit of background, it's much like luaLFS was with "subscriptions" or hooks to functions, but more complete at this point. It also takes some inspiration from the awesome PRISM, but with some Javascript orientated bits slapped on top.

README has a lot of info it in at the moment, including some basic usage. I've not documented much other than that yet. If you are planning on playing with it at this stage that main thing not mentioned is that I take explicit advantage of being able to manipulate "this" when plugins functions are called, giving easy access to the client connection, insim packet definitions, and the logger.

I just wanna say a quick bit of thanks to the guys who run the cargame.nl servers as I've been testing xi4n locally whilst connected to that, and doing 90 second sprints of furious debugging between races Also thanks for reminding me how much fun LFS can be
That's unbelievable! Having the option to swap out NodeJS with socket.io to have it run in a browser is just awesome. Must play around with this, possibilities are endless!
Great, awesome, ground breaking!

Eehhh.. What does it do?

I´ve also read that Lua thread a bit (its 5 years old :/ ). But I do not get it.

Quote from the_angry_angel :

I just wanna say a quick bit of thanks to the guys who run the cargame.nl servers as I've been testing xi4n locally whilst connected to that, and doing 90 second sprints of furious debugging between races

Hhmm must have been a short track otherwise you get more seconds
Cheers for running the cargame servers dude I really do enjoy playing on them, it's been a fun few weeks

Quote from cargame.nl :Eehhh.. What does it do?

Basically it's a multi-connection insim library written in javascript, but one you can also choose to run by pointing it at a directory with a config file and bunch of plugins.

It runs on nodejs which is a platform built on Google's (chrome) v8 javascript engine "for easily building fast, scalable network applications".

What xi4n does is it gives you a basic framework of socket maintenance, packet parsing, etc. and exposes an API that allows you to write plugins without worrying about how InSim really works - you just say what packets you want and what function(s) to call when that packet comes in - pre-parsed into an easy to use javascript object.

Once I've finished work for the day I'll try and write some documentation tonight and give a quick demo somewhere

The main benefit that I see over things like PRISM and pyinsim is that it's non-blocking by default, meaning you dont have to worry about yielding, or threads and the sync issues you get. By default all plugins can support as many servers as you've got in your config file. This combined with the other features that nodejs supports out of the box means you can very easily write things like an entirely in-memory live tracker (i.e. no DB, ActiveMQ, or other message queue or RPC), including InSim connection(s) and HTTP server, all in less than a few hundred lines of plugin That's the bit I find really cool

The other interesting thing, is that as its written in javascript it would be possible to do a little fiddling and port it to use websockets, which means given a sufficiently modern browser, you can get an insim connection directly from your browser, to your server. Could be very interesting for a control panel, perhaps (something I hadn't thought about.. hmmm).

I've got the nodejs bug at the moment after using it for a demo project at work and wanted something to play with at home
Quote from the_angry_angel :The main benefit that I see over things like PRISM and pyinsim is that it's non-blocking by default, meaning you dont have to worry about yielding, or threads and the sync issues you get.

Just a small correction in that as of version 2.0 pyinsim has been non-blocking and runs everything on a single thread.
And PRISM has always been non-blocking, thanks to Victor's network code (found in PRISM's core and in the modules he made).
Epic TAA fail. Boooo. Thats what happens when I don't pay attention
It took me a few extra days to get around to putting together a demo of what xi4n is exactly, and what it can do right now.

I figured since I'm not running it against a populated server at the moment I'd video something.

http://www.youtube.com/watch?v=U_SiwqAuzFw

Excuse the quality of the voice over. I don't like "public speaking", even pre-recorded and over the internet.

The entire xi4n install and livemap plugin, plus a few connected people weighs in at about 10-20MB of ram usage total, depending on the node garbage collection. Of that, about 4MB is the node environment. So it's reasonably slim for a 100% live tracker, in comparison to running your InSim client plus apache/nginx/IIS/whateveer and PHP/python/whatever and some form of database/RPC to communicate between the two.

Obviously what I've demo'd isn't 100% feature complete. I need to write some iconv stuff to deal with LFS' codepage nonsense and so forth, etc.

A couple of other things I'm interested in working on is a re-implementation of the LFSW relay that you can run yourself and allow anyone to connect in but not send destructive commands. I'm also interested in arsing about with a live control panel which may be an extension of the livemap plugin.
I can't watch the video yet, text browsing atm.. But it sounds pretty cool.

Javascript is an easy 'language' and with that AJAX stuff nowadays not bad at all.
OK, nice!

So... SO4.pth ... OK

But... Can you do it with a custom pth as well?

Found here; http://www.airio.eu/Downloads.aspx

And... Can the system detect easily if a car is off track?
Quote from cargame.nl :But... Can you do it with a custom pth as well?

At the moment it relies on insim's IS_STA packets to determine the track, and for a custom track that's only ever something like BL1X, but I'm sure it could be figured out some how - maybe from the IS_MSO packets when the track is loaded.. I'll see what I can do

Quote from cargame.nl :And... Can the system detect easily if a car is off track?

It could be added, again not something I've done - yet
Holy Shit... Just watched the youtube video. Thats pretty smart man. Well done!
Quote from the_angry_angel :but I'm sure it could be figured out some how

Yeah it's possible... With PRISM I look at the track code and then the name of the layout.

The problem with open configs is, is that there is no node information, but you say it doesn't matter ... Well.. OK.. Sounds good
Quote from mcgas001 :Holy Shit... Just watched the youtube video. Thats pretty smart man. Well done!

The example there isn't really doing anything but translating the insim packets into javascript objects and then basically proxying them to the browser and then theres some drawing going on - it's really not that hard, but thanks for the sentiment

I'm tempted to switch away from drawing using SVG at the moment, but I'll probably save that for much, much later. Maybe when webgl is a bit less crappy.

Quote from cargame.nl :Yeah it's possible... With PRISM I look at the track code and then the name of the layout.

Aah, yes, so I see - there's the layout name in IS_AXI. Hadn't noticed that That makes life a lot easier Cheers for the pointer dude

Quote from cargame.nl :The problem with open configs is, is that there is no node information, but you say it doesn't matter ... Well.. OK.. Sounds good

I cheat and don't use any node info - only the X an Y coordinates from IS_MCI - you still seem to get them for custom layouts still. I've not tried drawing a custom track yet, but I don't see why it would be any different.. Or at least I hope not

Tonight I've been fiddling with translating LFS' strings into utf8, which is annoyingly tricky when javascript doesn't have anything suitable out of the box, and you start not really knowing anything about multi-byte character encoding. I've more or less got that sorted (although I really do want to murder someone who was involved with character encoding right now :tilt and I want to pop that into the packet handler so you can easily translate from LFS' munged mess to utf8 - useful for the livemap to deal with LFS' mixed character sets on the web interface in standard HTML. I've got a bit of work to get it to that stage, but the basics seem to work now, which is nice.

Next on my list, is setting up a general state manager that multiple plugins can use and then I'll get the livemap ported over to use that instead. It'll be a bit lighter on the bandwidth than the current version - which will be nice Hopefully it'll help out with the browser CPU usage too

Hoping to have a couple more hours before the weekend to try and get some of that done. Hopefully in a week or so time there'll be a nice, lower bandwidth, non-buggy version that can display most of the character sets LFS supports
Took a look at the video, how did you get color into the CMD prompt, very jealous that you got this working in such a short amount of time. Keep on rocking on dude!
Quote from Dygear :how did you get color into the CMD prompt

Cheating really. The node runtime executable for windows is kind enough to add support for the normal ANSI escape codes that work on everything else, so I basically get ANSI colour support on Windows for free.

I don't really understand why Microsoft never brought that across from Windows 9x into NT land

There is ansihack, but I don't know if it works on modern versions of Windows. There is also ansicon (also on github), which I use for a couple of other projects both personal and at work, and is still updated

Quote from Dygear :Keep on rocking on dude!

Cheers for the encouragement dude It's definitely appreciated
Hi guys,

Just an update. If you'd rather this in video form there's another on the youtubes. It's not necessary to watch as it's just the same as what I've written here and visually there's not much difference
  • I've bumped the version to 0.0.2 because of an API change.
  • I've completely rewritten the livemap plugin - the original is now gone.
  • Livemap2 depends on a generic state plugin, which makes livemap2 a lot simplier
  • Livemap2 now understands the concept of layouts, and should attempt to load them - I've not yet managed to test that yet, but it should work
  • Livemap2 is lower bandwidth
  • Really basic LFS string support (translating codepages and colours)
    • Translation to UTF8 is mostly working, but there are few characters that aren't quite right - I'm working on those
    • Colour support, but needs tidying massively
    • I want to add multiple output types, so you can auto-colour for the web, or for the console, or strip completely
  • Livemap2 has highlightable players (pretty sure that wasn't in the original)
  • There are a couple of problems with either the livemap2 or state plugin, such as it occasionally not picking up players that have left, but I'm working on them.
The video discusses a couple of ideas I have for the future for this project, such as reverse chat (i.e. chat from the web interface to the server). One I've not mentioned in that I've got a couple of ideas for a longer 3/6/12/24 hour event with a live stream, and live interactivity from non-racers in a few months time - but we'll see how things go as a lot of it will depend on xi4n's progress and how much of what I've got in mind is realistically implementable
The node.js server makes 1 InSim connection and every web client is connecting through node.js server so it's still 1 InSim connection?

If yes - you are my JS master! It's incredible that we have sockets in JS.
Quote from misiek08 :The node.js server makes 1 InSim connection and every web client is connecting through node.js server so it's still 1 InSim connection?

Correct The livemap plugin works pretty well underload - I've had a couple of thousand concurrent connections before there are CPU issues on a small VM.

The web client itself is a little hacky and could really benefit from being ported to use angular.js or backbone, or something similar, but it's totally usable as it is right now.

As an fyi I've not worked on anything that's in the github repo at the moment (the repo on my home network has a few additions that I've not pushed up), as I've been using my evenings for a work project for a few weeks, however I do have plans to continue with xi4n as I've got a couple of competition plans that totally rely on it

Edit: The video above is out of date, in terms of the look and number of bugs in the livemap plugin - aside from some codepage issues, it should be bug-free.

Edit: Updated video on the youtubes - regarding what I've done, some experimental in-browser 3D track stuff, web control panels and bonus rambling: http://www.youtube.com/watch?v=vuZly5agOkM
Push the changes if you can
This is very interesting, but a little confusing to an old-fashioned programmer.

It looks like at it's core, it basically translates insim packets (from a lfs server, or client?) to JSON versions, and can run local js plugins to 'do stuff' with the insim information locally. But what can it do beyond that? Does the lapper example just serve HTML to any connecting browser, or does it serve JSON insim packets directly to XIaN clients? Or could it do both? Should I just shut up & try to understand the code?

I'm only vaguely aware of the capabilities of nodejs, but it seems that this potentially gives it real flexibility. Have you any idea how it performs compared to similar things? That's probably not an issue with server insim information, but could be more important if all the other data is required.
You could serve packets to any connecting browser, if a plugin setup a HTTP server - like the livemap plugin does Or you could send back packets to LFS, like you would with any other InSim application.

Basically xi4n itself just translates and event-ifies packets from LFS, and a plugin just receives those events from the xi4n core. A plugin doesn't have to talk to a browser, it can talk to anything it needs or wants to There's no restriction on what a plugin can do at the moment, so if nodejs itself can do it, so can a plugin - be it talking to a browser, storing chat in a database or talking to another insim program - you name it and it can do it

Hope thats a bit clearer? I will be honest the code is a little hacky still and needs a bit of a tidy when I've got stuff working in a reasonable way, so it may not be the easiest to follow right now.
How to setup password on InSim connection? I don't see in opts anything called admin or password (clientmanager.js).
Apparently I forgot to add password capabilities completely I'm about to head away for for work, working very long hours for the next 2 days (behind a restrictive firewall that I don't control - yet), but I'll do my best to get it added into the github repo shortly If you need to hack it in for now you can pop it into https://github.com/theangryang ... master/lib/client.js#L165
Oh, there. Sorry, I was looking in clientmanager.js.

The TV plugins looks nice. I didn't tried the livemap yet, but it can be best thing for 16h race this year. I'm going to host it if organizers will approve it!


EDIT:
TV plugin doesn't know what VIEW_CAM and VIEW_DRIVER is. I don't know why, but it don't read exports.VIEW_ variables.

FGED GREDG RDFGDR GSFDG