From 6b29ee92e67eacccb4fe9e88f38b70f7bda9ce9f Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 9 Sep 2022 11:23:30 -0700 Subject: [PATCH] tweaks to game_makeRematch --- xwords4/common/comms.c | 4 ++++ xwords4/common/game.c | 29 +++++++++++++++++------------ xwords4/linux/linuxmain.c | 13 +++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index a3dd5e235..a4c82a13a 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -2817,6 +2817,10 @@ comms_checkIncomingStream( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream, XP_MEMSET( state, 0, sizeof(*state) ); #ifdef DEBUG state->comms = comms; + if ( comms->processingMsg ) { + XP_LOGFF( "processingMsg SET, so dropping message" ); + return XP_FALSE; + } XP_ASSERT( !comms->processingMsg ); comms->processingMsg = XP_TRUE; CommsConnType addrType = addr_getType( retAddr ); diff --git a/xwords4/common/game.c b/xwords4/common/game.c index f42e71111..e16634629 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -238,29 +238,34 @@ game_makeRematch( const XWGame* oldGame, XWEnv xwe, XW_UtilCtxt* util, CurGameInfo newGI = {0}; gi_copy( MPPARM(util->mpool) &newGI, gi ); newGI.gameID = 0; /* clear so will get generated */ - newGI.serverRole = SERVER_ISSERVER; + if ( SERVER_ISCLIENT == newGI.serverRole ) { + newGI.serverRole = SERVER_ISSERVER; /* we'll be inviting */ + } XWGame newGame; CommsAddrRec* selfAddrP = NULL; - /* CommsAddrRec* hostAddrP = NULL; */ CommsAddrRec selfAddr; if ( !!oldGame->comms ) { comms_getSelfAddr( oldGame->comms, &selfAddr ); selfAddrP = &selfAddr; - /* if ( SERVER_ISCLIENT == gi->serverRole ) { */ - /* comms_getHostAddr( oldGame->comms, &hostAddr ); */ - /* hostAddrP = &hostAddr; */ - /* } */ } - if ( game_makeNewGame( MPPARM(util->mpool) xwe, &newGame, &newGI, - selfAddrP, NULL, util, + CommsAddrRec hostAddr; + XP_Bool haveRemote = !oldGame->comms + || comms_getHostAddr( oldGame->comms, &hostAddr ); + if ( !haveRemote ) { + XP_U16 nRecs = 1; + comms_getAddrs( oldGame->comms, xwe, &hostAddr, &nRecs ); + haveRemote = 0 < nRecs; + } + XP_ASSERT( haveRemote ); + + if ( haveRemote && + game_makeNewGame( MPPARM(util->mpool) xwe, &newGame, &newGI, + selfAddrP, (CommsAddrRec*)NULL, util, (DrawCtx*)NULL, cp, (TransportProcs*)NULL ) ) { if ( !!newGame.comms ) { - CommsAddrRec hostAddr; - comms_getHostAddr( oldGame->comms, &hostAddr ); - - NetLaunchInfo nli = {0}; + NetLaunchInfo nli; nli_init( &nli, &newGI, selfAddrP, 1, 1 ); LOGNLI( &nli ); comms_invite( newGame.comms, xwe, &nli, &hostAddr ); diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index ccf1e54a6..3619dc20c 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -147,6 +147,17 @@ ensureLocalPlayerNames( LaunchParams* XP_UNUSED_DBG(params), CurGameInfo* gi ) } } +static gint +send_msgs_idle( gpointer data ) +{ + CommonGlobals* cGlobals = (CommonGlobals*)data; + CommsCtxt* comms = cGlobals->game.comms; + if ( !!comms ) { + comms_resendAll( comms, NULL_XWE, COMMS_CONN_NONE, XP_FALSE ); + } + return FALSE; +} + bool linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs ) { @@ -230,6 +241,8 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs ) #endif server_do( cGlobals->game.server, NULL_XWE ); linuxSaveGame( cGlobals ); /* again, to include address etc. */ + + (void)g_idle_add( send_msgs_idle, cGlobals ); } LOG_RETURNF( "%s", boolToStr(opened) ); return opened;