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.
This commit is contained in:
Eric House 2013-08-07 21:09:48 -07:00
parent bac947d780
commit 71ea59e7fb
5 changed files with 31 additions and 23 deletions

View file

@ -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 );

View file

@ -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;

View file

@ -586,6 +586,7 @@ gtkmain( LaunchParams* params )
apg.params = params;
params->pDb = openGamesDB( params->dbName );
if ( params->useUdp ) {
RelayConnProcs procs = {
.msgReceived = gtkGotBuf,
.msgNoticeReceived = gtkNoticeRcvd,
@ -601,6 +602,7 @@ gtkmain( LaunchParams* params )
DevIDType typ;
const XP_UCHAR* devID = linux_getDevID( params, &typ );
relaycon_reg( params, devID, typ );
}
apg.window = makeGamesWindow( &apg );
gtk_main();

View file

@ -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 );

View file

@ -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) );