Merge branch 'next' of git://gitorious.org/fg/flightgear into next
This commit is contained in:
commit
5402ab5a1b
2 changed files with 46 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// multiplaymgr.hpp
|
// multiplaymgr.cxx
|
||||||
//
|
//
|
||||||
// Written by Duncan McCreanor, started February 2003.
|
// Written by Duncan McCreanor, started February 2003.
|
||||||
// duncan.mccreanor@airservicesaustralia.com
|
// duncan.mccreanor@airservicesaustralia.com
|
||||||
|
@ -526,16 +526,46 @@ union FGMultiplayMgr::MsgBuf
|
||||||
T_MsgHdr Header;
|
T_MsgHdr Header;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
FGMultiplayMgr::isSane(const FGExternalMotionData& motionInfo)
|
||||||
|
{
|
||||||
|
// check for corrupted data (NaNs)
|
||||||
|
bool isCorrupted = false;
|
||||||
|
isCorrupted |= ((osg::isNaN(motionInfo.time )) ||
|
||||||
|
(osg::isNaN(motionInfo.lag )) ||
|
||||||
|
(osg::isNaN(motionInfo.orientation(3) )));
|
||||||
|
for (unsigned i = 0; (i < 3)&&(!isCorrupted); ++i)
|
||||||
|
{
|
||||||
|
isCorrupted |= ((osg::isNaN(motionInfo.position(i) ))||
|
||||||
|
(osg::isNaN(motionInfo.orientation(i) ))||
|
||||||
|
(osg::isNaN(motionInfo.linearVel(i)) )||
|
||||||
|
(osg::isNaN(motionInfo.angularVel(i)) )||
|
||||||
|
(osg::isNaN(motionInfo.linearAccel(i)) )||
|
||||||
|
(osg::isNaN(motionInfo.angularAccel(i)) ));
|
||||||
|
}
|
||||||
|
return !isCorrupted;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
|
FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
|
||||||
{
|
{
|
||||||
if ((! mInitialised) || (! mHaveServer))
|
if ((! mInitialised) || (! mHaveServer))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (! mHaveServer) {
|
if (! mHaveServer) {
|
||||||
SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::SendMyPosition - no server");
|
SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::SendMyPosition - no server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isSane(motionInfo))
|
||||||
|
{
|
||||||
|
// Current local data is invalid (NaN), so stop MP transmission.
|
||||||
|
// => Be nice to older FG versions (no NaN checks) and don't waste bandwidth.
|
||||||
|
SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::SendMyPosition - "
|
||||||
|
<< "Local data is invalid (NaN). Data not transmitted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static MsgBuf msgBuf;
|
static MsgBuf msgBuf;
|
||||||
static unsigned msgLen = 0;
|
static unsigned msgLen = 0;
|
||||||
T_PositionMsg* PosMsg = msgBuf.posMsg();
|
T_PositionMsg* PosMsg = msgBuf.posMsg();
|
||||||
|
@ -780,7 +810,7 @@ FGMultiplayMgr::update(double)
|
||||||
}
|
}
|
||||||
if (MsgHdr->Version != PROTO_VER) {
|
if (MsgHdr->Version != PROTO_VER) {
|
||||||
SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
|
SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
|
||||||
<< "message has invalid protocoll number!" );
|
<< "message has invalid protocol number!" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (MsgHdr->MsgLen != bytes) {
|
if (MsgHdr->MsgLen != bytes) {
|
||||||
|
@ -858,6 +888,15 @@ FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
|
||||||
for (unsigned i = 0; i < 3; ++i)
|
for (unsigned i = 0; i < 3; ++i)
|
||||||
motionInfo.angularAccel(i) = XDR_decode_float(PosMsg->angularAccel[i]);
|
motionInfo.angularAccel(i) = XDR_decode_float(PosMsg->angularAccel[i]);
|
||||||
|
|
||||||
|
// sanity check: do not allow injection of corrupted data (NaNs)
|
||||||
|
if (!isSane(motionInfo))
|
||||||
|
{
|
||||||
|
// drop this message, keep old position until receiving valid data
|
||||||
|
SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::ProcessPosMsg - "
|
||||||
|
<< "Position message with invalid data (NaN) received from "
|
||||||
|
<< MsgHdr->Callsign);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//cout << "INPUT MESSAGE\n";
|
//cout << "INPUT MESSAGE\n";
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// multiplaymgr.hpp
|
// multiplaymgr.hxx
|
||||||
//
|
//
|
||||||
// Written by Duncan McCreanor, started February 2003.
|
// Written by Duncan McCreanor, started February 2003.
|
||||||
// duncan.mccreanor@airservicesaustralia.com
|
// duncan.mccreanor@airservicesaustralia.com
|
||||||
|
@ -81,6 +81,7 @@ private:
|
||||||
void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
|
void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
|
||||||
long stamp);
|
long stamp);
|
||||||
void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
|
void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
|
||||||
|
bool isSane(const FGExternalMotionData& motionInfo);
|
||||||
|
|
||||||
/// maps from the callsign string to the FGAIMultiplayer
|
/// maps from the callsign string to the FGAIMultiplayer
|
||||||
typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
|
typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
|
||||||
|
|
Loading…
Add table
Reference in a new issue