don't include dict tiles/values in initial server msg

There's code on all platforms to force user to have dict prior to
opening a game or responding to an invitation. "Empty" dict play hasn't
made sense in a long time.
This commit is contained in:
Eric House 2021-03-12 10:37:53 -08:00
parent ca88d9c0bf
commit f9e1deabfc
5 changed files with 34 additions and 44 deletions

View file

@ -231,9 +231,9 @@ board_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, ModelCtxt* model
board->isFlipped = (XP_Bool)stream_getBits( stream, 1 );
board->gameOver = (XP_Bool)stream_getBits( stream, 1 );
board->showColors = (XP_Bool)stream_getBits( stream, 1 );
// board->showCellValues = (XP_Bool)
// FIX_NEXT_VERSION_CHANGE: remove this conditionally
(void)stream_getBits( stream, 1 ); /* REMOVE ME */
if ( version < STREAM_VERS_NOEMPTYDICT ) {
(void)stream_getBits( stream, 1 );
}
if ( version >= STREAM_VERS_KEYNAV ) {
board->focussed = (BoardObjectType)stream_getBits( stream, 2 );
@ -332,8 +332,6 @@ board_writeToStream( const BoardCtxt* board, XWStreamCtxt* stream )
stream_putBits( stream, 1, board->isFlipped );
stream_putBits( stream, 1, board->gameOver );
stream_putBits( stream, 1, board->showColors );
// FIX_NEXT_VERSION_CHANGE: remove this
stream_putBits( stream, 1, 0 ); // board->showCellValues );
stream_putBits( stream, 2, board->focussed );
#ifdef KEYBOARD_NAV
stream_putBits( stream, 1, board->focusHasDived );

View file

@ -47,6 +47,7 @@
#endif
#define MAX_COLS MAX_ROWS
#define STREAM_VERS_NOEMPTYDICT 0x1D
#define STREAM_VERS_GICREATED 0x1C /* game struct gets created timestamp */
#define STREAM_VERS_DUPLICATE 0x1B
#define STREAM_VERS_DISABLEDS 0x1A
@ -90,7 +91,7 @@
#define STREAM_VERS_405 0x01
/* search for FIX_NEXT_VERSION_CHANGE next time this is changed */
#define CUR_STREAM_VERS STREAM_VERS_GICREATED
#define CUR_STREAM_VERS STREAM_VERS_NOEMPTYDICT
typedef struct XP_Rect {
XP_S16 left;

View file

@ -72,6 +72,7 @@ p_dict_unref( const DictionaryCtxt* dict, XWEnv xwe
if ( !!dict ) {
DictionaryCtxt* _dict = (DictionaryCtxt*)dict;
pthread_mutex_lock( &_dict->mutex );
XP_ASSERT( 0 != _dict->refCount );
--_dict->refCount;
XP_ASSERT( 0 <= _dict->refCount );
#ifdef DEBUG_REF
@ -767,7 +768,6 @@ common_destructor( DictionaryCtxt* dict, XWEnv XP_UNUSED(xwe) )
XP_FREE( dict->mpool, dict );
} /* common_destructor */
#ifndef XWFEATURE_STANDALONE_ONLY
void
dict_loadFromStream( DictionaryCtxt* dict, XWEnv xwe, XWStreamCtxt* stream )
{
@ -828,7 +828,16 @@ dict_loadFromStream( DictionaryCtxt* dict, XWEnv xwe, XWStreamCtxt* stream )
}
setBlankTile( dict );
} /* dict_loadFromStream */
#endif
void
dict_skipFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream )
{
DictionaryCtxt* dict = XP_CALLOC( mpool, sizeof(*dict)); /* leaked */
MPASSIGN( dict->mpool, mpool );
dict_ref( dict, xwe ); /* so unref works :-) */
dict_loadFromStream( dict, xwe, stream );
dict_unref( dict, xwe );
}
#ifdef TEXT_MODEL
/* Return the strlen of the longest face, e.g. 1 for English and Italian;

View file

@ -124,7 +124,6 @@ model_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
ModelCtxt* model;
XP_U16 nCols;
XP_U16 ii;
XP_Bool hasDict;
XP_U16 nPlayers;
XP_U16 version = stream_getVersion( stream );
@ -141,16 +140,8 @@ model_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
}
XP_ASSERT( MAX_COLS >= nCols );
hasDict = (version >= STREAM_VERS_MODEL_NO_DICT)
? XP_FALSE : stream_getBits( stream, 1 );
nPlayers = (XP_U16)stream_getBits( stream, NPLAYERS_NBITS );
if ( hasDict ) {
DictionaryCtxt* savedDict = util_makeEmptyDict( util, xwe );
dict_loadFromStream( savedDict, xwe, stream );
dict_unref( savedDict, xwe );
}
model = model_make( MPPARM(mpool) xwe, dict, dicts, util, nCols );
model->nPlayers = nPlayers;

View file

@ -1854,21 +1854,6 @@ registerRemotePlayer( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
}
return deviceIndex;
} /* registerRemotePlayer */
static void
clearLocalRobots( ServerCtxt* server )
{
XP_U16 ii;
CurGameInfo* gi = server->vol.gi;
XP_U16 nPlayers = gi->nPlayers;
for ( ii = 0; ii < nPlayers; ++ii ) {
LocalPlayer* player = &gi->players[ii];
if ( LP_IS_LOCAL( player ) ) {
player->robotIQ = 0;
}
}
} /* clearLocalRobots */
#endif
static void
@ -1924,8 +1909,16 @@ client_readInitialMessage( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
XP_U16 nCols = localGI.boardSize;
DictionaryCtxt* newDict = util_makeEmptyDict( server->vol.util, xwe );
dict_loadFromStream( newDict, xwe, stream );
XP_LOGFF( "streamVersion: %d; STREAM_VERS_NOEMPTYDICT: %d",
streamVersion, STREAM_VERS_NOEMPTYDICT );
if ( streamVersion < STREAM_VERS_NOEMPTYDICT ) {
XP_LOGFF( "loading and dropping empty dict" );
DictionaryCtxt* empty = util_makeEmptyDict( server->vol.util, xwe );
dict_loadFromStream( empty, xwe, stream );
dict_unref( empty, xwe );
} else {
XP_LOGFF( "NO empty dict bytes to skip" );
}
#ifdef STREAM_VERS_BIGBOARD
if ( STREAM_VERS_DICTNAME <= streamVersion ) {
@ -1953,11 +1946,9 @@ client_readInitialMessage( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
const DictionaryCtxt* curDict = model_getDictionary( model );
XP_ASSERT( !!newDict );
if ( curDict == NULL ) {
model_setDictionary( model, xwe, newDict );
} else if ( dict_tilesAreSame( newDict, curDict ) ) {
XP_ASSERT(0);
} else {
/* keep the dict the local user installed */
#ifdef STREAM_VERS_BIGBOARD
if ( '\0' != rmtDictName[0] ) {
@ -1968,12 +1959,7 @@ client_readInitialMessage( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
rmtDictSum, localGI.phoniesAction );
}
#endif
} else {
model_setDictionary( model, xwe, newDict );
util_userError( server->vol.util, xwe, ERR_SERVER_DICT_WINS );
clearLocalRobots( server );
}
dict_unref( newDict, xwe ); /* new owner will have ref'd */
XP_ASSERT( !server->pool );
makePoolOnce( server );
@ -2088,7 +2074,12 @@ sendInitialMessage( ServerCtxt* server, XWEnv xwe )
gi_writeToStream( stream, &localGI );
const DictionaryCtxt* dict = model_getDictionary( model );
if ( streamVersion < STREAM_VERS_NOEMPTYDICT ) {
XP_LOGFF( "writing dict to stream" );
dict_writeToStream( dict, stream );
} else {
XP_LOGFF( "SKIPPING write of dict to stream" );
}
#ifdef STREAM_VERS_BIGBOARD
if ( STREAM_VERS_DICTNAME <= streamVersion ) {
stringToStream( stream, dict_getShortName(dict) );