FlightGear
next
mpmessages.hxx
Go to the documentation of this file.
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
// Copyright (C) 2003 Airservices Australia
8
//
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License as
11
// published by the Free Software Foundation; either version 2 of the
12
// License, or (at your option) any later version.
13
//
14
// This program is distributed in the hope that it will be useful, but
15
// WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// General Public License for more details.
18
//
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
//
23
24
#ifndef MPMESSAGES_H
25
#define MPMESSAGES_H
26
27
#define MPMESSAGES_HID "$Id$"
28
29
/****************************************************************
30
* @version $Id$
31
*
32
* Description: Each message used for multiplayer communications
33
* consists of a header and optionally a block of data. The combined
34
* header and data is sent as one IP packet.
35
*
36
******************************************************************/
37
38
#include <vector>
39
40
#include <simgear/compiler.h>
41
#include <simgear/props/props.hxx>
42
#include <simgear/math/SGMath.hxx>
43
#include "
tiny_xdr.hxx
"
44
45
// magic value for messages
46
const
uint32_t
MSG_MAGIC
= 0x46474653;
// "FGFS"
47
// protocoll version
48
const
uint32_t
PROTO_VER
= 0x00010001;
// 1.1
49
50
// Message identifiers
51
#define CHAT_MSG_ID 1
52
#define UNUSABLE_POS_DATA_ID 2
53
#define OLD_OLD_POS_DATA_ID 3
54
#define OLD_POS_DATA_ID 4
55
#define OLD_PROP_MSG_ID 5
56
#define RESET_DATA_ID 6
57
#define POS_DATA_ID 7
58
#define MP_2017_DATA_ID 8
59
60
// XDR demands 4 byte alignment, but some compilers use8 byte alignment
61
// so it's safe to let the overall size of a network message be a
62
// multiple of 8!
63
#define MAX_CALLSIGN_LEN 8
64
#define MAX_CHAT_MSG_LEN 256
65
#define MAX_MODEL_NAME_LEN 96
66
#define MAX_PROPERTY_LEN 52
67
68
// Header for use with all messages sent
69
struct
T_MsgHdr
{
70
xdr_data_t
Magic
;
// Magic Value
71
xdr_data_t
Version
;
// Protocoll version
72
xdr_data_t
MsgId
;
// Message identifier
73
xdr_data_t
MsgLen
;
// absolute length of message
74
xdr_data_t
RequestedRangeNm
;
// obsolete field (ReplyAddress) reused to request a range to fgms
75
xdr_data_t
ReplyPort
;
// player's receiver port
76
char
Callsign
[
MAX_CALLSIGN_LEN
];
// Callsign used by the player
77
};
78
79
// Chat message
80
struct
T_ChatMsg
{
81
char
Text
[
MAX_CHAT_MSG_LEN
];
// Text of chat message
82
};
83
84
// Position message
85
struct
T_PositionMsg
{
86
char
Model
[
MAX_MODEL_NAME_LEN
];
// Name of the aircraft model
87
88
// Time when this packet was generated
89
xdr_data2_t
time
;
90
xdr_data2_t
lag
;
91
92
// position wrt the earth centered frame
93
xdr_data2_t
position
[3];
94
// orientation wrt the earth centered frame, stored in the angle axis
95
// representation where the angle is coded into the axis length
96
xdr_data_t
orientation
[3];
97
98
// linear velocity wrt the earth centered frame measured in
99
// the earth centered frame
100
xdr_data_t
linearVel
[3];
101
// angular velocity wrt the earth centered frame measured in
102
// the earth centered frame
103
xdr_data_t
angularVel
[3];
104
105
// linear acceleration wrt the earth centered frame measured in
106
// the earth centered frame
107
xdr_data_t
linearAccel
[3];
108
// angular acceleration wrt the earth centered frame measured in
109
// the earth centered frame
110
xdr_data_t
angularAccel
[3];
111
// Padding. The alignment is 8 bytes on x86_64 because there are
112
// 8-byte types in the message, so the size should be explicitly
113
// rounded out to a multiple of 8. Of course, it's a bad idea to
114
// put a C struct directly on the wire, but that's a fight for
115
// another day...
116
xdr_data_t
pad
;
117
};
118
119
struct
FGPropertyData
{
120
unsigned
id
;
121
122
// While the type isn't transmitted, it is needed for the destructor
123
simgear::props::Type
type
;
124
union
{
125
int
int_value
;
126
float
float_value
;
127
char
*
string_value
;
128
};
129
FGPropertyData
() :
string_value
(nullptr) {}
130
~FGPropertyData
() {
131
if
((
type
== simgear::props::STRING) || (
type
== simgear::props::UNSPECIFIED))
132
{
133
delete
[]
string_value
;
134
}
135
}
136
};
137
138
139
140
// Position message
141
struct
FGExternalMotionData
{
142
// simulation time when this packet was generated
143
double
time
;
144
// the artificial lag the client should stay behind the average
145
// simulation time to arrival time difference
146
// FIXME: should be some 'per model' instead of 'per packet' property
147
double
lag
;
148
149
// position wrt the earth centered frame
150
SGVec3d
position
;
151
// orientation wrt the earth centered frame
152
SGQuatf
orientation
;
153
154
// linear velocity wrt the earth centered frame measured in
155
// the earth centered frame
156
SGVec3f
linearVel
;
157
// angular velocity wrt the earth centered frame measured in
158
// the earth centered frame
159
SGVec3f
angularVel
;
160
161
// linear acceleration wrt the earth centered frame measured in
162
// the earth centered frame
163
SGVec3f
linearAccel
;
164
// angular acceleration wrt the earth centered frame measured in
165
// the earth centered frame
166
SGVec3f
angularAccel
;
167
168
// The set of properties received for this timeslot
169
std::vector<FGPropertyData*>
properties
;
170
171
~FGExternalMotionData
()
172
{
173
std::vector<FGPropertyData*>::const_iterator propIt;
174
std::vector<FGPropertyData*>::const_iterator propItEnd;
175
propIt =
properties
.begin();
176
propItEnd =
properties
.end();
177
178
while
(propIt != propItEnd)
179
{
180
delete
*propIt;
181
propIt++;
182
}
183
}
184
};
185
186
#endif
MAX_MODEL_NAME_LEN
#define MAX_MODEL_NAME_LEN
Definition
mpmessages.hxx:65
MAX_CALLSIGN_LEN
#define MAX_CALLSIGN_LEN
Definition
mpmessages.hxx:63
MSG_MAGIC
const uint32_t MSG_MAGIC
Definition
mpmessages.hxx:46
MAX_CHAT_MSG_LEN
#define MAX_CHAT_MSG_LEN
Definition
mpmessages.hxx:64
PROTO_VER
const uint32_t PROTO_VER
Definition
mpmessages.hxx:48
FGExternalMotionData
Definition
mpmessages.hxx:141
FGExternalMotionData::time
double time
Definition
mpmessages.hxx:143
FGExternalMotionData::angularVel
SGVec3f angularVel
Definition
mpmessages.hxx:159
FGExternalMotionData::position
SGVec3d position
Definition
mpmessages.hxx:150
FGExternalMotionData::linearAccel
SGVec3f linearAccel
Definition
mpmessages.hxx:163
FGExternalMotionData::lag
double lag
Definition
mpmessages.hxx:147
FGExternalMotionData::angularAccel
SGVec3f angularAccel
Definition
mpmessages.hxx:166
FGExternalMotionData::orientation
SGQuatf orientation
Definition
mpmessages.hxx:152
FGExternalMotionData::linearVel
SGVec3f linearVel
Definition
mpmessages.hxx:156
FGExternalMotionData::~FGExternalMotionData
~FGExternalMotionData()
Definition
mpmessages.hxx:171
FGExternalMotionData::properties
std::vector< FGPropertyData * > properties
Definition
mpmessages.hxx:169
FGPropertyData::string_value
char * string_value
Definition
mpmessages.hxx:127
FGPropertyData::FGPropertyData
FGPropertyData()
Definition
mpmessages.hxx:129
FGPropertyData::id
unsigned id
Definition
mpmessages.hxx:120
FGPropertyData::int_value
int int_value
Definition
mpmessages.hxx:125
FGPropertyData::~FGPropertyData
~FGPropertyData()
Definition
mpmessages.hxx:130
FGPropertyData::float_value
float float_value
Definition
mpmessages.hxx:126
FGPropertyData::type
simgear::props::Type type
Definition
mpmessages.hxx:123
T_ChatMsg
Definition
mpmessages.hxx:80
T_ChatMsg::Text
char Text[256]
Definition
mpmessages.hxx:81
T_MsgHdr
Definition
mpmessages.hxx:69
T_MsgHdr::RequestedRangeNm
xdr_data_t RequestedRangeNm
Definition
mpmessages.hxx:74
T_MsgHdr::Callsign
char Callsign[8]
Definition
mpmessages.hxx:76
T_MsgHdr::Version
xdr_data_t Version
Definition
mpmessages.hxx:71
T_MsgHdr::MsgId
xdr_data_t MsgId
Definition
mpmessages.hxx:72
T_MsgHdr::ReplyPort
xdr_data_t ReplyPort
Definition
mpmessages.hxx:75
T_MsgHdr::Magic
xdr_data_t Magic
Definition
mpmessages.hxx:70
T_MsgHdr::MsgLen
xdr_data_t MsgLen
Definition
mpmessages.hxx:73
T_PositionMsg
Definition
mpmessages.hxx:85
T_PositionMsg::linearVel
xdr_data_t linearVel[3]
Definition
mpmessages.hxx:100
T_PositionMsg::lag
xdr_data2_t lag
Definition
mpmessages.hxx:90
T_PositionMsg::position
xdr_data2_t position[3]
Definition
mpmessages.hxx:93
T_PositionMsg::pad
xdr_data_t pad
Definition
mpmessages.hxx:116
T_PositionMsg::time
xdr_data2_t time
Definition
mpmessages.hxx:89
T_PositionMsg::angularAccel
xdr_data_t angularAccel[3]
Definition
mpmessages.hxx:110
T_PositionMsg::orientation
xdr_data_t orientation[3]
Definition
mpmessages.hxx:96
T_PositionMsg::Model
char Model[96]
Definition
mpmessages.hxx:86
T_PositionMsg::angularVel
xdr_data_t angularVel[3]
Definition
mpmessages.hxx:103
T_PositionMsg::linearAccel
xdr_data_t linearAccel[3]
Definition
mpmessages.hxx:107
tiny_xdr.hxx
xdr_data_t
uint32_t xdr_data_t
Definition
tiny_xdr.hxx:30
xdr_data2_t
uint64_t xdr_data2_t
Definition
tiny_xdr.hxx:31
src
MultiPlayer
mpmessages.hxx
Generated on Tue Jun 3 2025 12:58:40 for FlightGear by
1.13.2