]> git.mxchange.org Git - flightgear.git/blobdiff - src/MultiPlayer/mpmessages.hxx
Oliver Schroeder:
[flightgear.git] / src / MultiPlayer / mpmessages.hxx
index b0f91b268331b0b800b0fa6d7de698185941e0ec..65d00011a52fa948970521ee03cb3fdf01803d55 100644 (file)
 *
 ******************************************************************/
 
-#include <stdint.h>
+#include <simgear/compiler.h>
+#include "tiny_xdr.hpp"
 #include <plib/sg.h>
 
-// Message identifiers
-#define CHAT_MSG_ID 1
-#define UNUSABLE_POS_DATA_ID 2
-#define POS_DATA_ID 3
-/* should be a multiple of 8! */
-#define MAX_CALLSIGN_LEN 8
-/** Header for use with all messages sent */
-typedef struct {
-
-    /** Message identifier, multiple of 8! */
-    uint32_t MsgId;
-
-    /** Length of the message inclusive of this header */
-    uint32_t iMsgLen;
-
-    /** IP address for reply to message (player's receiver address) */
-    uint32_t lReplyAddress;
-
-    /** Port for replies (player's receiver port) */
-    uint32_t iReplyPort;
-
-    /** Callsign used by the player */
-    char sCallsign[MAX_CALLSIGN_LEN];
-
-} T_MsgHdr;
+// magic value for messages
+const uint32_t MSG_MAGIC = 0x46474653;  // "FGFS"
+// protocoll version
+const uint32_t PROTO_VER = 0x00010001;  // 1.1
 
-#define MAX_CHAT_MSG_LEN 48
-/** Chat message */
-typedef struct {
-
-    /** Text of chat message */
-    char sText[MAX_CHAT_MSG_LEN];
+// Message identifiers
+#define CHAT_MSG_ID             1
+#define UNUSABLE_POS_DATA_ID    2
+#define POS_DATA_ID             3
 
-} T_ChatMsg;
+// XDR demands 4 byte alignment, but some compilers use8 byte alignment
+// so it's safe to let the overall size of a netmork message be a 
+// multiple of 8!
+#define MAX_CALLSIGN_LEN        8
+#define MAX_CHAT_MSG_LEN        48
+#define MAX_MODEL_NAME_LEN      48
 
-/* should be a multiple of 8! */
-#define MAX_MODEL_NAME_LEN 48
 /** Aircraft position message */
-typedef struct {
-
-    /** Name of the aircraft model */
-    char sModel[MAX_MODEL_NAME_LEN];
-
-    /** Position data for the aircraft */
-    sgdVec3 PlayerPosition;
-    sgQuat PlayerOrientation;
-
-} T_PositionMsg;
-
+typedef xdr_data2_t xdrPosition[3];
+typedef xdr_data_t  xdrOrientation[4];
+
+// Header for use with all messages sent 
+class T_MsgHdr {
+public:  
+    xdr_data_t  Magic;                  // Magic Value
+    xdr_data_t  Version;                // Protocoll version
+    xdr_data_t  MsgId;                  // Message identifier 
+    xdr_data_t  iMsgLen;                // absolue length of message
+    xdr_data_t  lReplyAddress;          // (player's receiver address
+    xdr_data_t  iReplyPort;             // player's receiver port
+    char sCallsign[MAX_CALLSIGN_LEN];   // Callsign used by the player
+};
+
+// Chat message 
+class T_ChatMsg {
+public:    
+    char sText[MAX_CHAT_MSG_LEN];       // Text of chat message
+};
+
+// Position message
+class T_PositionMsg {
+public:
+    char sModel[MAX_MODEL_NAME_LEN];    // Name of the aircraft model
+    xdrPosition     PlayerPosition;     // players position
+    xdrOrientation  PlayerOrientation;  // players orientation
+};
 
 #endif