// 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>
+
+#include <simgear/debug/logstream.hxx>
#include <Main/fg_props.hxx>
#include "multiplayrxmgr.hxx"
m_sRxAddress = fgGetString("/sim/multiplay/rxhost");
m_iRxPort = fgGetInt("/sim/multiplay/rxport");
- cout << "FGMultiplayRxMgr::init - rxaddress= " << m_sRxAddress << endl;
- cout << "FGMultiplayRxMgr::init - rxport= " << m_iRxPort << endl;
- cout << "FGMultiplayRxMgr::init - callsign= " << m_sCallsign << endl;
+ SG_LOG( SG_NETWORK, SG_INFO, "FGMultiplayRxMgr::init - rxaddress= "
+ << m_sRxAddress );
+ SG_LOG( SG_NETWORK, SG_INFO, "FGMultiplayRxMgr::init - rxport= "
+ << m_iRxPort);
+ SG_LOG( SG_NETWORK, SG_INFO, "FGMultiplayRxMgr::init - callsign= "
+ << m_sCallsign );
+
// Create and open rx socket
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 {
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;
}
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;
}
// Data received
if (iBytes > 0) {
- if (iBytes >= sizeof(MsgHdr)) {
+ if (iBytes >= (int)sizeof(MsgHdr)) {
// Read header
MsgHdr = (T_MsgHdr *)sMsg;
sCallsign = MsgHdr->sCallsign;
// Process the player data unless we generated it
- if (m_sCallsign != string(MsgHdr->sCallsign)) {
+ if (m_sCallsign != MsgHdr->sCallsign) {
// Process messages
case CHAT_MSG_ID:
if (MsgHdr->iMsgLen == sizeof(T_MsgHdr) + sizeof(T_ChatMsg)) {
ChatMsg = (T_ChatMsg *)(sMsg + sizeof(T_MsgHdr));
- cout << "Chat [" << MsgHdr->sCallsign << "]" << " " << ChatMsg->sText << endl;
+ SG_LOG( SG_NETWORK, SG_BULK, "Chat [" << MsgHdr->sCallsign << "]" << " " << ChatMsg->sText );
} else {
- cerr << "FGMultiplayRxMgr::MP_ProcessData - Chat message received with insufficient data" << endl;
+ SG_LOG( SG_NETWORK, SG_ALERT, "FGMultiplayRxMgr::MP_ProcessData - Chat message received with insufficient data" );
}
break;
if (m_Player[iPlayerCnt]->CompareCallsign(MsgHdr->sCallsign)) {
// Player found. Update the data for the player.
- m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerPos);
+ m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerOrientation, PosMsg->PlayerPosition);
bActivePlayer = true;
}
iPlayerCnt = 0;
do {
if (m_Player[iPlayerCnt] == NULL) {
- cout << "FGMultiplayRxMgr::ProcessRxData - Add new player. IP: " << sIpAddress
- << ", Call: " << sCallsign << ", model: " << sModelName << endl;
+ 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]->SetPosition(PosMsg->PlayerPos);
+ m_Player[iPlayerCnt]->Open(sIpAddress, iPort, sCallsign, sModelName, false);
+ m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerOrientation, PosMsg->PlayerPosition);
bActivePlayer = true;
}
iPlayerCnt++;
// 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;
******************************************************************/
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;
}
}
+#endif // FG_MPLAYER_AS