mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
add ability to open game in sqlite3 DB from an Android phone. It's
read-only now: changes are not saved. But it works!
This commit is contained in:
parent
0c030360bf
commit
08e5fbdcc2
6 changed files with 64 additions and 7 deletions
|
@ -189,7 +189,7 @@ OBJ = \
|
||||||
$(PLATFORM)/linuxutl.o \
|
$(PLATFORM)/linuxutl.o \
|
||||||
$(CURSES_OBJS) $(GTK_OBJS) $(MAIN_OBJS)
|
$(CURSES_OBJS) $(GTK_OBJS) $(MAIN_OBJS)
|
||||||
|
|
||||||
LIBS = -lm -luuid $(GPROFFLAG)
|
LIBS = -lm -luuid -lsqlite3 $(GPROFFLAG)
|
||||||
# Turn this off for now. I apparently have a memory problem, but it
|
# Turn this off for now. I apparently have a memory problem, but it
|
||||||
# doesn't make the app unusable for testing while crash on boot does.
|
# doesn't make the app unusable for testing while crash on boot does.
|
||||||
# LIBS += -lmcheck
|
# LIBS += -lmcheck
|
||||||
|
|
|
@ -1770,18 +1770,22 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
||||||
} else if ( !!params->nbs && !!params->fileName ) {
|
} else if ( !!params->nbs && !!params->fileName ) {
|
||||||
do_nbs_then_close( &g_globals.cGlobals, &procs );
|
do_nbs_then_close( &g_globals.cGlobals, &procs );
|
||||||
} else {
|
} else {
|
||||||
|
XP_Bool opened = XP_FALSE;
|
||||||
initCurses( &g_globals );
|
initCurses( &g_globals );
|
||||||
getmaxyx( g_globals.boardWin, height, width );
|
getmaxyx( g_globals.boardWin, height, width );
|
||||||
|
|
||||||
g_globals.draw = (struct CursesDrawCtx*)
|
g_globals.draw = (struct CursesDrawCtx*)
|
||||||
cursesDrawCtxtMake( g_globals.boardWin );
|
cursesDrawCtxtMake( g_globals.boardWin );
|
||||||
|
|
||||||
|
XWStreamCtxt* stream = NULL;
|
||||||
if ( !!params->fileName && file_exists( params->fileName ) ) {
|
if ( !!params->fileName && file_exists( params->fileName ) ) {
|
||||||
XWStreamCtxt* stream;
|
|
||||||
stream = streamFromFile( &g_globals.cGlobals, params->fileName,
|
stream = streamFromFile( &g_globals.cGlobals, params->fileName,
|
||||||
&g_globals );
|
&g_globals );
|
||||||
|
} else if ( !!params->dbFileName && file_exists( params->dbFileName ) ) {
|
||||||
|
stream = streamFromDB( &g_globals.cGlobals, &g_globals );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !!stream ) {
|
||||||
(void)game_makeFromStream( MEMPOOL stream, &g_globals.cGlobals.game,
|
(void)game_makeFromStream( MEMPOOL stream, &g_globals.cGlobals.game,
|
||||||
¶ms->gi, params->dict, ¶ms->dicts,
|
¶ms->gi, params->dict, ¶ms->dicts,
|
||||||
params->util,
|
params->util,
|
||||||
|
@ -1789,11 +1793,12 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
||||||
&g_globals.cGlobals.cp, &procs );
|
&g_globals.cGlobals.cp, &procs );
|
||||||
|
|
||||||
stream_destroy( stream );
|
stream_destroy( stream );
|
||||||
|
|
||||||
if ( !isServer && params->gi.serverRole == SERVER_ISSERVER ) {
|
if ( !isServer && params->gi.serverRole == SERVER_ISSERVER ) {
|
||||||
isServer = XP_TRUE;
|
isServer = XP_TRUE;
|
||||||
}
|
}
|
||||||
} else {
|
opened = XP_TRUE;
|
||||||
|
}
|
||||||
|
if ( !opened ) {
|
||||||
game_makeNewGame( MEMPOOL &g_globals.cGlobals.game, ¶ms->gi,
|
game_makeNewGame( MEMPOOL &g_globals.cGlobals.game, ¶ms->gi,
|
||||||
params->util, (DrawCtx*)g_globals.draw,
|
params->util, (DrawCtx*)g_globals.draw,
|
||||||
&g_globals.cGlobals.cp, &procs, params->gameSeed );
|
&g_globals.cGlobals.cp, &procs, params->gameSeed );
|
||||||
|
|
|
@ -417,9 +417,12 @@ createOrLoadObjects( GtkAppGlobals* globals )
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( !!params->fileName && file_exists( params->fileName ) ) {
|
if ( !!params->fileName && file_exists( params->fileName ) ) {
|
||||||
|
|
||||||
stream = streamFromFile( &globals->cGlobals, params->fileName, globals );
|
stream = streamFromFile( &globals->cGlobals, params->fileName, globals );
|
||||||
|
} else if ( !!params->dbFileName && file_exists( params->dbFileName ) ) {
|
||||||
|
stream = streamFromDB( &globals->cGlobals, globals );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !!stream ) {
|
||||||
opened = game_makeFromStream( MEMPOOL stream, &globals->cGlobals.game,
|
opened = game_makeFromStream( MEMPOOL stream, &globals->cGlobals.game,
|
||||||
&globals->cGlobals.params->gi,
|
&globals->cGlobals.params->gi,
|
||||||
params->dict, ¶ms->dicts, params->util,
|
params->dict, ¶ms->dicts, params->util,
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <linux/un.h>
|
#include <linux/un.h>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#ifdef XWFEATURE_BLUETOOTH
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
# include <bluetooth/bluetooth.h>
|
# include <bluetooth/bluetooth.h>
|
||||||
|
@ -104,6 +105,42 @@ streamFromFile( CommonGlobals* cGlobals, char* name, void* closure )
|
||||||
return stream;
|
return stream;
|
||||||
} /* streamFromFile */
|
} /* streamFromFile */
|
||||||
|
|
||||||
|
XWStreamCtxt*
|
||||||
|
streamFromDB( CommonGlobals* cGlobals, void* closure )
|
||||||
|
{
|
||||||
|
XWStreamCtxt* stream = NULL;
|
||||||
|
const LaunchParams* params = cGlobals->params;
|
||||||
|
const char* name = params->dbFileName;
|
||||||
|
XP_U32 rowid = params->dbFileID;
|
||||||
|
sqlite3* ppDb;
|
||||||
|
int res = sqlite3_open( name, &ppDb );
|
||||||
|
if ( SQLITE_OK == res ) {
|
||||||
|
sqlite3_blob* ppBlob;
|
||||||
|
res = sqlite3_blob_open( ppDb, "main", "summaries", "SNAPSHOT", rowid,
|
||||||
|
0 /*flags*/, &ppBlob );
|
||||||
|
if ( SQLITE_OK == res ) {
|
||||||
|
int size = sqlite3_blob_bytes( ppBlob );
|
||||||
|
XP_U8 buf[size];
|
||||||
|
res = sqlite3_blob_read( ppBlob, buf, size, 0 );
|
||||||
|
if ( SQLITE_OK == res ) {
|
||||||
|
stream = mem_stream_make( MPPARM(params->util->mpool) params->vtMgr,
|
||||||
|
closure, CHANNEL_NONE, NULL );
|
||||||
|
stream_putBytes( stream, buf, size );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlite3_blob_close( ppBlob );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( SQLITE_OK != res ) {
|
||||||
|
XP_LOGF( "%s: error from sqlite: %s", __func__,
|
||||||
|
sqlite3_errmsg(ppDb) );
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)sqlite3_close( ppDb );
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
writeToFile( XWStreamCtxt* stream, void* closure )
|
writeToFile( XWStreamCtxt* stream, void* closure )
|
||||||
{
|
{
|
||||||
|
@ -414,6 +451,8 @@ typedef enum {
|
||||||
,CMD_SEED
|
,CMD_SEED
|
||||||
,CMD_GAMESEED
|
,CMD_GAMESEED
|
||||||
,CMD_GAMEFILE
|
,CMD_GAMEFILE
|
||||||
|
,CMD_GAMEDB_FILE
|
||||||
|
,CMD_GAMEDB_ID
|
||||||
,CMD_NOMMAP
|
,CMD_NOMMAP
|
||||||
,CMD_PRINTHISORY
|
,CMD_PRINTHISORY
|
||||||
,CMD_SKIPWARNINGS
|
,CMD_SKIPWARNINGS
|
||||||
|
@ -501,6 +540,8 @@ static CmdInfoRec CmdInfoRecs[] = {
|
||||||
,{ CMD_SEED, true, "seed", "random seed" }
|
,{ CMD_SEED, true, "seed", "random seed" }
|
||||||
,{ CMD_GAMESEED, true, "game-seed", "game seed (for relay play)" }
|
,{ CMD_GAMESEED, true, "game-seed", "game seed (for relay play)" }
|
||||||
,{ CMD_GAMEFILE, true, "file", "file to save to/read from" }
|
,{ CMD_GAMEFILE, true, "file", "file to save to/read from" }
|
||||||
|
,{ CMD_GAMEDB_FILE, true, "game-db-file", "sqlite3 file, android format, holding game" }
|
||||||
|
,{ CMD_GAMEDB_ID, true, "game-db-id", "id of row of game we want (defaults to first)" }
|
||||||
,{ CMD_NOMMAP, false, "no-mmap", "copy dicts to memory rather than mmap them" }
|
,{ CMD_NOMMAP, false, "no-mmap", "copy dicts to memory rather than mmap them" }
|
||||||
,{ CMD_PRINTHISORY, false, "print-history", "print history on game over" }
|
,{ CMD_PRINTHISORY, false, "print-history", "print history on game over" }
|
||||||
,{ CMD_SKIPWARNINGS, false, "skip-warnings", "no modals on phonies" }
|
,{ CMD_SKIPWARNINGS, false, "skip-warnings", "no modals on phonies" }
|
||||||
|
@ -1452,6 +1493,11 @@ main( int argc, char** argv )
|
||||||
case CMD_GAMEFILE:
|
case CMD_GAMEFILE:
|
||||||
mainParams.fileName = optarg;
|
mainParams.fileName = optarg;
|
||||||
break;
|
break;
|
||||||
|
case CMD_GAMEDB_FILE:
|
||||||
|
mainParams.dbFileName = optarg;
|
||||||
|
case CMD_GAMEDB_ID:
|
||||||
|
mainParams.dbFileID = atoi(optarg);
|
||||||
|
break;
|
||||||
case CMD_NOMMAP:
|
case CMD_NOMMAP:
|
||||||
mainParams.useMmap = false;
|
mainParams.useMmap = false;
|
||||||
break;
|
break;
|
||||||
|
@ -1675,7 +1721,7 @@ main( int argc, char** argv )
|
||||||
/* sanity checks */
|
/* sanity checks */
|
||||||
totalPlayerCount = mainParams.nLocalPlayers
|
totalPlayerCount = mainParams.nLocalPlayers
|
||||||
+ mainParams.info.serverInfo.nRemotePlayers;
|
+ mainParams.info.serverInfo.nRemotePlayers;
|
||||||
if ( !mainParams.fileName ) {
|
if ( !mainParams.fileName && !mainParams.dbFileName ) {
|
||||||
if ( (totalPlayerCount < 1) ||
|
if ( (totalPlayerCount < 1) ||
|
||||||
(totalPlayerCount > MAX_NUM_PLAYERS) ) {
|
(totalPlayerCount > MAX_NUM_PLAYERS) ) {
|
||||||
mainParams.needsNewGame = XP_TRUE;
|
mainParams.needsNewGame = XP_TRUE;
|
||||||
|
|
|
@ -64,6 +64,7 @@ void catFinalScores( const CommonGlobals* cGlobals );
|
||||||
XP_Bool file_exists( const char* fileName );
|
XP_Bool file_exists( const char* fileName );
|
||||||
XWStreamCtxt* streamFromFile( CommonGlobals* cGlobals, char* name,
|
XWStreamCtxt* streamFromFile( CommonGlobals* cGlobals, char* name,
|
||||||
void* closure );
|
void* closure );
|
||||||
|
XWStreamCtxt* streamFromDB( CommonGlobals* cGlobals, void* closure );
|
||||||
void writeToFile( XWStreamCtxt* stream, void* closure );
|
void writeToFile( XWStreamCtxt* stream, void* closure );
|
||||||
|
|
||||||
int blocking_read( int fd, unsigned char* buf, int len );
|
int blocking_read( int fd, unsigned char* buf, int len );
|
||||||
|
|
|
@ -49,6 +49,8 @@ typedef struct LaunchParams {
|
||||||
CurGameInfo gi;
|
CurGameInfo gi;
|
||||||
PlayerDicts dicts;
|
PlayerDicts dicts;
|
||||||
char* fileName;
|
char* fileName;
|
||||||
|
char* dbFileName;
|
||||||
|
XP_U32 dbFileID;
|
||||||
char* pipe;
|
char* pipe;
|
||||||
char* nbs;
|
char* nbs;
|
||||||
char* bonusFile;
|
char* bonusFile;
|
||||||
|
|
Loading…
Add table
Reference in a new issue