]> git.mxchange.org Git - flightgear.git/blobdiff - src/MultiPlayer/multiplayrxmgr.cxx
Finish what was committed in a broken state yesterday.
[flightgear.git] / src / MultiPlayer / multiplayrxmgr.cxx
index e5bd29c6b0b902540d7eadaa91ec07a7bcf17ecc..474a09faf14371c7effb6f9ecbf975d05751452f 100644 (file)
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 //
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef FG_MPLAYER_AS
 
 /******************************************************************
 * $Id$
 ******************************************************************/
 
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#if !(defined(_MSC_VER) || defined(__MINGW32__))
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
 #include <plib/netSocket.h>
 #include <stdlib.h>
 
@@ -133,7 +140,7 @@ bool FGMultiplayRxMgr::init(void) {
         mDataRxSocket = new netSocket();
         if (!mDataRxSocket->open(false)) {
             // Failed to open rx socket
-            cerr << "FGMultiplayRxMgr::Open - Failed to create data receive socket" << endl;
+            SG_LOG( SG_NETWORK, SG_ALERT, "FGMultiplayRxMgr::Open - Failed to create data receive socket" );
             bSuccess = false;
         } else {
 
@@ -143,7 +150,7 @@ bool FGMultiplayRxMgr::init(void) {
             if (mDataRxSocket->bind(m_sRxAddress.c_str(), m_iRxPort) != 0) {
                 perror("bind");
                 // Failed to bind
-                cerr << "FGMultiplayRxMgr::Open - Failed to bind receive socket" << endl;
+                SG_LOG( SG_NETWORK, SG_ALERT, "FGMultiplayRxMgr::Open - Failed to bind receive socket" );
                 bSuccess = false;
             }
 
@@ -153,7 +160,7 @@ bool FGMultiplayRxMgr::init(void) {
         m_bInitialised = bSuccess;
 
     } else {
-        cerr << "FGMultiplayRxMgr::OpenRx - Receiver open requested when receiver is already open" << endl;
+        SG_LOG( SG_NETWORK, SG_ALERT, "FGMultiplayRxMgr::OpenRx - Receiver open requested when receiver is already open" );
         bSuccess = false;
     }
 
@@ -226,7 +233,7 @@ void FGMultiplayRxMgr::ProcessData(void) {
 
             // Data received
             if (iBytes > 0) {
-                if (iBytes >= sizeof(MsgHdr)) {
+                if (iBytes >= (int)sizeof(MsgHdr)) {
 
                     // Read header
                     MsgHdr = (T_MsgHdr *)sMsg;
@@ -276,7 +283,7 @@ void FGMultiplayRxMgr::ProcessData(void) {
                                             if (m_Player[iPlayerCnt] == NULL) {
                                                 SG_LOG( SG_NETWORK, SG_INFO, "FGMultiplayRxMgr::ProcessRxData - Add new player. IP: " << sIpAddress << ", Call: " <<  sCallsign << ", model: " << sModelName );
                                                 m_Player[iPlayerCnt] = new MPPlayer;
-                                                m_Player[iPlayerCnt]->Open(string(sIpAddress), iPort, string(sCallsign), string(sModelName), false);
+                                                m_Player[iPlayerCnt]->Open(sIpAddress, iPort, sCallsign, sModelName, false);
                                                 m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerPos);
                                                 bActivePlayer = true;
                                             }
@@ -286,18 +293,18 @@ void FGMultiplayRxMgr::ProcessData(void) {
                                         // Check if the player was added
                                         if (!bActivePlayer) {
                                             if (iPlayerCnt == MAX_PLAYERS) {
-                                                cerr << "FGMultiplayRxMgr::MP_ProcessData - Unable to add new player (" << sCallsign << "). Too many players." << endl;
+                                                SG_LOG( SG_NETWORK, SG_ALERT, "FGMultiplayRxMgr::MP_ProcessData - Unable to add new player (" << sCallsign << "). Too many players." );
                                             }
                                         }
                                     }
 
                                 } else {
-                                    cerr << "FGMultiplayRxMgr::MP_ProcessData - Position message received with insufficient data" << endl;
+                                    SG_LOG( SG_NETWORK, SG_ALERT, "FGMultiplayRxMgr::MP_ProcessData - Position message received with insufficient data" );
                                 }
                                 break;
 
                             default:
-                                cerr << "FGMultiplayRxMgr::MP_ProcessData - Unknown message Id received: " << MsgHdr->MsgId << endl;
+                                SG_LOG( SG_NETWORK, SG_ALERT, "FGMultiplayRxMgr::MP_ProcessData - Unknown message Id received: " << MsgHdr->MsgId );
                                 break;
 
 
@@ -330,16 +337,18 @@ void FGMultiplayRxMgr::ProcessData(void) {
 ******************************************************************/
 void FGMultiplayRxMgr::Update(void) {
 
-    int iPlayerDataState;
+    MPPlayer::TPlayerDataState ePlayerDataState;
     int iPlayerId;
 
     for (iPlayerId = 0; iPlayerId < MAX_PLAYERS; iPlayerId++) {
         if (m_Player[iPlayerId] != NULL) {
-            iPlayerDataState = m_Player[iPlayerId]->Draw();
+            ePlayerDataState = m_Player[iPlayerId]->Draw();
 
             // If the player has not received an update for some
             // time then assume that the player has quit.
-            if (iPlayerDataState == PLAYER_DATA_EXPIRED) {
+            if (ePlayerDataState == MPPlayer::PLAYER_DATA_EXPIRED) {
+                SG_LOG( SG_NETWORK, SG_BULK, "FGMultiplayRxMgr::Update - Deleting player from game. Callsign: "
+                        << m_Player[iPlayerId]->Callsign() );
                 delete m_Player[iPlayerId];
                 m_Player[iPlayerId] = NULL;
             }
@@ -349,4 +358,5 @@ void FGMultiplayRxMgr::Update(void) {
 
 }
 
+#endif // FG_MPLAYER_AS