From dfa0502a0664ad8fbe34c5b2f65c5d86d80740ed Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 26 Aug 2024 11:29:09 -0700 Subject: [PATCH] always generate gameID using the same function Android was using curSeconds(): bad! --- xwords4/android/jni/xwjni.c | 4 +--- xwords4/common/game.c | 12 ++++-------- xwords4/common/game.h | 2 ++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index 650bbdfef..56dea7fdf 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -470,9 +470,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi ) game_makeNewGame, which sets gameID. So check here if it's still unset and if necessary set it -- including back in the java world. */ if ( 0 == gi->gameID ) { - while ( 0 == gi->gameID ) { - gi->gameID = getCurSeconds( env ); - } + gi->gameID = game_makeGameID( 0 ); setInt( env, jgi, "gameID", gi->gameID ); } diff --git a/xwords4/common/game.c b/xwords4/common/game.c index 2d1b748c9..65113defb 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -79,11 +79,9 @@ checkServerRole( CurGameInfo* gi, XP_U16* nPlayersHere, } } /* checkServerRole */ -static XP_U32 -makeGameID( XW_UtilCtxt* XP_UNUSED_DBG(util) ) +XP_U32 +game_makeGameID( XP_U32 gameID ) { - XP_U32 gameID = 0; - assertUtilOK( util ); while ( 0 == gameID ) { /* High bit never set by XP_RANDOM() alone */ gameID = (XP_RANDOM() << 16) ^ XP_RANDOM(); @@ -178,9 +176,7 @@ game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi, checkServerRole( gi, &nPlayersHere, &nPlayersTotal ); assertUtilOK( util ); - if ( 0 == gi->gameID ) { - gi->gameID = makeGameID( util ); - } + gi->gameID = game_makeGameID( gi->gameID ); XW_DUtilCtxt* dutil = util_getDevUtilCtxt( util, xwe ); game->created = dutil_getCurSeconds( dutil, xwe ); game->util = util; @@ -247,7 +243,7 @@ game_makeRematch( const XWGame* oldGame, XWEnv xwe, XW_UtilCtxt* newUtil, RematchInfo* rip; if ( server_getRematchInfo( oldGame->server, newUtil, - makeGameID( newUtil ), nop, &rip ) ) { + game_makeGameID( 0 ), nop, &rip ) ) { CommsAddrRec* selfAddrP = NULL; CommsAddrRec selfAddr; if ( !!oldGame->comms ) { diff --git a/xwords4/common/game.h b/xwords4/common/game.h index cada4877a..ccade8569 100644 --- a/xwords4/common/game.h +++ b/xwords4/common/game.h @@ -77,6 +77,8 @@ typedef struct _XWGame { XP_U32 created; /* dutil_getCurSeconds() of creation */ } XWGame; +XP_U32 game_makeGameID(); + XP_Bool game_makeNewGame( MPFORMAL XWEnv xwe, XWGame* game, CurGameInfo* gi, const CommsAddrRec* selfAddr, const CommsAddrRec* hostAddr, XW_UtilCtxt* util, DrawCtx* draw, const CommonPrefs* cp,