]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/mpmessages.hxx
Vivian Meazza:
[flightgear.git] / src / MultiPlayer / mpmessages.hxx
1 // mpmessages.hxx -- Message definitions for multiplayer communications
2 // within a multiplayer Flightgear
3 //
4 // Written by Duncan McCreanor, started February 2003.
5 // duncan.mccreanor@airservicesaustralia.com
6 //
7 // With minor additions be Vivian Meazza, January 2006
8 //
9 // Copyright (C) 2003  Airservices Australia
10 //
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of the
14 // License, or (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 // General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25
26 #ifndef MPMESSAGES_H
27 #define MPMESSAGES_H
28
29 #define MPMESSAGES_HID "$Id$"
30
31 /****************************************************************
32 * @version $Id$
33 *
34 * Description: Each message used for multiplayer communications
35 * consists of a header and optionally a block of data. The combined
36 * header and data is sent as one IP packet.
37 *
38 ******************************************************************/
39
40 #include <plib/sg.h>
41 #include <simgear/compiler.h>
42 #include "tiny_xdr.hxx"
43
44 // magic value for messages
45 const uint32_t MSG_MAGIC = 0x46474653;  // "FGFS"
46 // protocoll version
47 const uint32_t PROTO_VER = 0x00010001;  // 1.1
48
49 // Message identifiers
50 #define CHAT_MSG_ID             1
51 #define UNUSABLE_POS_DATA_ID    2
52 #define OLD_POS_DATA_ID         3
53 #define POS_DATA_ID             4
54 #define PROP_MSG_ID             5
55
56 // XDR demands 4 byte alignment, but some compilers use8 byte alignment
57 // so it's safe to let the overall size of a network message be a 
58 // multiple of 8!
59 #define MAX_CALLSIGN_LEN        8
60 #define MAX_CHAT_MSG_LEN        256
61 #define MAX_MODEL_NAME_LEN      96
62 #define MAX_PROPERTY_LEN        52
63
64 /** Aircraft position message */
65 typedef xdr_data2_t xdrPosition[3];
66 typedef xdr_data_t  xdrOrientation[4];
67
68 // Header for use with all messages sent 
69 class T_MsgHdr {
70 public:  
71     xdr_data_t  Magic;                  // Magic Value
72     xdr_data_t  Version;                // Protocoll version
73     xdr_data_t  MsgId;                  // Message identifier 
74     xdr_data_t  MsgLen;                 // absolute length of message
75     xdr_data_t  ReplyAddress;           // (player's receiver address
76     xdr_data_t  ReplyPort;              // player's receiver port
77     char Callsign[MAX_CALLSIGN_LEN];    // Callsign used by the player
78 };
79
80 // Chat message 
81 class T_ChatMsg {
82 public:    
83     char Text[MAX_CHAT_MSG_LEN];       // Text of chat message
84 };
85
86 // Position message
87 class T_PositionMsg {
88 public:
89     char Model[MAX_MODEL_NAME_LEN];    // Name of the aircraft model
90     xdr_data_t  time;                  // Time when this packet was generated
91     xdr_data_t  timeusec;              // Microsecs when this packet was generated
92     xdr_data2_t lat;                   // Position, orientation, speed
93     xdr_data2_t lon;                   // ...
94     xdr_data2_t alt;                   // ...
95     xdr_data2_t hdg;                   // ...
96     xdr_data2_t roll;                  // ...
97     xdr_data2_t pitch;                 // ...
98     xdr_data2_t speedN;                // ...
99     xdr_data2_t speedE;                // ...
100     xdr_data2_t speedD;                // ...
101         xdr_data_t  accN;                                  // acceleration N
102         xdr_data_t  accE;                  // acceleration E
103         xdr_data_t  accD;                  // acceleration D
104     xdr_data_t  left_aileron;          // control positions
105     xdr_data_t  right_aileron;         // control positions
106     xdr_data_t  elevator;              // ...
107     xdr_data_t  rudder;                // ...
108 //    xdr_data_t  rpms[6];               // RPMs of all of the motors
109     xdr_data_t  rateH;                 // Rate of change of heading
110     xdr_data_t  rateR;                 // roll
111     xdr_data_t  rateP;                 // and pitch
112 //      xdr_data_t  dummy;                 // pad message length
113 };
114
115 // Property message
116 class T_PropertyMsg {
117 public:
118     char property[MAX_PROPERTY_LEN];    // the property name
119     xdr_data_t  type;                                   // the type
120     xdr_data2_t val;                                    // and value
121 //      xdr_data2_t dummy;                                      // pad message length
122         
123 };
124
125 #endif
126
127