From 71ea59e7fbebf6be3f4df8d9ce3a294380e9c42a Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 7 Aug 2013 21:09:48 -0700 Subject: [PATCH] separate whether app is using udp from whether it stores games in a sqlite3 db so that it can switch mid-game -- that being something that needs testing. --- xwords4/linux/cursesmain.c | 16 ++++++++++------ xwords4/linux/gtkboard.c | 7 ++++--- xwords4/linux/gtkmain.c | 28 +++++++++++++++------------- xwords4/linux/linuxmain.c | 2 +- xwords4/linux/relaycon.c | 1 + 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index c982eca15..ff49079b6 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -2023,10 +2023,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) g_globals.draw = (struct CursesDrawCtx*) cursesDrawCtxtMake( g_globals.boardWin ); - XWStreamCtxt* stream = NULL; - if ( !!params->dbName ) { - g_globals.cGlobals.pDb = openGamesDB( params->dbName ); - + if ( params->useUdp ) { RelayConnProcs procs = { .msgReceived = cursesGotBuf, .msgNoticeReceived = cursesNoticeRcvd, @@ -2041,14 +2038,21 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) DevIDType typ; const XP_UCHAR* devID = linux_getDevID( params, &typ ); relaycon_reg( params, devID, typ ); + } - GSList* games = listGames( g_globals.cGlobals.pDb ); + XWStreamCtxt* stream = NULL; + if ( !!params->dbName ) { + sqlite3* pDb = openGamesDB( params->dbName ); + /* Gross that both need to be set, but they do. */ + params->pDb = g_globals.cGlobals.pDb = pDb; + + GSList* games = listGames( pDb ); if ( !!games ) { stream = mem_stream_make( MEMPOOL params->vtMgr, &g_globals.cGlobals, CHANNEL_NONE, NULL ); sqlite3_int64 selRow = *(sqlite3_int64*)games->data; - if ( loadGame( stream, g_globals.cGlobals.pDb, selRow ) ) { + if ( loadGame( stream, pDb, selRow ) ) { g_globals.cGlobals.selRow = selRow; } else { stream_destroy( stream ); diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index dd386ecdc..257449cd8 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -400,11 +400,12 @@ relay_sendNoConn_gtk( const XP_U8* msg, XP_U16 len, const XP_UCHAR* relayID, { GtkGameGlobals* globals = (GtkGameGlobals*)closure; XP_Bool success = XP_FALSE; - if ( !!globals->cGlobals.pDb && !globals->draw ) { + LaunchParams* params = globals->cGlobals.params; + if ( params->useUdp && !globals->draw ) { XP_U16 seed = comms_getChannelSeed( globals->cGlobals.game.comms ); XP_U32 clientToken = makeClientToken( globals->cGlobals.selRow, seed ); - XP_S16 nSent = relaycon_sendnoconn( globals->cGlobals.params, msg, len, - relayID, clientToken ); + XP_S16 nSent = relaycon_sendnoconn( params, msg, len, relayID, + clientToken ); success = nSent == len; } return success; diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index a033b501d..2c8fb6bc1 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -586,21 +586,23 @@ gtkmain( LaunchParams* params ) apg.params = params; params->pDb = openGamesDB( params->dbName ); - RelayConnProcs procs = { - .msgReceived = gtkGotBuf, - .msgNoticeReceived = gtkNoticeRcvd, - .devIDChanged = gtkDevIDChanged, - .msgErrorMsg = gtkErrorMsgRcvd, - .socketChanged = gtkSocketChanged, - }; + if ( params->useUdp ) { + RelayConnProcs procs = { + .msgReceived = gtkGotBuf, + .msgNoticeReceived = gtkNoticeRcvd, + .devIDChanged = gtkDevIDChanged, + .msgErrorMsg = gtkErrorMsgRcvd, + .socketChanged = gtkSocketChanged, + }; - relaycon_init( params, &procs, &apg, - params->connInfo.relay.relayName, - params->connInfo.relay.defaultSendPort ); + relaycon_init( params, &procs, &apg, + params->connInfo.relay.relayName, + params->connInfo.relay.defaultSendPort ); - DevIDType typ; - const XP_UCHAR* devID = linux_getDevID( params, &typ ); - relaycon_reg( params, devID, typ ); + DevIDType typ; + const XP_UCHAR* devID = linux_getDevID( params, &typ ); + relaycon_reg( params, devID, typ ); + } apg.window = makeGamesWindow( &apg ); gtk_main(); diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 55011a880..ff8937d27 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -1028,7 +1028,7 @@ linux_tcp_send( CommonGlobals* cGlobals, const XP_U8* buf, XP_U16 buflen, const CommsAddrRec* addrRec ) { XP_S16 result = 0; - if ( !!cGlobals->pDb ) { + if ( cGlobals->params->useUdp ) { XP_ASSERT( -1 != cGlobals->selRow ); XP_U16 seed = comms_getChannelSeed( cGlobals->game.comms ); XP_U32 clientToken = makeClientToken( cGlobals->selRow, seed ); diff --git a/xwords4/linux/relaycon.c b/xwords4/linux/relaycon.c index 036bbe60a..ebceddb6c 100644 --- a/xwords4/linux/relaycon.c +++ b/xwords4/linux/relaycon.c @@ -263,6 +263,7 @@ relaycon_cleanup( LaunchParams* params ) static RelayConStorage* getStorage( LaunchParams* params ) { + XP_ASSERT( params->useUdp ); RelayConStorage* storage = (RelayConStorage*)params->relayConStorage; if ( NULL == storage ) { storage = XP_CALLOC( params->mpool, sizeof(*storage) );