From 5a28a7fc278fa7b63558147545c64508503bf4f0 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 21 Apr 2020 21:18:43 -0700 Subject: [PATCH] fix gtk games connecting to relay/each other I broke gtk back in February making curses changes --- xwords4/common/game.c | 42 ++++++++++++++++++++++++--------------- xwords4/common/gameinfo.h | 6 ++++-- xwords4/common/server.c | 5 +++-- xwords4/linux/gtkboard.c | 3 ++- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/xwords4/common/game.c b/xwords4/common/game.c index 03a38a11f..4d915681f 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -549,13 +549,22 @@ gi_setNPlayers( CurGameInfo* gi, XP_U16 nTotal, XP_U16 nHere ) } if ( nHere != curLocal ) { - /* This will happen when a device has more than on player. Not sure I + /* This will happen when a device has more than one player. Not sure I handle that correctly, but don't assert for now. */ XP_LOGFF( "nHere: %d; curLocal: %d; a problem?", nHere, curLocal ); - /* for ( XP_U16 ii = 0; ii < nTotal; ++ii ) { */ - /* gi->players[ii].isLocal = ii < nHere; */ - /* } */ + for ( XP_U16 ii = 0; ii < nTotal; ++ii ) { + if ( !gi->players[ii].isLocal ) { + gi->players[ii].isLocal = XP_TRUE; + XP_LOGFF( "making player #%d local when wasn't before", ii ); + ++curLocal; + XP_ASSERT( curLocal <= nHere ); + if ( curLocal == nHere ) { + break; + } + } + } } + LOGGI( gi, __func__ ); } XP_U16 @@ -762,20 +771,21 @@ player_timePenalty( CurGameInfo* gi, XP_U16 playerNum ) #ifdef DEBUG void -game_logGI( const CurGameInfo* gi, const char* msg ) +game_logGI( const CurGameInfo* gi, const char* msg, const char* func, int line ) { - XP_LOGFF( "msg: %s", msg ); - - XP_LOGF( " nPlayers: %d", gi->nPlayers ); - for ( XP_U16 ii = 0; ii < gi->nPlayers; ++ii ) { - const LocalPlayer* lp = &gi->players[ii]; - XP_LOGF( " player[%d]: local: %d; robotIQ: %d; name: %s", ii, - lp->isLocal, lp->robotIQ, lp->name ); + XP_LOGFF( "msg: %s from %s() line %d; addr: %p", msg, func, line, gi ); + if ( !!gi ) { + XP_LOGF( " nPlayers: %d", gi->nPlayers ); + for ( XP_U16 ii = 0; ii < gi->nPlayers; ++ii ) { + const LocalPlayer* lp = &gi->players[ii]; + XP_LOGF( " player[%d]: local: %d; robotIQ: %d; name: %s", ii, + lp->isLocal, lp->robotIQ, lp->name ); + } + XP_LOGF( " forceChannel: %d", gi->forceChannel ); + XP_LOGF( " serverRole: %d", gi->serverRole ); + XP_LOGF( " gameID: %d", gi->gameID ); + XP_LOGF( " dictName: %s", gi->dictName ); } - XP_LOGF( " forceChannel: %d", gi->forceChannel ); - XP_LOGF( " serverRole: %d", gi->serverRole ); - XP_LOGF( " gameID: %d", gi->gameID ); - XP_LOGF( " dictName: %s", gi->dictName ); } #endif diff --git a/xwords4/common/gameinfo.h b/xwords4/common/gameinfo.h index 0f169063e..3d5a3ce96 100644 --- a/xwords4/common/gameinfo.h +++ b/xwords4/common/gameinfo.h @@ -64,9 +64,11 @@ typedef struct CurGameInfo { } CurGameInfo; #ifdef DEBUG - void game_logGI( const CurGameInfo* gi, const char* msg ); +# define LOGGI( gip, msg ) game_logGI( (gip), (msg), __func__, __LINE__ ) + void game_logGI( const CurGameInfo* gi, const char* msg, + const char* func, int line ); #else -# define game_logGI(gi, msg) +# define LOGGI(gi, msg) #endif #ifdef CPLUS diff --git a/xwords4/common/server.c b/xwords4/common/server.c index d4963b6bb..de7961e1d 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -672,8 +672,9 @@ server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream ) nPlayers = gi->nPlayers; XP_ASSERT( nPlayers > 0 ); - stream_putBits( stream, NPLAYERS_NBITS, - gi_countLocalPlayers( gi, XP_FALSE) ); + XP_U16 localPlayers = gi_countLocalPlayers( gi, XP_FALSE); + XP_ASSERT( 0 < localPlayers ); + stream_putBits( stream, NPLAYERS_NBITS, localPlayers ); for ( lp = gi->players; nPlayers-- > 0; ++lp ) { XP_UCHAR* name; diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index 472e9694c..a35d6c825 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -583,7 +583,8 @@ createOrLoadObjects( GtkGameGlobals* globals ) TransportProcs procs; setTransportProcs( &procs, globals ); - if ( linuxOpenGame( cGlobals, &procs, NULL ) ) { + + if ( linuxOpenGame( cGlobals, &procs, &cGlobals->addr ) ) { if ( !params->fileName && !!params->dbName ) { XP_UCHAR buf[64];