Multiplayer protocol: Difference between revisions
m (Rearrange order) |
|||
Line 1: | Line 1: | ||
== Resources == | == Resources == | ||
Line 26: | Line 20: | ||
http://forum.flightgear.org/viewtopic.php?f=18&t=13510&hilit=development+help+xdr#p136501 | http://forum.flightgear.org/viewtopic.php?f=18&t=13510&hilit=development+help+xdr#p136501 | ||
== The messages == | |||
All messages are composed of XDR encoded data. (see [http://www.faqs.org/rfcs/rfc1832.html RFC 1832] for a complete description of XDR). XDR basically means: All data is in network byte order and aligned to the nearest multiple of 4 bytes. Strings are encoded as a zero-terminated array of characters,aligned to the nearest multiple of 4 bytes. Floating point numbers (32 or 64 bit) must be encode in the IEEE standard. | |||
FlightGear uses XDR encoded messages that are sent via UDP. | |||
== The header == | == The header == |
Revision as of 06:36, 17 December 2014
Resources
The routines for handling XDR are contained in $FG_SRC/Multiplayer/tiny_xdr.[h|c]xx:
http://gitorious.org/fg/flightgear/blobs/next/src/MultiPlayer/tiny_xdr.cxx
The different message types supported by the MP protocol are specified in $FG_SRC/MultiPlayer/mpmessages.hxx:
http://gitorious.org/fg/flightgear/blobs/next/src/MultiPlayer/mpmessages.hxx
The multiplayer system code:
https://gitorious.org/fg/flightgear/blobs/next/src/MultiPlayer/multiplaymgr.cxx
eXternal Data Representation (XDR):
http://en.wikipedia.org/wiki/External_Data_Representation
Multiplayer Forum Post (very helpful):
http://forum.flightgear.org/viewtopic.php?f=18&t=13510&hilit=development+help+xdr#p136501
The messages
All messages are composed of XDR encoded data. (see RFC 1832 for a complete description of XDR). XDR basically means: All data is in network byte order and aligned to the nearest multiple of 4 bytes. Strings are encoded as a zero-terminated array of characters,aligned to the nearest multiple of 4 bytes. Floating point numbers (32 or 64 bit) must be encode in the IEEE standard. FlightGear uses XDR encoded messages that are sent via UDP.
The header
The header is always 32 bytes long and contains the following fields in exactly that order:
|Magic|Version|MsgId|MsgLen|ReplyAddress|ReplyPort|Callsign|Data|
Magic: | 4 bytes, always 0x46474653 ("FGFS") | |
Version: | 4 bytes, protocol version, currently 0x00010001 (1.1) | |
MsgId: | 4 bytes, defines what data is appended to the header. Can be 0x00000001 for chat messages (deprecated) or 0x00000007 for position data - all other values are outdated and ignored | |
MsgLen: | 4 bytes, the length of the data.
| |
ReplyAddress: | 4 bytes, deprecated and ignored | |
ReplyPort: | 4 bytes, deprecated and ignored | |
Callsign: | 8 bytes, zero terminated array of characters representing
the user callsign |
Data of chat messages
The data for chat messages is a zero terminated array of characters. The MsgLen field in the header represents its length. The maximum length is defined to be 256 bytes.
Data of position messages
The data of position data is more complicated and looks like this:
ModelName | 96 bytes, zero terminated array of characters representing the aircraft model used by the user |
time | 8 bytes, representing the time when this message was generated double |
lag | 8 bytes, time offset for network lag double |
PosX | 8 bytes, XDR encoded double value, X-ccordinate of users position wrt the earth centered frame |
PosY | 8 bytes, XDR encoded double value, Y-ccordinate of users position wrt the earth centered frame |
PosZ | 8 bytes, XDR encoded double value, z-ccordinate of users
position wrt the earth centered frame |
OriX | 4 bytes, XDR encoded float value, X-orientation of the user wrt the earth centered frame, stored in the angle axis representation where the angle is coded into the axis length |
OriY | 4 bytes, XDR encoded float value, Y-orientation of the user wrt the earth centered frame, stored in the angle axis representation where the angle is coded into the axis length |
OriZ | 4 bytes, XDR encoded float value, Z-orientation of the user wrt the earth centered frame, stored in the angle axis representation where the angle is coded into the axis length |
VelX | 4 bytes, XDR encoded float value, velocity of the user in X direction wrt the earth centered frame measured in the earth centered frame |
VelY | 4 bytes, XDR encoded float value, velocity of the user in Y direction wrt the earth centered frame measured in the earth centered frame |
VelZ | 4 bytes, XDR encoded float value, velocity of the user in Z direction wrt the earth centered frame measured in the earth centered frame |
AV1 | 4 bytes, XDR encoded float value, 1. part of the three dimensional angular velocity vector wrt the earth centered frame measured in the earth centered frame |
AV2 | 4 bytes, XDR encoded float value, 2. part of the three dimensional angular velocity vector wrt the earth centered frame measured in the earth centered frame |
AV3 | 4 bytes, XDR encoded float value, 3. part of the three dimensional angular velocity vector wrt the earth centered frame measured in the earth centered frame |
LA1 | 4 bytes, XDR encoded float value, 1. part of the three dimensional linear accelaration vector wrt the earth centered frame measured in the earth centered frame |
LA2 | 4 bytes, XDR encoded float value, 2. part of the three dimensional linear accelaration vector wrt the earth centered frame measured in the earth centered frame |
LA3 | 4 bytes, XDR encoded float value, 3. part of the three dimensional linear accelaration vector wrt the earth centered frame measured in the earth centered frame |
AA1 | 4 bytes, XDR encoded float value, 1. part of the three dimensional angular accelaration vector wrt the earth centered frame measured in the earth centered frame |
AA2 | 4 bytes, XDR encoded float value, 2. part of the three dimensional angular accelaration vector wrt the earth centered frame measured in the earth centered frame |
AA3 | 4 bytes, XDR encoded float value, 3. part of the three dimensional angular accelaration vector wrt the earth centered frame measured in the earth centered frame |
pad | up to 8 bytes for padding the data to a multiple of 8 bytes |
This data is followed by property-values, which are encoded in the form ID|Value
Note This table is is current for FlightGear 3.2.0. For the list in the development version, see src/MultiPlayer/multiplaymgr.cxx. |
The following properties are transmitted, but not necessarily all present and not in this order:
ID | Property | Types |
---|---|---|
100 | surface-positions/left-aileron-pos-norm | float |
101 | surface-positions/right-aileron-pos-norm | float |
102 | surface-positions/elevator-pos-norm | float |
103 | surface-positions/rudder-pos-norm | float |
104 | surface-positions/flap-pos-norm | float |
105 | surface-positions/speedbrake-pos-norm | float |
106 | gear/tailhook/position-norm | float |
107 | gear/launchbar/position-norm | float |
108 | gear/launchbar/state | string |
109 | gear/launchbar/holdback-position-norm | float |
110 | canopy/position-norm | float |
111 | surface-positions/wing-pos-norm | float |
112 | surface-positions/wing-fold-pos-norm | float |
200 | gear/gear[0]/compression-norm | float |
201 | gear/gear[0]/position-norm | float |
210 | gear/gear[1]/compression-norm | float |
211 | gear/gear[1]/position-norm | float |
220 | gear/gear[2]/compression-norm | float |
221 | gear/gear[2]/position-norm | float |
230 | gear/gear[3]/compression-norm | float |
231 | gear/gear[3]/position-norm | float |
240 | gear/gear[4]/compression-norm | float |
241 | gear/gear[4]/position-norm | float |
300 | engines/engine[0]/n1 | float |
301 | engines/engine[0]/n2 | float |
302 | engines/engine[0]/rpm | float |
310 | engines/engine[1]/n1 | float |
311 | engines/engine[1]/n2 | float |
312 | engines/engine[1]/rpm | float |
320 | engines/engine[2]/n1 | float |
321 | engines/engine[2]/n2 | float |
322 | engines/engine[2]/rpm | float |
330 | engines/engine[3]/n1 | float |
331 | engines/engine[3]/n2 | float |
332 | engines/engine[3]/rpm | float |
340 | engines/engine[4]/n1 | float |
341 | engines/engine[4]/n2 | float |
342 | engines/engine[4]/rpm | float |
350 | engines/engine[5]/n1 | float |
351 | engines/engine[5]/n2 | float |
352 | engines/engine[5]/rpm | float |
360 | engines/engine[6]/n1 | float |
361 | engines/engine[6]/n2 | float |
362 | engines/engine[6]/rpm | float |
370 | engines/engine[7]/n1 | float |
371 | engines/engine[7]/n2 | float |
372 | engines/engine[7]/rpm | float |
380 | engines/engine[8]/n1 | float |
381 | engines/engine[8]/n2 | float |
382 | engines/engine[8]/rpm | float |
390 | engines/engine[9]/n1 | float |
391 | engines/engine[9]/n2 | float |
392 | engines/engine[9]/rpm | float |
800 | rotors/main/rpm | float |
801 | rotors/tail/rpm | float |
810 | rotors/main/blade[0]/position-deg | float |
811 | rotors/main/blade[1]/position-deg | float |
812 | rotors/main/blade[2]/position-deg | float |
813 | rotors/main/blade[3]/position-deg | float |
820 | rotors/main/blade[0]/flap-deg | float |
821 | rotors/main/blade[1]/flap-deg | float |
822 | rotors/main/blade[2]/flap-deg | float |
823 | rotors/main/blade[3]/flap-deg | float |
830 | rotors/tail/blade[0]/position-deg | float |
831 | rotors/tail/blade[1]/position-deg | float |
900 | sim/hitches/aerotow/tow/length | float |
901 | sim/hitches/aerotow/tow/elastic-constant | float |
902 | sim/hitches/aerotow/tow/weight-per-m-kg-m | float |
903 | sim/hitches/aerotow/tow/dist | float |
904 | sim/hitches/aerotow/tow/connected-to-property-node | bool |
905 | sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign | string |
906 | sim/hitches/aerotow/tow/brake-force | float |
907 | sim/hitches/aerotow/tow/end-force-x | float |
908 | sim/hitches/aerotow/tow/end-force-y | float |
909 | sim/hitches/aerotow/tow/end-force-z | float |
930 | sim/hitches/aerotow/is-slave | bool |
931 | sim/hitches/aerotow/speed-in-tow-direction | float |
932 | sim/hitches/aerotow/open | bool |
933 | sim/hitches/aerotow/local-pos-x | float |
934 | sim/hitches/aerotow/local-pos-y | float |
935 | sim/hitches/aerotow/local-pos-z | float |
1001 | controls/flight/slats | float |
1002 | controls/flight/speedbrake | float |
1003 | controls/flight/spoilers | float |
1004 | controls/gear/gear-down | float |
1005 | controls/lighting/nav-lights | float |
1006 | controls/armament/station[0]/jettison-all | bool |
1100 | sim/model/variant | int |
1101 | sim/model/livery/file | string |
1200 | environment/wildfire/data | string |
1201 | environment/contrail | int |
1300 | tanker | int |
1400 | scenery/events | string |
1500 | instrumentation/transponder/transmitted-id | int |
1501 | instrumentation/transponder/altitude | int |
1502 | instrumentation/transponder/ident | bool |
1503 | instrumentation/transponder/inputs/mode | int |
10001 | sim/multiplay/transmission-freq-hz | string |
10002 | sim/multiplay/chat | string |
10100 | sim/multiplay/generic/string[0] | string |
10101 | sim/multiplay/generic/string[1] | string |
10102 | sim/multiplay/generic/string[2] | string |
10103 | sim/multiplay/generic/string[3] | string |
10104 | sim/multiplay/generic/string[4] | string |
10105 | sim/multiplay/generic/string[5] | string |
10106 | sim/multiplay/generic/string[6] | string |
10107 | sim/multiplay/generic/string[7] | string |
10108 | sim/multiplay/generic/string[8] | string |
10109 | sim/multiplay/generic/string[9] | string |
10110 | sim/multiplay/generic/string[10] | string |
10111 | sim/multiplay/generic/string[11] | string |
10112 | sim/multiplay/generic/string[12] | string |
10113 | sim/multiplay/generic/string[13] | string |
10114 | sim/multiplay/generic/string[14] | string |
10115 | sim/multiplay/generic/string[15] | string |
10116 | sim/multiplay/generic/string[16] | string |
10117 | sim/multiplay/generic/string[17] | string |
10118 | sim/multiplay/generic/string[18] | string |
10119 | sim/multiplay/generic/string[19] | string |
10200 | sim/multiplay/generic/float[0] | float |
10201 | sim/multiplay/generic/float[1] | float |
10202 | sim/multiplay/generic/float[2] | float |
10203 | sim/multiplay/generic/float[3] | float |
10204 | sim/multiplay/generic/float[4] | float |
10205 | sim/multiplay/generic/float[5] | float |
10206 | sim/multiplay/generic/float[6] | float |
10207 | sim/multiplay/generic/float[7] | float |
10208 | sim/multiplay/generic/float[8] | float |
10209 | sim/multiplay/generic/float[9] | float |
10210 | sim/multiplay/generic/float[10] | float |
10211 | sim/multiplay/generic/float[11] | float |
10212 | sim/multiplay/generic/float[12] | float |
10213 | sim/multiplay/generic/float[13] | float |
10214 | sim/multiplay/generic/float[14] | float |
10215 | sim/multiplay/generic/float[15] | float |
10216 | sim/multiplay/generic/float[16] | float |
10217 | sim/multiplay/generic/float[17] | float |
10218 | sim/multiplay/generic/float[18] | float |
10219 | sim/multiplay/generic/float[19] | float |
10300 | sim/multiplay/generic/int[0] | int |
10301 | sim/multiplay/generic/int[1] | int |
10302 | sim/multiplay/generic/int[2] | int |
10303 | sim/multiplay/generic/int[3] | int |
10304 | sim/multiplay/generic/int[4] | int |
10305 | sim/multiplay/generic/int[5] | int |
10306 | sim/multiplay/generic/int[6] | int |
10307 | sim/multiplay/generic/int[7] | int |
10308 | sim/multiplay/generic/int[8] | int |
10309 | sim/multiplay/generic/int[9] | int |
10310 | sim/multiplay/generic/int[10] | int |
10311 | sim/multiplay/generic/int[11] | int |
10312 | sim/multiplay/generic/int[12] | int |
10313 | sim/multiplay/generic/int[13] | int |
10314 | sim/multiplay/generic/int[14] | int |
10315 | sim/multiplay/generic/int[15] | int |
10316 | sim/multiplay/generic/int[16] | int |
10317 | sim/multiplay/generic/int[17] | int |
10318 | sim/multiplay/generic/int[18] | int |
10319 | sim/multiplay/generic/int[19] | int |
Types
The types are XDR encoded as follows:
- INT: 4 bytes, send unconditionally
- FLOAT: 4 bytes, send unconditionally
- BOOL: 4 bytes, send unconditionally
- STRING [LEN|STR|PAD]:
- LEN: 4 bytes, length of the decoded string
- STR: LEN*4 bytes, encoded string.
- PAD: n*4 bytes, padding.
Caution Due to a bug, all bytes in the STRING field are sent as 4-byte ints (not in the header or the position message). So STR has length LEN*4 and padding (4-LEN%4)*4 bytes, if LEN%4 is not 0. |