add relayID to DB and to table

This commit is contained in:
Eric House 2017-10-21 14:59:10 -07:00
parent a6602fabe0
commit ec7fde3b62
4 changed files with 40 additions and 27 deletions

View file

@ -52,6 +52,7 @@ openGamesDB( const char* dbName )
",inviteInfo BLOB" ",inviteInfo BLOB"
",room VARCHAR(32)" ",room VARCHAR(32)"
",connvia VARCHAR(32)" ",connvia VARCHAR(32)"
",relayid VARCHAR(32)"
",ended INT(1)" ",ended INT(1)"
",turn INT(2)" ",turn INT(2)"
",local INT(1)" ",local INT(1)"
@ -199,11 +200,12 @@ addSnapshot( CommonGlobals* cGlobals )
void void
summarize( CommonGlobals* cGlobals ) summarize( CommonGlobals* cGlobals )
{ {
XP_S16 nMoves = model_getNMoves( cGlobals->game.model ); const XWGame* game = &cGlobals->game;
XP_Bool gameOver = server_getGameIsOver( cGlobals->game.server ); XP_S16 nMoves = model_getNMoves( game->model );
XP_Bool gameOver = server_getGameIsOver( game->server );
XP_Bool isLocal; XP_Bool isLocal;
XP_S16 turn = server_getCurrentTurn( cGlobals->game.server, &isLocal ); XP_S16 turn = server_getCurrentTurn( game->server, &isLocal );
XP_U32 lastMoveTime = server_getLastMoveTime( cGlobals->game.server ); XP_U32 lastMoveTime = server_getLastMoveTime( game->server );
XP_U16 seed = 0; XP_U16 seed = 0;
XP_S16 nMissing = 0; XP_S16 nMissing = 0;
XP_U16 nTotal = cGlobals->gi->nPlayers; XP_U16 nTotal = cGlobals->gi->nPlayers;
@ -214,10 +216,11 @@ summarize( CommonGlobals* cGlobals )
// gchar* connvia = "local"; // gchar* connvia = "local";
gchar connvia[128] = {0}; gchar connvia[128] = {0};
XP_UCHAR relayID[32] = {0};
if ( !!cGlobals->game.comms ) { if ( !!game->comms ) {
nMissing = server_getMissingPlayers( cGlobals->game.server ); nMissing = server_getMissingPlayers( game->server );
comms_getAddr( cGlobals->game.comms, &addr ); comms_getAddr( game->comms, &addr );
CommsConnType typ; CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) { for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) {
if ( !!connvia[0] ) { if ( !!connvia[0] ) {
@ -242,18 +245,21 @@ summarize( CommonGlobals* cGlobals )
break; break;
} }
} }
seed = comms_getChannelSeed( cGlobals->game.comms ); seed = comms_getChannelSeed( game->comms );
XP_U16 len = VSIZE(relayID);
(void)comms_getRelayID( game->comms, relayID, &len );
} else { } else {
strcat( connvia, "local" ); strcat( connvia, "local" );
} }
const char* fmt = "UPDATE games " const char* fmt = "UPDATE games "
" SET room='%s', ended=%d, turn=%d, local=%d, ntotal=%d, nmissing=%d, " " SET room='%s', ended=%d, turn=%d, local=%d, ntotal=%d, "
" nmoves=%d, seed=%d, gameid=%d, connvia='%s', lastMoveTime=%d" " nmissing=%d, nmoves=%d, seed=%d, gameid=%d, connvia='%s', "
" relayid='%s', lastMoveTime=%d"
" WHERE rowid=%lld"; " WHERE rowid=%lld";
XP_UCHAR buf[256]; XP_UCHAR buf[256];
snprintf( buf, sizeof(buf), fmt, room, gameOver?1:0, turn, isLocal?1:0, snprintf( buf, sizeof(buf), fmt, room, gameOver?1:0, turn, isLocal?1:0,
nTotal, nMissing, nMoves, seed, gameID, connvia, lastMoveTime, nTotal, nMissing, nMoves, seed, gameID, connvia, relayID, lastMoveTime,
cGlobals->selRow ); cGlobals->selRow );
XP_LOGF( "query: %s", buf ); XP_LOGF( "query: %s", buf );
sqlite3_stmt* stmt = NULL; sqlite3_stmt* stmt = NULL;
@ -310,7 +316,7 @@ getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib )
{ {
XP_Bool success = XP_FALSE; XP_Bool success = XP_FALSE;
const char* fmt = "SELECT room, ended, turn, local, nmoves, ntotal, nmissing, " const char* fmt = "SELECT room, ended, turn, local, nmoves, ntotal, nmissing, "
"seed, connvia, gameid, lastMoveTime, snap " "seed, connvia, gameid, lastMoveTime, relayid, snap "
"FROM games WHERE rowid = %lld"; "FROM games WHERE rowid = %lld";
XP_UCHAR query[256]; XP_UCHAR query[256];
snprintf( query, sizeof(query), fmt, rowid ); snprintf( query, sizeof(query), fmt, rowid );
@ -321,25 +327,28 @@ getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib )
result = sqlite3_step( ppStmt ); result = sqlite3_step( ppStmt );
if ( SQLITE_ROW == result ) { if ( SQLITE_ROW == result ) {
success = XP_TRUE; success = XP_TRUE;
getColumnText( ppStmt, 0, gib->room, sizeof(gib->room) ); int col = 0;
gib->gameOver = 1 == sqlite3_column_int( ppStmt, 1 ); getColumnText( ppStmt, col++, gib->room, sizeof(gib->room) );
gib->turn = sqlite3_column_int( ppStmt, 2 ); gib->gameOver = 1 == sqlite3_column_int( ppStmt, col++ );
gib->turnLocal = 1 == sqlite3_column_int( ppStmt, 3 ); gib->turn = sqlite3_column_int( ppStmt, col++ );
gib->nMoves = sqlite3_column_int( ppStmt, 4 ); gib->turnLocal = 1 == sqlite3_column_int( ppStmt, col++ );
gib->nTotal = sqlite3_column_int( ppStmt, 5 ); gib->nMoves = sqlite3_column_int( ppStmt, col++ );
gib->nMissing = sqlite3_column_int( ppStmt, 6 ); gib->nTotal = sqlite3_column_int( ppStmt, col++ );
gib->seed = sqlite3_column_int( ppStmt, 7 ); gib->nMissing = sqlite3_column_int( ppStmt, col++ );
getColumnText( ppStmt, 8, gib->conn, sizeof(gib->conn) ); gib->seed = sqlite3_column_int( ppStmt, col++ );
gib->gameID = sqlite3_column_int( ppStmt, 9 ); getColumnText( ppStmt, col++, gib->conn, sizeof(gib->conn) );
gib->lastMoveTime = sqlite3_column_int( ppStmt, 10 ); gib->gameID = sqlite3_column_int( ppStmt, col++ );
gib->lastMoveTime = sqlite3_column_int( ppStmt, col++ );
getColumnText( ppStmt, col++, gib->relayID, sizeof(gib->relayID) );
snprintf( gib->name, sizeof(gib->name), "Game %lld", rowid ); snprintf( gib->name, sizeof(gib->name), "Game %lld", rowid );
#ifdef PLATFORM_GTK #ifdef PLATFORM_GTK
/* Load the snapshot */ /* Load the snapshot */
GdkPixbuf* snap = NULL; GdkPixbuf* snap = NULL;
const XP_U8* ptr = sqlite3_column_blob( ppStmt, 11 ); int snapCol = col++;
const XP_U8* ptr = sqlite3_column_blob( ppStmt, snapCol );
if ( !!ptr ) { if ( !!ptr ) {
int size = sqlite3_column_bytes( ppStmt, 11 ); int size = sqlite3_column_bytes( ppStmt, snapCol );
/* Skip the version that's written in */ /* Skip the version that's written in */
ptr += sizeof(XP_U16); size -= sizeof(XP_U16); ptr += sizeof(XP_U16); size -= sizeof(XP_U16);
GInputStream* istr = g_memory_input_stream_new_from_data( ptr, size, NULL ); GInputStream* istr = g_memory_input_stream_new_from_data( ptr, size, NULL );

View file

@ -31,6 +31,7 @@ typedef struct _GameInfo {
XP_UCHAR name[128]; XP_UCHAR name[128];
XP_UCHAR room[128]; XP_UCHAR room[128];
XP_UCHAR conn[128]; XP_UCHAR conn[128];
XP_UCHAR relayID[32];
#ifdef PLATFORM_GTK #ifdef PLATFORM_GTK
GdkPixbuf* snap; GdkPixbuf* snap;
#endif #endif

View file

@ -1315,7 +1315,7 @@ static void
disenable_buttons( GtkGameGlobals* globals ) disenable_buttons( GtkGameGlobals* globals )
{ {
XP_U16 nPending = server_getPendingRegs( globals->cGlobals.game.server ); XP_U16 nPending = server_getPendingRegs( globals->cGlobals.game.server );
if ( !globals->invite_button && 0 < nPending ) { if ( !globals->invite_button && 0 < nPending && !!globals->buttons_hbox ) {
globals->invite_button = globals->invite_button =
addButton( globals->buttons_hbox, "Invite", addButton( globals->buttons_hbox, "Invite",
G_CALLBACK(handle_invite_button), globals ); G_CALLBACK(handle_invite_button), globals );

View file

@ -76,7 +76,7 @@ findOpenGame( const GtkAppGlobals* apg, sqlite3_int64 rowid )
} }
enum { ROW_ITEM, ROW_THUMB, NAME_ITEM, ROOM_ITEM, GAMEID_ITEM, SEED_ITEM, enum { ROW_ITEM, ROW_THUMB, NAME_ITEM, ROOM_ITEM, GAMEID_ITEM, SEED_ITEM,
CONN_ITEM, OVER_ITEM, TURN_ITEM, LOCAL_ITEM, NMOVES_ITEM, NTOTAL_ITEM, CONN_ITEM, RELAYID_ITEM, OVER_ITEM, TURN_ITEM, LOCAL_ITEM, NMOVES_ITEM, NTOTAL_ITEM,
MISSING_ITEM, LASTTURN_ITEM, N_ITEMS }; MISSING_ITEM, LASTTURN_ITEM, N_ITEMS };
static void static void
@ -167,6 +167,7 @@ init_games_list( GtkAppGlobals* apg )
addTextColumn( list, "GameID", GAMEID_ITEM ); addTextColumn( list, "GameID", GAMEID_ITEM );
addTextColumn( list, "Seed", SEED_ITEM ); addTextColumn( list, "Seed", SEED_ITEM );
addTextColumn( list, "Conn. via", CONN_ITEM ); addTextColumn( list, "Conn. via", CONN_ITEM );
addTextColumn( list, "RelayID", RELAYID_ITEM );
addTextColumn( list, "Ended", OVER_ITEM ); addTextColumn( list, "Ended", OVER_ITEM );
addTextColumn( list, "Turn", TURN_ITEM ); addTextColumn( list, "Turn", TURN_ITEM );
addTextColumn( list, "Local", LOCAL_ITEM ); addTextColumn( list, "Local", LOCAL_ITEM );
@ -183,6 +184,7 @@ init_games_list( GtkAppGlobals* apg )
G_TYPE_INT, /* GAMEID_ITEM */ G_TYPE_INT, /* GAMEID_ITEM */
G_TYPE_INT, /* SEED_ITEM */ G_TYPE_INT, /* SEED_ITEM */
G_TYPE_STRING, /* CONN_ITEM */ G_TYPE_STRING, /* CONN_ITEM */
G_TYPE_STRING, /*RELAYID_ITEM */
G_TYPE_BOOLEAN, /* OVER_ITEM */ G_TYPE_BOOLEAN, /* OVER_ITEM */
G_TYPE_INT, /* TURN_ITEM */ G_TYPE_INT, /* TURN_ITEM */
G_TYPE_STRING, /* LOCAL_ITEM */ G_TYPE_STRING, /* LOCAL_ITEM */
@ -239,6 +241,7 @@ add_to_list( GtkWidget* list, sqlite3_int64 rowid, XP_Bool isNew,
GAMEID_ITEM, gib->gameID, GAMEID_ITEM, gib->gameID,
SEED_ITEM, gib->seed, SEED_ITEM, gib->seed,
CONN_ITEM, gib->conn, CONN_ITEM, gib->conn,
RELAYID_ITEM, gib->relayID,
TURN_ITEM, gib->turn, TURN_ITEM, gib->turn,
OVER_ITEM, gib->gameOver, OVER_ITEM, gib->gameOver,
LOCAL_ITEM, localString, LOCAL_ITEM, localString,