snapshot -- connects to relay but doesn't play yet.

This commit is contained in:
Eric House 2013-01-07 08:00:47 -08:00
parent 469e656464
commit 565b742971
9 changed files with 70 additions and 38 deletions

View file

@ -249,7 +249,7 @@ typedef struct _PlayerDicts {
# define RELAY_ROOM_DEFAULT "Room 1"
#endif
#ifndef RELAY_PORT_DEFAULT
# define RELAY_PORT_DEFAULT 10999
# define RELAY_PORT_DEFAULT 10997
#endif
#ifdef MEM_DEBUG

View file

@ -101,6 +101,7 @@ DEFINES += -DXWFEATURE_WALKDICT
DEFINES += -DXWFEATURE_WALKDICT_FILTER
DEFINES += -DXWFEATURE_DICTSANITY
DEFINES += -DHASH_STREAM
DEFINES += -DRELAY_NAME_DEFAULT="\"localhost\""
#DEFINES += -DXWFEATURE_SCOREONEPASS
### Enable zero or one of these two ###
#DEFINES += -DXWFEATURE_TRAYUNDO_ALL

View file

@ -21,13 +21,11 @@
#include "gamesdb.h"
#include "main.h"
#define DB_NAME "games.db"
sqlite3*
openGamesDB( void )
openGamesDB( const char* dbName )
{
sqlite3* pDb = NULL;
int result = sqlite3_open( DB_NAME, &pDb );
int result = sqlite3_open( dbName, &pDb );
XP_ASSERT( SQLITE_OK == result );
const char* createStr =
@ -62,7 +60,8 @@ writeToDB( XWStreamCtxt* stream, void* closure )
char* query;
sqlite3_stmt* stmt = NULL;
if ( -1 == selRow ) { /* new row; need to insert blob first */
XP_Bool newGame = -1 == selRow;
if ( newGame ) { /* new row; need to insert blob first */
query = "INSERT INTO games (game) VALUES (?)";
} else {
const char* fmt = "UPDATE games SET game=? where rowid=%lld";
@ -77,7 +76,7 @@ writeToDB( XWStreamCtxt* stream, void* closure )
result = sqlite3_step( stmt );
XP_ASSERT( SQLITE_DONE == result );
if ( -1 == selRow ) { /* new row; need to insert blob first */
if ( newGame ) { /* new row; need to insert blob first */
selRow = sqlite3_last_insert_rowid( pDb );
XP_LOGF( "%s: new rowid: %lld", __func__, selRow );
cGlobals->selRow = selRow;
@ -95,6 +94,10 @@ writeToDB( XWStreamCtxt* stream, void* closure )
if ( !!stmt ) {
sqlite3_finalize( stmt );
}
if ( newGame ) {
(*cGlobals->firstSave)( cGlobals->firstSaveClosure );
}
}
GSList*

View file

@ -27,7 +27,7 @@
#include "main.h"
#include "comtypes.h"
sqlite3* openGamesDB( void );
sqlite3* openGamesDB( const char* dbName );
void closeGamesDB( sqlite3* dbp );
void writeToDB( XWStreamCtxt* stream, void* closure );

View file

@ -456,35 +456,34 @@ createOrLoadObjects( GtkAppGlobals* globals )
}
if ( !opened ) {
CommsAddrRec addr;
CommsAddrRec addr = cGlobals->addr;
XP_MEMSET( &addr, 0, sizeof(addr) );
addr.conType = params->conType;
/* XP_MEMSET( &addr, 0, sizeof(addr) ); */
/* addr.conType = cGlobals->addr.conType; */
#ifdef XWFEATURE_RELAY
if ( addr.conType == COMMS_CONN_RELAY ) {
XP_ASSERT( !!params->connInfo.relay.relayName );
globals->cGlobals.defaultServerName
= params->connInfo.relay.relayName;
}
/* if ( addr.conType == COMMS_CONN_RELAY ) { */
/* XP_ASSERT( !!params->connInfo.relay.relayName ); */
/* globals->cGlobals.defaultServerName */
/* = params->connInfo.relay.relayName; */
/* } */
#endif
CommonGlobals* cGlobals = &globals->cGlobals;
game_makeNewGame( MEMPOOL &cGlobals->game, &cGlobals->gi,
cGlobals->util, (DrawCtx*)globals->draw,
&cGlobals->cp, &procs, params->gameSeed );
addr.conType = params->conType;
// addr.conType = params->conType;
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( addr.conType == COMMS_CONN_RELAY ) {
addr.u.ip_relay.ipAddr = 0;
addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort;
addr.u.ip_relay.seeksPublicRoom = params->connInfo.relay.seeksPublicRoom;
addr.u.ip_relay.advertiseRoom = params->connInfo.relay.advertiseRoom;
XP_STRNCPY( addr.u.ip_relay.hostName, params->connInfo.relay.relayName,
sizeof(addr.u.ip_relay.hostName) - 1 );
XP_STRNCPY( addr.u.ip_relay.invite, params->connInfo.relay.invite,
sizeof(addr.u.ip_relay.invite) - 1 );
/* addr.u.ip_relay.ipAddr = 0; */
/* addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort; */
/* addr.u.ip_relay.seeksPublicRoom = params->connInfo.relay.seeksPublicRoom; */
/* addr.u.ip_relay.advertiseRoom = params->connInfo.relay.advertiseRoom; */
/* XP_STRNCPY( addr.u.ip_relay.hostName, params->connInfo.relay.relayName, */
/* sizeof(addr.u.ip_relay.hostName) - 1 ); */
/* XP_STRNCPY( addr.u.ip_relay.invite, params->connInfo.relay.invite, */
/* sizeof(addr.u.ip_relay.invite) - 1 ); */
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( addr.conType == COMMS_CONN_BT ) {
@ -2385,6 +2384,8 @@ initGlobals( GtkAppGlobals* globals, LaunchParams* params )
globals->cGlobals.socketChanged = gtk_socket_changed;
globals->cGlobals.socketChangedClosure = globals;
globals->cGlobals.firstSave = newGameSaved;
globals->cGlobals.firstSaveClosure = globals;
globals->cGlobals.addAcceptor = gtk_socket_acceptor;
#endif
@ -2521,18 +2522,20 @@ freeGlobals( GtkAppGlobals* globals )
XP_Bool
makeNewGame( GtkAppGlobals* globals )
{
CommsAddrRec addr;
if ( !!globals->cGlobals.game.comms ) {
comms_getAddr( globals->cGlobals.game.comms, &addr );
CommonGlobals* cGlobals = &globals->cGlobals;
if ( !!cGlobals->game.comms ) {
comms_getAddr( cGlobals->game.comms, &cGlobals->addr );
} else {
comms_getInitialAddr( &addr, RELAY_NAME_DEFAULT, RELAY_PORT_DEFAULT );
comms_getInitialAddr( &cGlobals->addr, RELAY_NAME_DEFAULT,
RELAY_PORT_DEFAULT );
}
CurGameInfo* gi = &globals->cGlobals.gi;
XP_Bool success = newGameDialog( globals, gi, &addr, XP_TRUE, XP_FALSE );
if ( success && !!gi->dictName && !globals->cGlobals.dict ) {
globals->cGlobals.dict =
linux_dictionary_make( MEMPOOL globals->cGlobals.params,
CurGameInfo* gi = &cGlobals->gi;
XP_Bool success = newGameDialog( globals, gi, &cGlobals->addr,
XP_TRUE, XP_FALSE );
if ( success && !!gi->dictName && !cGlobals->dict ) {
cGlobals->dict =
linux_dictionary_make( MEMPOOL cGlobals->params,
gi->dictName, XP_TRUE );
}
LOG_RETURNF( "%d", success );

View file

@ -183,7 +183,7 @@ addButton( gchar* label, GtkWidget* parent, GCallback proc, void* closure )
}
static GtkWidget*
makeGamesWindow( GTKGamesGlobals* gg )
makeGamesWindow( GTKGamesGlobals* gg )
{
GtkWidget* window;
@ -195,6 +195,7 @@ makeGamesWindow( GTKGamesGlobals* gg )
gtk_container_add( GTK_CONTAINER(window), vbox );
gtk_widget_show( vbox );
GtkWidget* list = init_games_list( gg );
gg->listWidget = list;
gtk_container_add( GTK_CONTAINER(vbox), list );
gtk_widget_show( list );
@ -238,6 +239,17 @@ windowDestroyed( GtkAppGlobals* globals )
(void)g_idle_add( freeGameGlobals, globals );
}
void
newGameSaved( void* closure )
{
GtkAppGlobals* globals = (GtkAppGlobals*)closure;
GTKGamesGlobals* gg = globals->gg;
CommonGlobals* cGlobals = &globals->cGlobals;
XP_UCHAR buf[128];
getGameName( gg, &cGlobals->selRow, buf, sizeof(buf) );
add_to_list( gg->listWidget, &cGlobals->selRow, buf );
}
int
gtkmain( LaunchParams* params )
{
@ -245,7 +257,7 @@ gtkmain( LaunchParams* params )
gg.selRow = -1;
gg.params = params;
XP_LOGF( "%s: I'M HERE!!! (calling makeGamesDB())", __func__ );
gg.pDb = openGamesDB();
gg.pDb = openGamesDB( params->dbName );
(void)makeGamesWindow( &gg );
gtk_main();

View file

@ -25,5 +25,6 @@
int gtkmain( LaunchParams* params );
void windowDestroyed( GtkAppGlobals* globals );
void newGameSaved( void* closure );
#endif

View file

@ -74,7 +74,7 @@
#include "memstream.h"
#include "LocalizedStrIncludes.h"
#define DEFAULT_PORT 10999
#define DEFAULT_PORT 10997
#define DEFAULT_LISTEN_PORT 4998
XP_Bool
@ -523,6 +523,7 @@ typedef enum {
#endif
,CMD_GAMESEED
,CMD_GAMEFILE
,CMD_DBFILE
,CMD_SAVEFAIL_PCT
#ifdef USE_SQLITE
,CMD_GAMEDB_FILE
@ -620,6 +621,7 @@ static CmdInfoRec CmdInfoRecs[] = {
#endif
,{ CMD_GAMESEED, true, "game-seed", "game seed (for relay play)" }
,{ CMD_GAMEFILE, true, "file", "file to save to/read from" }
,{ CMD_DBFILE, true, "db", "sqlite3 db to store game data" }
,{ CMD_SAVEFAIL_PCT, true, "savefail-pct", "How often, at random, does save fail?" }
#ifdef USE_SQLITE
,{ CMD_GAMEDB_FILE, true, "game-db-file",
@ -1736,6 +1738,9 @@ main( int argc, char** argv )
case CMD_GAMEFILE:
mainParams.fileName = optarg;
break;
case CMD_DBFILE:
mainParams.dbName = optarg;
break;
case CMD_SAVEFAIL_PCT:
mainParams.saveFailPct = atoi( optarg );
break;

View file

@ -50,6 +50,7 @@ typedef struct LaunchParams {
GSList* dictDirs;
char* fileName;
char* dbName;
XP_U16 saveFailPct;
const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS];
#ifdef USE_SQLITE
@ -162,6 +163,8 @@ typedef struct _TimerInfo {
#endif
} TimerInfo;
typedef void (*FirstSaveFunc)(void* closure);
struct CommonGlobals {
LaunchParams* params;
CommonPrefs cp;
@ -169,6 +172,7 @@ struct CommonGlobals {
XWGame game;
CurGameInfo gi;
CommsAddrRec addr;
DictionaryCtxt* dict;
PlayerDicts dicts;
XP_U16 lastNTilesToUse;
@ -179,6 +183,8 @@ struct CommonGlobals {
SocketChangedFunc socketChanged;
void* socketChangedClosure;
FirstSaveFunc firstSave;
void* firstSaveClosure;
CommsRelayState state;
@ -216,6 +222,7 @@ typedef struct _GTKGamesGlobals {
sqlite3_int64 selRow;
LaunchParams* params;
GSList* globalsList;
GtkWidget* listWidget;
} GTKGamesGlobals;
#endif