mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
fix number of missing players not being calculated correctly
This commit is contained in:
parent
113c7a13d2
commit
3d6f972e9e
3 changed files with 31 additions and 21 deletions
|
@ -83,6 +83,7 @@
|
|||
#define STREAM_VERS_41B4 0x02
|
||||
#define STREAM_VERS_405 0x01
|
||||
|
||||
/* search for FIX_NEXT_VERSION_CHANGE next time this is changed */
|
||||
#define CUR_STREAM_VERS STREAM_VERS_COMMSBACKOFF
|
||||
|
||||
typedef struct XP_Rect {
|
||||
|
|
|
@ -76,6 +76,7 @@ typedef struct ServerVolatiles {
|
|||
void* turnChangeData;
|
||||
GameOverListener gameOverListener;
|
||||
void* gameOverData;
|
||||
XP_U16 pendingRegistrations;
|
||||
XP_Bool showPrevMove;
|
||||
} ServerVolatiles;
|
||||
|
||||
|
@ -86,7 +87,6 @@ typedef struct ServerNonvolatiles {
|
|||
XW_State stateAfterShow;
|
||||
XP_S8 currentTurn; /* invalid when game is over */
|
||||
XP_S8 quitter; /* -1 unless somebody resigned */
|
||||
XP_U8 pendingRegistrations;
|
||||
XP_Bool showRobotScores;
|
||||
XP_Bool sortNewTiles;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
|
@ -206,21 +206,23 @@ logNewState( XW_State old, XW_State newst )
|
|||
****************************************************************************/
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
static void
|
||||
syncPlayers( ServerCtxt* server )
|
||||
figureMissing( ServerCtxt* server )
|
||||
{
|
||||
XP_U16 pendingRegistrations = 0;
|
||||
XP_U16 ii;
|
||||
CurGameInfo* gi = server->vol.gi;
|
||||
LocalPlayer* lp = gi->players;
|
||||
ServerPlayer* player = server->players;
|
||||
for ( ii = 0; ii < gi->nPlayers; ++ii, ++lp, ++player ) {
|
||||
if ( !lp->isLocal/* && !lp->name */ ) {
|
||||
++server->nv.pendingRegistrations;
|
||||
if ( !lp->isLocal && !lp->name ) {
|
||||
++pendingRegistrations;
|
||||
}
|
||||
player->deviceIndex = lp->isLocal? SERVER_DEVICE : UNKNOWN_DEVICE;
|
||||
}
|
||||
server->vol.pendingRegistrations = pendingRegistrations;
|
||||
}
|
||||
#else
|
||||
# define syncPlayers( server )
|
||||
# define figureMissing( server )
|
||||
#endif
|
||||
|
||||
static XP_Bool
|
||||
|
@ -243,7 +245,7 @@ initServer( ServerCtxt* server )
|
|||
SETSTATE( server, XWSTATE_BEGIN );
|
||||
}
|
||||
|
||||
syncPlayers( server );
|
||||
figureMissing( server );
|
||||
|
||||
server->nv.nDevices = 1; /* local device (0) is always there */
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
|
@ -302,7 +304,8 @@ getNV( XWStreamCtxt* stream, ServerNonvolatiles* nv, XP_U16 nPlayers )
|
|||
if ( STREAM_VERS_DICTNAME <= version ) {
|
||||
nv->quitter = (XP_S8)stream_getBits( stream, NPLAYERS_NBITS ) - 1;
|
||||
}
|
||||
nv->pendingRegistrations = (XP_U8)stream_getBits( stream, NPLAYERS_NBITS );
|
||||
/* FIX_NEXT_VERSION_CHANGE */
|
||||
/*nv->pendingRegistrations = (XP_U8)*/ stream_getBits( stream, NPLAYERS_NBITS );
|
||||
|
||||
for ( ii = 0; ii < nPlayers; ++ii ) {
|
||||
nv->addresses[ii].channelNo =
|
||||
|
@ -337,7 +340,8 @@ putNV( XWStreamCtxt* stream, const ServerNonvolatiles* nv, XP_U16 nPlayers )
|
|||
/* +1: make -1 (NOTURN) into a positive number */
|
||||
stream_putBits( stream, NPLAYERS_NBITS, nv->currentTurn+1 );
|
||||
stream_putBits( stream, NPLAYERS_NBITS, nv->quitter+1 );
|
||||
stream_putBits( stream, NPLAYERS_NBITS, nv->pendingRegistrations );
|
||||
/* FIX_NEXT_VERSION_CHANGE */
|
||||
stream_putBits( stream, NPLAYERS_NBITS, 0 /*nv->pendingRegistrations*/ );
|
||||
|
||||
for ( ii = 0; ii < nPlayers; ++ii ) {
|
||||
stream_putBits( stream, 16, nv->addresses[ii].channelNo );
|
||||
|
@ -416,9 +420,11 @@ server_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
|
|||
server->nv.prevWordsStream = readStreamIf( server, stream );
|
||||
}
|
||||
|
||||
figureMissing( server );
|
||||
|
||||
util_informMissing( util, server->vol.gi->serverRole == SERVER_ISSERVER,
|
||||
comms_getConType( comms ),
|
||||
server->nv.pendingRegistrations );
|
||||
server->vol.pendingRegistrations );
|
||||
return server;
|
||||
} /* server_makeFromStream */
|
||||
|
||||
|
@ -551,9 +557,10 @@ server_countTilesInPool( ServerCtxt* server )
|
|||
#define NAME_LEN_NBITS 6
|
||||
#define MAX_NAME_LEN ((1<<(NAME_LEN_NBITS-1))-1)
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
void
|
||||
XP_Bool
|
||||
server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_Bool result;
|
||||
LOG_FUNC();
|
||||
CurGameInfo* gi = server->vol.gi;
|
||||
XP_U16 nPlayers;
|
||||
|
@ -564,7 +571,8 @@ server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
|
||||
XP_ASSERT( gi->serverRole == SERVER_ISCLIENT );
|
||||
XP_ASSERT( stream != NULL );
|
||||
if ( server->nv.gameState == XWSTATE_NONE ) {
|
||||
result = server->nv.gameState == XWSTATE_NONE;
|
||||
if ( result ) {
|
||||
stream_open( stream );
|
||||
|
||||
writeProto( server, stream, XWPROTO_DEVICE_REGISTRATION );
|
||||
|
@ -598,12 +606,12 @@ server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
#ifdef STREAM_VERS_BIGBOARD
|
||||
stream_putU8( stream, CUR_STREAM_VERS );
|
||||
#endif
|
||||
|
||||
} else {
|
||||
XP_LOGF( "%s: wierd state %s; dropping message", __func__,
|
||||
getStateStr(server->nv.gameState) );
|
||||
}
|
||||
stream_destroy( stream );
|
||||
return result;
|
||||
} /* server_initClientConnection */
|
||||
#endif
|
||||
|
||||
|
@ -697,7 +705,7 @@ handleRegistrationMsg( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
playersInMsg = (XP_U16)stream_getBits( stream, NPLAYERS_NBITS );
|
||||
XP_ASSERT( playersInMsg > 0 );
|
||||
|
||||
if ( server->nv.pendingRegistrations < playersInMsg ) {
|
||||
if ( server->vol.pendingRegistrations < playersInMsg ) {
|
||||
util_userError( server->vol.util, ERR_REG_UNEXPECTED_USER );
|
||||
success = XP_FALSE;
|
||||
} else {
|
||||
|
@ -736,7 +744,7 @@ handleRegistrationMsg( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
}
|
||||
#endif
|
||||
|
||||
if ( server->nv.pendingRegistrations == 0 ) {
|
||||
if ( server->vol.pendingRegistrations == 0 ) {
|
||||
XP_ASSERT( ii == playersInMsg ); /* otherwise malformed */
|
||||
setStreamVersion( server );
|
||||
checkResizeBoard( server );
|
||||
|
@ -1029,7 +1037,7 @@ server_do( ServerCtxt* server )
|
|||
|
||||
switch( server->nv.gameState ) {
|
||||
case XWSTATE_BEGIN:
|
||||
if ( server->nv.pendingRegistrations == 0 ) { /* all players on
|
||||
if ( server->vol.pendingRegistrations == 0 ) { /* all players on
|
||||
device */
|
||||
assignTilesToAll( server );
|
||||
SETSTATE( server, XWSTATE_INTURN );
|
||||
|
@ -1124,7 +1132,7 @@ findFirstPending( ServerCtxt* server, ServerPlayer** playerP )
|
|||
LocalPlayer* lp;
|
||||
CurGameInfo* gi = server->vol.gi;
|
||||
XP_U16 nPlayers = gi->nPlayers;
|
||||
XP_U16 nPending = server->nv.pendingRegistrations;
|
||||
XP_U16 nPending = server->vol.pendingRegistrations;
|
||||
|
||||
XP_ASSERT( nPlayers > 0 );
|
||||
lp = gi->players + nPlayers;
|
||||
|
@ -1158,7 +1166,7 @@ registerRemotePlayer( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
|
||||
/* The player must already be there with a null name, or it's an error.
|
||||
Take the first empty slot. */
|
||||
XP_ASSERT( server->nv.pendingRegistrations > 0 );
|
||||
XP_ASSERT( server->vol.pendingRegistrations > 0 );
|
||||
|
||||
/* find the slot to use */
|
||||
lp = findFirstPending( server, &player );
|
||||
|
@ -1177,7 +1185,7 @@ registerRemotePlayer( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
channelNo = stream_getAddress( stream );
|
||||
deviceIndex = getIndexForDevice( server, channelNo );
|
||||
|
||||
--server->nv.pendingRegistrations;
|
||||
--server->vol.pendingRegistrations;
|
||||
|
||||
if ( deviceIndex == -1 ) {
|
||||
RemoteAddress* addr;
|
||||
|
@ -1348,7 +1356,7 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
sortTilesIf( server, ii );
|
||||
}
|
||||
|
||||
syncPlayers( server );
|
||||
figureMissing( server );
|
||||
|
||||
SETSTATE( server, XWSTATE_INTURN );
|
||||
|
||||
|
@ -2425,7 +2433,7 @@ server_getMissingPlayers( const ServerCtxt* server )
|
|||
}
|
||||
break;
|
||||
case SERVER_ISSERVER:
|
||||
if ( 0 < server->nv.pendingRegistrations ) {
|
||||
if ( 0 < server->vol.pendingRegistrations ) {
|
||||
XP_U16 nPlayers = server->vol.gi->nPlayers;
|
||||
const ServerPlayer* players = server->players;
|
||||
for ( ii = 0; ii < nPlayers; ++ii ) {
|
||||
|
@ -2548,6 +2556,7 @@ tileCountsOk( const ServerCtxt* server )
|
|||
static void
|
||||
setTurn( ServerCtxt* server, XP_S16 turn )
|
||||
{
|
||||
XP_ASSERT( -1 == turn || 0 == server->vol.pendingRegistrations );
|
||||
if ( server->nv.currentTurn != turn ) {
|
||||
server->nv.currentTurn = turn;
|
||||
server->nv.lastMoveTime = util_getCurSeconds( server->vol.util );
|
||||
|
|
|
@ -116,7 +116,7 @@ XP_Bool server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incoming );
|
|||
/* client-side messages. Client (platform code)owns the stream used to talk
|
||||
* to the server, and passes it in. */
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
void server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream );
|
||||
XP_Bool server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream );
|
||||
#endif
|
||||
|
||||
#ifdef XWFEATURE_CHAT
|
||||
|
|
Loading…
Add table
Reference in a new issue