mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
drop duplicate packet rather than asserting
This commit is contained in:
parent
51850ad019
commit
8fa5e3e4bd
1 changed files with 37 additions and 27 deletions
|
@ -706,6 +706,10 @@ handleRegistrationMsg( ServerCtxt* server, XWStreamCtxt* stream )
|
||||||
#endif
|
#endif
|
||||||
for ( ; ii < playersInMsg; ++ii ) {
|
for ( ; ii < playersInMsg; ++ii ) {
|
||||||
clientIndex = registerRemotePlayer( server, stream );
|
clientIndex = registerRemotePlayer( server, stream );
|
||||||
|
if ( -1 == clientIndex ) {
|
||||||
|
success = XP_FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* This is abusing the semantics of turn change -- at least in the
|
/* This is abusing the semantics of turn change -- at least in the
|
||||||
case where there is another device yet to register -- but we
|
case where there is another device yet to register -- but we
|
||||||
|
@ -1133,15 +1137,19 @@ findFirstPending( ServerCtxt* server, ServerPlayer** playerP )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XP_ASSERT( lp >= gi->players ); /* did we find a slot? */
|
if ( lp < gi->players ) { /* did we find a slot? */
|
||||||
*playerP = server->players + nPlayers;
|
XP_LOGF( "%s: no slot found for player; duplicate packet?", __func__ );
|
||||||
|
lp = NULL;
|
||||||
|
} else {
|
||||||
|
*playerP = server->players + nPlayers;
|
||||||
|
}
|
||||||
return lp;
|
return lp;
|
||||||
} /* findFirstPending */
|
} /* findFirstPending */
|
||||||
|
|
||||||
static XP_S8
|
static XP_S8
|
||||||
registerRemotePlayer( ServerCtxt* server, XWStreamCtxt* stream )
|
registerRemotePlayer( ServerCtxt* server, XWStreamCtxt* stream )
|
||||||
{
|
{
|
||||||
XP_S8 deviceIndex;
|
XP_S8 deviceIndex = -1;
|
||||||
XP_PlayerAddr channelNo;
|
XP_PlayerAddr channelNo;
|
||||||
XP_UCHAR* name;
|
XP_UCHAR* name;
|
||||||
XP_U16 nameLen;
|
XP_U16 nameLen;
|
||||||
|
@ -1154,40 +1162,42 @@ registerRemotePlayer( ServerCtxt* server, XWStreamCtxt* stream )
|
||||||
|
|
||||||
/* find the slot to use */
|
/* find the slot to use */
|
||||||
lp = findFirstPending( server, &player );
|
lp = findFirstPending( server, &player );
|
||||||
|
if ( NULL != lp ) {
|
||||||
|
|
||||||
/* get data from stream */
|
/* get data from stream */
|
||||||
lp->robotIQ = 1 == stream_getBits( stream, 1 )? 1 : 0;
|
lp->robotIQ = 1 == stream_getBits( stream, 1 )? 1 : 0;
|
||||||
nameLen = stream_getBits( stream, NAME_LEN_NBITS );
|
nameLen = stream_getBits( stream, NAME_LEN_NBITS );
|
||||||
name = (XP_UCHAR*)XP_MALLOC( server->mpool, nameLen + 1 );
|
name = (XP_UCHAR*)XP_MALLOC( server->mpool, nameLen + 1 );
|
||||||
stream_getBytes( stream, name, nameLen );
|
stream_getBytes( stream, name, nameLen );
|
||||||
name[nameLen] = '\0';
|
name[nameLen] = '\0';
|
||||||
|
|
||||||
replaceStringIfDifferent( server->mpool, &lp->name, name );
|
replaceStringIfDifferent( server->mpool, &lp->name, name );
|
||||||
XP_FREE( server->mpool, name );
|
XP_FREE( server->mpool, name );
|
||||||
|
|
||||||
channelNo = stream_getAddress( stream );
|
channelNo = stream_getAddress( stream );
|
||||||
deviceIndex = getIndexForDevice( server, channelNo );
|
deviceIndex = getIndexForDevice( server, channelNo );
|
||||||
|
|
||||||
--server->nv.pendingRegistrations;
|
--server->nv.pendingRegistrations;
|
||||||
|
|
||||||
if ( deviceIndex == -1 ) {
|
if ( deviceIndex == -1 ) {
|
||||||
RemoteAddress* addr;
|
RemoteAddress* addr;
|
||||||
addr = &server->nv.addresses[server->nv.nDevices];
|
addr = &server->nv.addresses[server->nv.nDevices];
|
||||||
|
|
||||||
XP_ASSERT( channelNo != 0 );
|
XP_ASSERT( channelNo != 0 );
|
||||||
addr->channelNo = channelNo;
|
addr->channelNo = channelNo;
|
||||||
XP_LOGF( "%s: set channelNo to %x for device %d", __func__,
|
XP_LOGF( "%s: set channelNo to %x for device %d", __func__,
|
||||||
channelNo, server->nv.nDevices );
|
channelNo, server->nv.nDevices );
|
||||||
|
|
||||||
deviceIndex = server->nv.nDevices++;
|
deviceIndex = server->nv.nDevices++;
|
||||||
#ifdef STREAM_VERS_BIGBOARD
|
#ifdef STREAM_VERS_BIGBOARD
|
||||||
addr->streamVersion = STREAM_SAVE_PREVWORDS;
|
addr->streamVersion = STREAM_SAVE_PREVWORDS;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
XP_LOGF( "%s: deviceIndex already set", __func__ );
|
XP_LOGF( "%s: deviceIndex already set", __func__ );
|
||||||
}
|
}
|
||||||
|
|
||||||
player->deviceIndex = deviceIndex;
|
player->deviceIndex = deviceIndex;
|
||||||
|
}
|
||||||
return deviceIndex;
|
return deviceIndex;
|
||||||
} /* registerRemotePlayer */
|
} /* registerRemotePlayer */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue