do a better job of rejecting messages that have strayed in from a different game.

This commit is contained in:
ehouse 2006-09-15 07:33:59 +00:00
parent 5d64862ba6
commit e61414933f

View file

@ -494,6 +494,7 @@ comms_getInitialAddr( CommsAddrRec* addr )
#ifdef XWFEATURE_BLUETOOTH #ifdef XWFEATURE_BLUETOOTH
addr->conType = COMMS_CONN_BT; /* for temporary ease in debugging */ addr->conType = COMMS_CONN_BT; /* for temporary ease in debugging */
#else #else
addr->conType = COMMS_CONN_RELAY; /* for temporary ease in debugging */
addr->u.ip_relay.ipAddr = 0L; /* force 'em to set it */ addr->u.ip_relay.ipAddr = 0L; /* force 'em to set it */
addr->u.ip_relay.port = 10999; addr->u.ip_relay.port = 10999;
{ {
@ -853,22 +854,26 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
if ( stream_getSize( stream ) if ( stream_getSize( stream )
>= sizeof(channelNo) + sizeof(msgID) + sizeof(lastMsgRcd) ) { >= sizeof(channelNo) + sizeof(msgID) + sizeof(lastMsgRcd) ) {
channelNo = stream_getU16( stream );
XP_STATUSF( "read channelNo %d", channelNo );
if ( channelNo == 0 || channelNo <= comms->nextChannelNo ) {
validMessage = XP_TRUE; validMessage = XP_TRUE;
channelNo = stream_getU16( stream );
msgID = stream_getU32( stream ); msgID = stream_getU32( stream );
lastMsgRcd = stream_getU32( stream ); lastMsgRcd = stream_getU32( stream );
XP_DEBUGF( "rcd: msg " XP_LD " on chnl %d", msgID, channelNo ); XP_DEBUGF( "rcd: msg " XP_LD " on chnl %d", msgID,
channelNo );
removeFromQueue( comms, channelNo, lastMsgRcd ); removeFromQueue( comms, channelNo, lastMsgRcd );
/* Problem: need to detect duplicate messages even before the /* Problem: need to detect duplicate messages even before
server's had a chance to assign channels. Solution, which the server's had a chance to assign channels.
is a hack: since hostID does the same thing, use it in the Solution, which is a hack: since hostID does the same
relay case. But in the relay-less case, which still needs thing, use it in the relay case. But in the relay-less
to work, do assign channels. The dup message problem is case, which still needs to work, do assign channels.
far less common there. */ The dup message problem is far less common there. */
if ( channelNo == 0 ) { if ( channelNo == 0 ) {
XP_ASSERT( comms->isServer ); XP_ASSERT( comms->isServer );
@ -895,11 +900,13 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
} }
#ifdef DEBUG #ifdef DEBUG
if ( !!recs ) { if ( !!recs ) {
XP_ASSERT( lastMsgRcd <= recs->nextMsgID );
XP_ASSERT( lastMsgRcd < 0x0000FFFF ); XP_ASSERT( lastMsgRcd < 0x0000FFFF );
recs->lastACK = (XP_U16)lastMsgRcd; recs->lastACK = (XP_U16)lastMsgRcd;
} }
#endif #endif
} }
}
if ( validMessage ) { if ( validMessage ) {
XP_LOGF( "remembering senderID %x for channel %d", XP_LOGF( "remembering senderID %x for channel %d",
@ -925,6 +932,7 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
} else { } else {
XP_LOGF( "%s: message too small", __FUNCTION__ ); XP_LOGF( "%s: message too small", __FUNCTION__ );
} }
LOG_RETURNF( "%d", (XP_U16)validMessage );
return validMessage; return validMessage;
} /* comms_checkIncomingStream */ } /* comms_checkIncomingStream */