2003-03-26 14:06:51 +00:00
|
|
|
// mpmessages.hxx -- Message definitions for multiplayer communications
|
|
|
|
// within a multiplayer Flightgear
|
|
|
|
//
|
|
|
|
// Written by Duncan McCreanor, started February 2003.
|
|
|
|
// duncan.mccreanor@airservicesaustralia.com
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 Airservices Australia
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-03-26 14:06:51 +00:00
|
|
|
//
|
|
|
|
|
2003-03-19 20:45:09 +00:00
|
|
|
#ifndef MPMESSAGES_H
|
|
|
|
#define MPMESSAGES_H
|
|
|
|
|
|
|
|
#define MPMESSAGES_HID "$Id$"
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* @version $Id$
|
|
|
|
*
|
|
|
|
* Description: Each message used for multiplayer communications
|
|
|
|
* consists of a header and optionally a block of data. The combined
|
|
|
|
* header and data is sent as one IP packet.
|
|
|
|
*
|
|
|
|
******************************************************************/
|
|
|
|
|
2006-02-17 09:43:33 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2005-11-01 13:41:49 +00:00
|
|
|
#include <simgear/compiler.h>
|
2006-10-10 05:17:07 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
2006-02-17 09:43:33 +00:00
|
|
|
#include <simgear/math/SGMath.hxx>
|
2005-11-01 13:41:49 +00:00
|
|
|
#include "tiny_xdr.hxx"
|
2003-03-19 20:45:09 +00:00
|
|
|
|
2005-09-18 12:37:18 +00:00
|
|
|
// magic value for messages
|
|
|
|
const uint32_t MSG_MAGIC = 0x46474653; // "FGFS"
|
|
|
|
// protocoll version
|
|
|
|
const uint32_t PROTO_VER = 0x00010001; // 1.1
|
2003-03-19 20:45:09 +00:00
|
|
|
|
2005-09-18 12:37:18 +00:00
|
|
|
// Message identifiers
|
|
|
|
#define CHAT_MSG_ID 1
|
|
|
|
#define UNUSABLE_POS_DATA_ID 2
|
2006-02-17 09:43:33 +00:00
|
|
|
#define OLD_OLD_POS_DATA_ID 3
|
|
|
|
#define OLD_POS_DATA_ID 4
|
|
|
|
#define OLD_PROP_MSG_ID 5
|
|
|
|
#define RESET_DATA_ID 6
|
|
|
|
#define POS_DATA_ID 7
|
2017-02-04 22:59:14 +00:00
|
|
|
#define MP_2017_DATA_ID 8
|
2003-03-19 20:45:09 +00:00
|
|
|
|
2005-09-18 12:37:18 +00:00
|
|
|
// XDR demands 4 byte alignment, but some compilers use8 byte alignment
|
2006-02-09 12:29:05 +00:00
|
|
|
// so it's safe to let the overall size of a network message be a
|
2005-09-18 12:37:18 +00:00
|
|
|
// multiple of 8!
|
|
|
|
#define MAX_CALLSIGN_LEN 8
|
2006-02-09 12:29:05 +00:00
|
|
|
#define MAX_CHAT_MSG_LEN 256
|
|
|
|
#define MAX_MODEL_NAME_LEN 96
|
|
|
|
#define MAX_PROPERTY_LEN 52
|
2003-03-19 20:45:09 +00:00
|
|
|
|
2005-09-18 12:37:18 +00:00
|
|
|
// Header for use with all messages sent
|
2006-02-17 09:43:33 +00:00
|
|
|
struct T_MsgHdr {
|
2005-09-18 12:37:18 +00:00
|
|
|
xdr_data_t Magic; // Magic Value
|
|
|
|
xdr_data_t Version; // Protocoll version
|
|
|
|
xdr_data_t MsgId; // Message identifier
|
2006-02-09 12:29:05 +00:00
|
|
|
xdr_data_t MsgLen; // absolute length of message
|
2017-02-24 23:38:50 +00:00
|
|
|
xdr_data_t RequestedRangeNm; // obsolete field (ReplyAddress) reused to request a range to fgms
|
2005-10-30 18:01:51 +00:00
|
|
|
xdr_data_t ReplyPort; // player's receiver port
|
|
|
|
char Callsign[MAX_CALLSIGN_LEN]; // Callsign used by the player
|
2005-09-18 12:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Chat message
|
2006-02-17 09:43:33 +00:00
|
|
|
struct T_ChatMsg {
|
2005-10-30 18:01:51 +00:00
|
|
|
char Text[MAX_CHAT_MSG_LEN]; // Text of chat message
|
2005-09-18 12:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Position message
|
2006-02-17 09:43:33 +00:00
|
|
|
struct T_PositionMsg {
|
2005-10-30 18:01:51 +00:00
|
|
|
char Model[MAX_MODEL_NAME_LEN]; // Name of the aircraft model
|
2006-02-17 09:43:33 +00:00
|
|
|
|
|
|
|
// Time when this packet was generated
|
|
|
|
xdr_data2_t time;
|
|
|
|
xdr_data2_t lag;
|
|
|
|
|
|
|
|
// position wrt the earth centered frame
|
|
|
|
xdr_data2_t position[3];
|
|
|
|
// orientation wrt the earth centered frame, stored in the angle axis
|
|
|
|
// representation where the angle is coded into the axis length
|
|
|
|
xdr_data_t orientation[3];
|
|
|
|
|
|
|
|
// linear velocity wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
xdr_data_t linearVel[3];
|
|
|
|
// angular velocity wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
xdr_data_t angularVel[3];
|
|
|
|
|
|
|
|
// linear acceleration wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
xdr_data_t linearAccel[3];
|
|
|
|
// angular acceleration wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
xdr_data_t angularAccel[3];
|
2009-01-15 15:03:34 +00:00
|
|
|
// Padding. The alignment is 8 bytes on x86_64 because there are
|
|
|
|
// 8-byte types in the message, so the size should be explicitly
|
|
|
|
// rounded out to a multiple of 8. Of course, it's a bad idea to
|
|
|
|
// put a C struct directly on the wire, but that's a fight for
|
|
|
|
// another day...
|
|
|
|
xdr_data_t pad;
|
2006-02-09 12:29:05 +00:00
|
|
|
};
|
|
|
|
|
2006-10-10 05:17:07 +00:00
|
|
|
struct FGPropertyData {
|
2006-02-17 09:43:33 +00:00
|
|
|
unsigned id;
|
2006-10-10 05:17:07 +00:00
|
|
|
|
|
|
|
// While the type isn't transmitted, it is needed for the destructor
|
2009-07-15 23:15:17 +00:00
|
|
|
simgear::props::Type type;
|
2006-10-10 05:17:07 +00:00
|
|
|
union {
|
|
|
|
int int_value;
|
|
|
|
float float_value;
|
|
|
|
char* string_value;
|
|
|
|
};
|
2017-05-17 22:15:43 +00:00
|
|
|
FGPropertyData() : string_value(nullptr) {}
|
2006-10-10 05:17:07 +00:00
|
|
|
~FGPropertyData() {
|
2009-07-15 23:15:17 +00:00
|
|
|
if ((type == simgear::props::STRING) || (type == simgear::props::UNSPECIFIED))
|
2006-10-10 05:17:07 +00:00
|
|
|
{
|
|
|
|
delete [] string_value;
|
|
|
|
}
|
|
|
|
}
|
2006-02-17 09:43:33 +00:00
|
|
|
};
|
2003-03-19 20:45:09 +00:00
|
|
|
|
2006-10-10 05:17:07 +00:00
|
|
|
|
|
|
|
|
2006-02-17 09:43:33 +00:00
|
|
|
// Position message
|
|
|
|
struct FGExternalMotionData {
|
|
|
|
// simulation time when this packet was generated
|
|
|
|
double time;
|
|
|
|
// the artificial lag the client should stay behind the average
|
2011-02-15 23:49:00 +00:00
|
|
|
// simulation time to arrival time difference
|
2006-02-17 09:43:33 +00:00
|
|
|
// FIXME: should be some 'per model' instead of 'per packet' property
|
|
|
|
double lag;
|
|
|
|
|
|
|
|
// position wrt the earth centered frame
|
|
|
|
SGVec3d position;
|
|
|
|
// orientation wrt the earth centered frame
|
|
|
|
SGQuatf orientation;
|
|
|
|
|
|
|
|
// linear velocity wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
SGVec3f linearVel;
|
|
|
|
// angular velocity wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
SGVec3f angularVel;
|
|
|
|
|
|
|
|
// linear acceleration wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
SGVec3f linearAccel;
|
|
|
|
// angular acceleration wrt the earth centered frame measured in
|
|
|
|
// the earth centered frame
|
|
|
|
SGVec3f angularAccel;
|
|
|
|
|
2011-05-29 16:46:11 +00:00
|
|
|
// The set of properties received for this timeslot
|
2006-10-10 05:17:07 +00:00
|
|
|
std::vector<FGPropertyData*> properties;
|
2011-02-15 23:49:00 +00:00
|
|
|
|
|
|
|
~FGExternalMotionData()
|
|
|
|
{
|
|
|
|
std::vector<FGPropertyData*>::const_iterator propIt;
|
|
|
|
std::vector<FGPropertyData*>::const_iterator propItEnd;
|
|
|
|
propIt = properties.begin();
|
|
|
|
propItEnd = properties.end();
|
|
|
|
|
|
|
|
while (propIt != propItEnd)
|
|
|
|
{
|
|
|
|
delete *propIt;
|
|
|
|
propIt++;
|
|
|
|
}
|
|
|
|
}
|
2006-02-17 09:43:33 +00:00
|
|
|
};
|
2003-03-19 20:45:09 +00:00
|
|
|
|
2006-02-17 09:43:33 +00:00
|
|
|
#endif
|