Replacing Python on a Battlefield 2 server

Lately I’ve been doing some work (I promise it is real work) with Battlefield 2. The server part of the game has a cut-down version of Python built in so that you can interact with it, modifying aspects of the game and reacting to events etc. More details on this can be found on this wiki.

Anyway, the Python version it uses is pretty old (2.3.4, current version is 2.5.2) and it’s had functionality cut, e.g. no threading support. For the work I’m doing I needed threading support and a few other things so wanted to swap out the version of Python for another - turns out this wasn’t obvious so here are the steps:

  1. Replace the Battlefield 2 Python library (e.g. ‘bf2/bin/ia-32/libdice_py.so’) with the version of your choice. I just linked to my locally installed version ‘/usr/lib/libpython2.5.so’.
  2. Replace the Python library path at runtime to use the new libraries, e.g. edit ‘bf2/python/bf2/__init__.py’ and putting the equivalent of ’sys.path = ['/usr/lib/python2.5/', '/usr/lib/python2.5/lib-dynload/', 'python', 'mods/bf2/python', 'admin']‘ after the ‘import sys’ line.

I do get the following warning at runtime: ’sys:1: RuntimeWarning: Python C API version mismatch for module host: This Python has API version 1013, module host has version 1012.’ but it doesn’t seem to cause any problems (so far!).

Am I online?

I’ve recently changed my broadband provider and wondered how reliable they’d be. I figured I needed a way for my house to let me know whenever the connection had dropped and for how long for etc. Remembering my post a little while ago about
publishing to Twitter about local Bluetooth devices
, I thought I could do something similar. So now I’ve written a little script (twitter-netcheck) that notices whenever my internet connection is dropped and then publishes to Twitter whenever it comes back. It also sends me a direct message so I get alerted by SMS or IM immediately. Quite handy I think - try it out for yourself

Tweetjects and Bluetooth

Andy Stanford-Clark recently got a few people together to talk about blogjects and tweetjects after getting his house to tweet about the various goings-on there. That inspired me to think about what I could do with Twitter and remembered a while ago I’d created a little script that polled for nearby Bluetooth devices and published them via MQTT. So as a good distraction from work I thought I might integrate this with Twitter and so we now have a little python script that lets my laptop publish details of any bluetooth devices it sees appear and disappear. So what’s the use of this then? Probably very little but it might be interesting to hook it up in my flat and see who goes in and out of there…

[Update]
I failed to find the time to set this up as a proper project somewhere but here’s the scripts in case anyone wanted to make use of the application:

Christmas fun

Ok, so I got a bit bored at some point over Christmas and decided to play with one of my presents - a USB Rocket Launcher.

The first difficulty was getting it to run on my Linux laptop as the drivers were only for Windows. A quick search and Scott Weston sorted me out. Then I thought it should really be controlled by more than just the keyboard so I hooked it into the Thinkpad accelerometer - now movements of the laptop could direct it. Finally, as I knew Andy Stanford-Clark would be a bit disappointed in me if I hadn’t, I MQTT‘d it so that the accelerometer details are published to a broker, a bridge app subscribes to that info and (where appropriate) publishes commands which are received by a final subscriber that actually sends the commands to the rocket launcher. This way you can easily swap out the accelerometer or indeed rocket launcher for something completely different.

I feel quite pleased with myself and slightly ashamed at the same time.