#include <iostream>
#include <algorithm>
#include <cstring>
+#include <errno.h>
#include <osg/Math> // isNaN
#include <simgear/misc/stdint.hxx>
{1300, "tanker", simgear::props::INT},
+ {1400, "scenery/events", simgear::props::STRING},
+
{10001, "sim/multiplay/transmission-freq-hz", simgear::props::STRING},
{10002, "sim/multiplay/chat", simgear::props::STRING},
mTimeUntilSend = 0.0;
mCallsign = fgGetString("/sim/multiplay/callsign");
- if (!txAddress.empty()) {
+ if ((!txAddress.empty()) && (txAddress!="0")) {
mServer.set(txAddress.c_str(), txPort);
if (strncmp (mServer.getHost(), "0.0.0.0", 8) == 0) {
mHaveServer = false;
- SG_LOG(SG_NETWORK, SG_WARN,
- "FGMultiplayMgr - could not resolve '"
- << txAddress << "', Multiplayermode disabled");
+ SG_LOG(SG_NETWORK, SG_ALERT,
+ "FGMultiplayMgr - Could not resolve '"
+ << txAddress << "'. Multiplayer mode disabled.");
return;
} else {
- SG_LOG(SG_NETWORK, SG_INFO, "have server");
+ SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - have server");
mHaveServer = true;
}
if (rxPort <= 0)
rxPort = txPort;
}
if (rxPort <= 0) {
- SG_LOG(SG_NETWORK, SG_DEBUG,
- "FGMultiplayMgr - No receiver port, Multiplayermode disabled");
+ SG_LOG(SG_NETWORK, SG_INFO,
+ "FGMultiplayMgr - No receiver port. Multiplayer mode disabled.");
return;
}
if (mCallsign.empty())
mSocket.reset(new simgear::Socket());
if (!mSocket->open(false)) {
SG_LOG( SG_NETWORK, SG_WARN,
- "FGMultiplayMgr::init - Failed to create data socket" );
+ "FGMultiplayMgr - Failed to create data socket. Multiplayer mode disabled." );
return;
}
mSocket->setBlocking(false);
if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) {
- perror("bind");
- SG_LOG( SG_NETWORK, SG_DEBUG,
- "FGMultiplayMgr::Open - Failed to bind receive socket" );
+ SG_LOG( SG_NETWORK, SG_ALERT,
+ "FGMultiplayMgr - Failed to bind receive socket. Multiplayer mode disabled. "
+ << strerror(errno) << "(errno " << errno << ")");
return;
}
fgSetBool("/sim/multiplay/online", true);
mInitialised = true;
+
+ SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer mode active!");
} // FGMultiplayMgr::init()
//////////////////////////////////////////////////////////////////////
strncpy(PosMsg->Model, fgGetString("/sim/model/path"), MAX_MODEL_NAME_LEN);
PosMsg->Model[MAX_MODEL_NAME_LEN - 1] = '\0';
- if (fgGetBool("/sim/freeze/replay-state", true))
+ if (fgGetBool("/sim/freeze/replay-state", true)&&
+ fgGetBool("/sim/multiplay/freeze-on-replay",true))
{
// do not send position updates during replay
for (unsigned i = 0 ; i < 3; ++i)
// packet waiting to be processed.
//////////////////////////////////////////////////
simgear::IPAddress SenderAddress;
- bytes = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
+ int RecvStatus = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
&SenderAddress);
//////////////////////////////////////////////////
// no Data received
//////////////////////////////////////////////////
- if (bytes <= 0) {
- if (errno != EAGAIN && errno != 0) // MSVC output "NoError" otherwise
- perror("FGMultiplayMgr::MP_ProcessData");
- break;
+ if (RecvStatus == 0)
+ break;
+
+ // socket error reported?
+ // errno isn't thread-safe - so only check its value when
+ // socket return status < 0 really indicates a failure.
+ if ((RecvStatus < 0)&&
+ ((errno == EAGAIN) || (errno == 0))) // MSVC output "NoError" otherwise
+ {
+ // ignore "normal" errors
+ break;
}
+
+ if (RecvStatus<0)
+ {
+ SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - Unable to receive data. "
+ << strerror(errno) << "(errno " << errno << ")");
+ break;
+ }
+
+ // status is positive: bytes received
+ bytes = (ssize_t) RecvStatus;
if (bytes <= static_cast<ssize_t>(sizeof(T_MsgHdr))) {
SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
<< "received message with insufficient data" );
mp->setCallSign(callsign);
mMultiPlayerMap[callsign] = mp;
- FGAIManager *aiMgr = (FGAIManager*)globals->get_subsystem("ai_model");
+ FGAIManager *aiMgr = (FGAIManager*)globals->get_subsystem("ai-model");
if (aiMgr) {
aiMgr->attach(mp);