I've been working on some Javascript (node.js) code to work with the FG multiplayer protocol. Implementing a packet encoder/decoder according to http://wiki.flightgear.org/Multiplayer_protocol was easy enough, but I soon noticed decoding errors. Sometimes packets arrive with invalid property IDs. OpenRadar and ATC-Pie are engaged in obvious abuse-of-protocol, but I've noticed FlightGear generating malformed packets (both from my local 3.4 install and from players on the public MP network.)
In particular packets with the faulty IDs 48 and 49 are showing up, and I'm not the only one to have seen this: https://forum.flightgear.org/viewtopic.php?f=17&t=6760&start=90 (look in the posted debug logs.)
I finally relented and read the relevant C++ - I'd been avoiding doing so because, other people's code Anway, after reading https://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/MultiPlayer/multiplaymgr.cxx I think I've worked out what is going on.
The clue is the numbers 48 and 49, which correspond to ASCII for '0' and '1'. If I add some code to dump the words surrounding the invalid encoded properties, I get output like this:
- Code: Select all
wtf: 10200,1,48,0,0,0,10201,1,48,0,0,0,10202,1,48,0,0,0,10203,1061997773,10300,0,10302,1,10303,0,10304,0,10305,0
The first word is a valid property ID, in this case "sim/multiplay/generic/float[0]", which is (if you look it up in the table of encodable MP properties) supposed to be a float. However, what follows is a correctly encoded string! The length word (1), the character '0' (49) and then three words of padding (in line with the broken string encoding that FlightGear uses.)
In other words, the multiplayer protocol code isn't coercing values stored in the property tree to the correct type - the code that actually writes property values to a MP protocol buffer determines what type to write based on the type stored in the property tree, not what is implied by the MP property identifier, if there's a mismatch (for instance, if an aircraft writes a string to a property that's expected to be a float) the resulting packet will be malformed.