mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-14 20:47:54 +01:00
do a better job of rejecting messages that have strayed in from a different game.
This commit is contained in:
parent
5d64862ba6
commit
e61414933f
1 changed files with 76 additions and 68 deletions
|
@ -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 */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue