]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/mpmessages.hxx
returning addresses of auto vars is *dangerous* (ask Vasilii! :-)
[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 // 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., 675 Mass Ave, Cambridge, MA 02139, 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 <plib/sg.h>
39 #include <simgear/compiler.h>
40 #include "tiny_xdr.hxx"
41
42 // magic value for messages
43 const uint32_t MSG_MAGIC = 0x46474653;  // "FGFS"
44 // protocoll version
45 const uint32_t PROTO_VER = 0x00010001;  // 1.1
46
47 // Message identifiers
48 #define CHAT_MSG_ID             1
49 #define UNUSABLE_POS_DATA_ID    2
50 #define POS_DATA_ID             3
51
52 // XDR demands 4 byte alignment, but some compilers use8 byte alignment
53 // so it's safe to let the overall size of a netmork message be a 
54 // multiple of 8!
55 #define MAX_CALLSIGN_LEN        8
56 #define MAX_CHAT_MSG_LEN        48
57 #define MAX_MODEL_NAME_LEN      48
58
59 /** Aircraft position message */
60 typedef xdr_data2_t xdrPosition[3];
61 typedef xdr_data_t  xdrOrientation[4];
62
63 // Header for use with all messages sent 
64 class T_MsgHdr {
65 public:  
66     xdr_data_t  Magic;                  // Magic Value
67     xdr_data_t  Version;                // Protocoll version
68     xdr_data_t  MsgId;                  // Message identifier 
69     xdr_data_t  MsgLen;                 // absolue length of message
70     xdr_data_t  ReplyAddress;           // (player's receiver address
71     xdr_data_t  ReplyPort;              // player's receiver port
72     char Callsign[MAX_CALLSIGN_LEN];    // Callsign used by the player
73 };
74
75 // Chat message 
76 class T_ChatMsg {
77 public:    
78     char Text[MAX_CHAT_MSG_LEN];       // Text of chat message
79 };
80
81 // Position message
82 class T_PositionMsg {
83 public:
84     char Model[MAX_MODEL_NAME_LEN];    // Name of the aircraft model
85     xdrPosition     PlayerPosition;     // players position
86     xdrOrientation  PlayerOrientation;  // players orientation
87 };
88
89 #endif
90
91