test deletion of games and generation of anonymous relayIDs

This commit is contained in:
Eric House 2013-01-29 07:42:10 -08:00
parent 9ee16adc3a
commit c75ecef240
12 changed files with 132 additions and 63 deletions

View file

@ -1769,14 +1769,18 @@ static void
cursesDevIDChanged( void* closure, const XP_UCHAR* devID ) cursesDevIDChanged( void* closure, const XP_UCHAR* devID )
{ {
CursesAppGlobals* globals = (CursesAppGlobals*)closure; CursesAppGlobals* globals = (CursesAppGlobals*)closure;
sqlite3* pDb = globals->cGlobals.pDb; CommonGlobals* cGlobals = &globals->cGlobals;
sqlite3* pDb = cGlobals->pDb;
if ( !!devID ) { if ( !!devID ) {
XP_LOGF( "%s(devID=%s)", __func__, devID ); XP_LOGF( "%s(devID=%s)", __func__, devID );
db_store( pDb, KEY_RDEVID, devID ); db_store( pDb, KEY_RDEVID, devID );
} else { } else {
XP_LOGF( "%s: bad relayid", __func__ ); XP_LOGF( "%s: bad relayid", __func__ );
db_remove( pDb, KEY_RDEVID ); db_remove( pDb, KEY_RDEVID );
sendRelayReg( globals->cGlobals.params, pDb );
DevIDType typ;
const XP_UCHAR* devID = linux_getDevID( cGlobals->params, &typ );
relaycon_reg( cGlobals->params, devID, typ );
} }
} }
@ -1945,7 +1949,9 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
relaycon_init( params, &procs, &g_globals, relaycon_init( params, &procs, &g_globals,
params->connInfo.relay.relayName, params->connInfo.relay.relayName,
params->connInfo.relay.defaultSendPort ); params->connInfo.relay.defaultSendPort );
sendRelayReg( params, g_globals.cGlobals.pDb ); DevIDType typ;
const XP_UCHAR* devID = linux_getDevID( params, &typ );
relaycon_reg( params, devID, typ );
GSList* games = listGames( g_globals.cGlobals.pDb ); GSList* games = listGames( g_globals.cGlobals.pDb );
if ( !!games ) { if ( !!games ) {

View file

@ -247,9 +247,10 @@ db_store( sqlite3* pDb, const gchar* key, const gchar* value )
sqlite3_finalize( ppStmt ); sqlite3_finalize( ppStmt );
} }
void XP_Bool
db_fetch( sqlite3* pDb, const gchar* key, gchar* buf, gint buflen ) db_fetch( sqlite3* pDb, const gchar* key, gchar* buf, gint buflen )
{ {
XP_Bool found;
char query[256]; char query[256];
snprintf( query, sizeof(query), snprintf( query, sizeof(query),
"SELECT value from pairs where key = '%s'", key ); "SELECT value from pairs where key = '%s'", key );
@ -257,12 +258,14 @@ db_fetch( sqlite3* pDb, const gchar* key, gchar* buf, gint buflen )
int result = sqlite3_prepare_v2( pDb, query, -1, &ppStmt, NULL ); int result = sqlite3_prepare_v2( pDb, query, -1, &ppStmt, NULL );
XP_ASSERT( SQLITE_OK == result ); XP_ASSERT( SQLITE_OK == result );
result = sqlite3_step( ppStmt ); result = sqlite3_step( ppStmt );
if ( SQLITE_ROW == result ) { found = SQLITE_ROW == result;
if ( found ) {
getColumnText( ppStmt, 0, buf, buflen ); getColumnText( ppStmt, 0, buf, buflen );
} else { } else {
buf[0] = '\0'; buf[0] = '\0';
} }
sqlite3_finalize( ppStmt ); sqlite3_finalize( ppStmt );
return found;
} }
void void

View file

@ -52,7 +52,7 @@ void deleteGame( sqlite3* pDb, sqlite3_int64 rowid );
#define KEY_RDEVID "RDEVID" #define KEY_RDEVID "RDEVID"
void db_store( sqlite3* dbp, const gchar* key, const gchar* value ); void db_store( sqlite3* dbp, const gchar* key, const gchar* value );
void db_fetch( sqlite3* dbp, const gchar* key, gchar* buf, gint buflen ); XP_Bool db_fetch( sqlite3* dbp, const gchar* key, gchar* buf, gint buflen );
void db_remove( sqlite3* dbp, const gchar* key ); void db_remove( sqlite3* dbp, const gchar* key );
#endif #endif

View file

@ -310,9 +310,11 @@ relay_status_gtk( void* closure, CommsRelayState state )
{ {
XP_LOGF( "%s got status: %s", __func__, CommsRelayState2Str(state) ); XP_LOGF( "%s got status: %s", __func__, CommsRelayState2Str(state) );
GtkGameGlobals* globals = (GtkGameGlobals*)closure; GtkGameGlobals* globals = (GtkGameGlobals*)closure;
globals->cGlobals.state = state; if ( !!globals->draw ) {
globals->stateChar = 'A' + COMMS_RELAYSTATE_ALLCONNECTED - state; globals->cGlobals.state = state;
draw_gtk_status( globals->draw, globals->stateChar ); globals->stateChar = 'A' + COMMS_RELAYSTATE_ALLCONNECTED - state;
draw_gtk_status( globals->draw, globals->stateChar );
}
} }
static void static void
@ -2570,9 +2572,10 @@ freeGlobals( GtkGameGlobals* globals )
XP_Bool XP_Bool
loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params, loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
sqlite3* pDb, sqlite3_int64 rowid ) sqlite3_int64 rowid )
{ {
LOG_FUNC(); LOG_FUNC();
sqlite3* pDb = params->pDb;
initGlobalsNoDraw( globals, params ); initGlobalsNoDraw( globals, params );
TransportProcs procs; TransportProcs procs;

View file

@ -170,7 +170,7 @@ void initGlobals( GtkGameGlobals* globals, LaunchParams* params );
void freeGlobals( GtkGameGlobals* globals ); void freeGlobals( GtkGameGlobals* globals );
XP_Bool makeNewGame( GtkGameGlobals* globals ); XP_Bool makeNewGame( GtkGameGlobals* globals );
XP_Bool loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params, XP_Bool loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
sqlite3* pDb, sqlite3_int64 rowid ); sqlite3_int64 rowid );
void destroy_board_window( GtkWidget* widget, GtkGameGlobals* globals ); void destroy_board_window( GtkWidget* widget, GtkGameGlobals* globals );
#endif /* PLATFORM_GTK */ #endif /* PLATFORM_GTK */

View file

@ -208,7 +208,7 @@ handle_newgame_button( GtkWidget* XP_UNUSED(widget), void* closure )
freeGlobals( globals ); freeGlobals( globals );
} else { } else {
GtkWidget* gameWindow = globals->window; GtkWidget* gameWindow = globals->window;
globals->cGlobals.pDb = apg->pDb; globals->cGlobals.pDb = apg->params->pDb;
globals->cGlobals.selRow = -1; globals->cGlobals.selRow = -1;
recordOpened( apg, globals ); recordOpened( apg, globals );
gtk_widget_show( gameWindow ); gtk_widget_show( gameWindow );
@ -224,7 +224,7 @@ handle_open_button( GtkWidget* XP_UNUSED(widget), void* closure )
apg->params->needsNewGame = XP_FALSE; apg->params->needsNewGame = XP_FALSE;
GtkGameGlobals* globals = malloc( sizeof(*globals) ); GtkGameGlobals* globals = malloc( sizeof(*globals) );
initGlobals( globals, apg->params ); initGlobals( globals, apg->params );
globals->cGlobals.pDb = apg->pDb; globals->cGlobals.pDb = apg->params->pDb;
globals->cGlobals.selRow = selRow; globals->cGlobals.selRow = selRow;
recordOpened( apg, globals ); recordOpened( apg, globals );
gtk_widget_show( globals->window ); gtk_widget_show( globals->window );
@ -235,11 +235,20 @@ static void
handle_delete_button( GtkWidget* XP_UNUSED(widget), void* closure ) handle_delete_button( GtkWidget* XP_UNUSED(widget), void* closure )
{ {
GtkAppGlobals* apg = (GtkAppGlobals*)closure; GtkAppGlobals* apg = (GtkAppGlobals*)closure;
LaunchParams* params = apg->params;
guint len = apg->selRows->len; guint len = apg->selRows->len;
for ( guint ii = 0; ii < len; ++ii ) { for ( guint ii = 0; ii < len; ++ii ) {
sqlite3_int64 rowid = g_array_index( apg->selRows, sqlite3_int64, ii ); sqlite3_int64 rowid = g_array_index( apg->selRows, sqlite3_int64, ii );
removeRow( apg, rowid ); removeRow( apg, rowid );
deleteGame( apg->pDb, rowid ); deleteGame( params->pDb, rowid );
XP_UCHAR devIDBuf[64] = {0};
db_fetch( params->pDb, KEY_RDEVID, devIDBuf, sizeof(devIDBuf) );
if ( '\0' != devIDBuf[0] ) {
relaycon_deleted( params, devIDBuf, rowid );
} else {
XP_LOGF( "%s: not calling relaycon_deleted: no relayID", __func__ );
}
} }
apg->selRows = g_array_set_size( apg->selRows, 0 ); apg->selRows = g_array_set_size( apg->selRows, 0 );
updateButtons( apg ); updateButtons( apg );
@ -301,7 +310,7 @@ makeGamesWindow( GtkAppGlobals* apg )
gtk_widget_show( list ); gtk_widget_show( list );
GSList* games = listGames( apg->pDb ); GSList* games = listGames( apg->params->pDb );
for ( GSList* iter = games; !!iter; iter = iter->next ) { for ( GSList* iter = games; !!iter; iter = iter->next ) {
sqlite3_int64* rowid = (sqlite3_int64*)iter->data; sqlite3_int64* rowid = (sqlite3_int64*)iter->data;
onNewData( apg, *rowid, XP_TRUE ); onNewData( apg, *rowid, XP_TRUE );
@ -346,7 +355,7 @@ static void
onNewData( GtkAppGlobals* apg, sqlite3_int64 rowid, XP_Bool isNew ) onNewData( GtkAppGlobals* apg, sqlite3_int64 rowid, XP_Bool isNew )
{ {
GameInfo gib; GameInfo gib;
if ( getGameInfo( apg->pDb, rowid, &gib ) ) { if ( getGameInfo( apg->params->pDb, rowid, &gib ) ) {
add_to_list( apg->listWidget, rowid, isNew, &gib ); add_to_list( apg->listWidget, rowid, isNew, &gib );
} }
} }
@ -400,7 +409,7 @@ gtkGotBuf( void* closure, const XP_U8* buf, XP_U16 len )
gameGotBuf( &globals->cGlobals, XP_TRUE, buf, len ); gameGotBuf( &globals->cGlobals, XP_TRUE, buf, len );
} else { } else {
GtkGameGlobals tmpGlobals; GtkGameGlobals tmpGlobals;
if ( loadGameNoDraw( &tmpGlobals, apg->params, apg->pDb, gameToken ) ) { if ( loadGameNoDraw( &tmpGlobals, apg->params, gameToken ) ) {
gameGotBuf( &tmpGlobals.cGlobals, XP_FALSE, buf, len ); gameGotBuf( &tmpGlobals.cGlobals, XP_FALSE, buf, len );
saveGame( &tmpGlobals.cGlobals ); saveGame( &tmpGlobals.cGlobals );
} }
@ -413,7 +422,7 @@ requestMsgs( gpointer data )
{ {
GtkAppGlobals* apg = (GtkAppGlobals*)data; GtkAppGlobals* apg = (GtkAppGlobals*)data;
XP_UCHAR devIDBuf[64] = {0}; XP_UCHAR devIDBuf[64] = {0};
db_fetch( apg->pDb, KEY_RDEVID, devIDBuf, sizeof(devIDBuf) ); db_fetch( apg->params->pDb, KEY_RDEVID, devIDBuf, sizeof(devIDBuf) );
if ( '\0' != devIDBuf[0] ) { if ( '\0' != devIDBuf[0] ) {
relaycon_requestMsgs( apg->params, devIDBuf ); relaycon_requestMsgs( apg->params, devIDBuf );
} else { } else {
@ -434,13 +443,17 @@ static void
gtkDevIDChanged( void* closure, const XP_UCHAR* devID ) gtkDevIDChanged( void* closure, const XP_UCHAR* devID )
{ {
GtkAppGlobals* apg = (GtkAppGlobals*)closure; GtkAppGlobals* apg = (GtkAppGlobals*)closure;
LaunchParams* params = apg->params;
if ( !!devID ) { if ( !!devID ) {
XP_LOGF( "%s(devID=%s)", __func__, devID ); XP_LOGF( "%s(devID=%s)", __func__, devID );
db_store( apg->pDb, KEY_RDEVID, devID ); db_store( params->pDb, KEY_RDEVID, devID );
} else { } else {
XP_LOGF( "%s: bad relayid", __func__ ); XP_LOGF( "%s: bad relayid", __func__ );
db_remove( apg->pDb, KEY_RDEVID ); db_remove( params->pDb, KEY_RDEVID );
sendRelayReg( apg->params, apg->pDb );
DevIDType typ;
const XP_UCHAR* devID = linux_getDevID( params, &typ );
relaycon_reg( params, devID, typ );
} }
} }
@ -494,7 +507,7 @@ gtkmain( LaunchParams* params )
apg.selRows = g_array_new( FALSE, FALSE, sizeof( sqlite3_int64 ) ); apg.selRows = g_array_new( FALSE, FALSE, sizeof( sqlite3_int64 ) );
apg.params = params; apg.params = params;
apg.pDb = openGamesDB( params->dbName ); params->pDb = openGamesDB( params->dbName );
RelayConnProcs procs = { RelayConnProcs procs = {
.msgReceived = gtkGotBuf, .msgReceived = gtkGotBuf,
@ -507,12 +520,15 @@ gtkmain( LaunchParams* params )
relaycon_init( params, &procs, &apg, relaycon_init( params, &procs, &apg,
params->connInfo.relay.relayName, params->connInfo.relay.relayName,
params->connInfo.relay.defaultSendPort ); params->connInfo.relay.defaultSendPort );
sendRelayReg( params, apg.pDb );
DevIDType typ;
const XP_UCHAR* devID = linux_getDevID( params, &typ );
relaycon_reg( params, devID, typ );
apg.window = makeGamesWindow( &apg ); apg.window = makeGamesWindow( &apg );
gtk_main(); gtk_main();
closeGamesDB( apg.pDb ); closeGamesDB( params->pDb );
relaycon_cleanup( params ); relaycon_cleanup( params );
return 0; return 0;

View file

@ -580,7 +580,8 @@ setOneSecondTimer( CommonGlobals* cGlobals )
#endif #endif
typedef enum { typedef enum {
CMD_SKIP_GAMEOVER CMD_HELP
,CMD_SKIP_GAMEOVER
,CMD_SHOW_OTHERSCORES ,CMD_SHOW_OTHERSCORES
,CMD_HOSTIP ,CMD_HOSTIP
,CMD_DICT ,CMD_DICT
@ -595,6 +596,7 @@ typedef enum {
#ifdef XWFEATURE_DEVID #ifdef XWFEATURE_DEVID
,CMD_DEVID ,CMD_DEVID
,CMD_RDEVID ,CMD_RDEVID
,CMD_NOANONDEVID
#endif #endif
,CMD_GAMESEED ,CMD_GAMESEED
,CMD_GAMEFILE ,CMD_GAMEFILE
@ -678,7 +680,8 @@ typedef struct _CmdInfoRec {
} CmdInfoRec; } CmdInfoRec;
static CmdInfoRec CmdInfoRecs[] = { static CmdInfoRec CmdInfoRecs[] = {
{ CMD_SKIP_GAMEOVER, false, "skip-final", "skip final scores display" } { CMD_HELP, false, "help", "print usage" }
,{ CMD_SKIP_GAMEOVER, false, "skip-final", "skip final scores display" }
,{ CMD_SHOW_OTHERSCORES, false, "show-other", "show robot/remote scores" } ,{ CMD_SHOW_OTHERSCORES, false, "show-other", "show robot/remote scores" }
,{ CMD_HOSTIP, true, "hostip", "remote host ip address (for direct connect)" } ,{ CMD_HOSTIP, true, "hostip", "remote host ip address (for direct connect)" }
,{ CMD_DICT, true, "game-dict", "dictionary name for game" } ,{ CMD_DICT, true, "game-dict", "dictionary name for game" }
@ -693,6 +696,8 @@ static CmdInfoRec CmdInfoRecs[] = {
#ifdef XWFEATURE_DEVID #ifdef XWFEATURE_DEVID
,{ CMD_DEVID, true, "devid", "device ID (for testing GCM stuff)" } ,{ CMD_DEVID, true, "devid", "device ID (for testing GCM stuff)" }
,{ CMD_RDEVID, true, "rdevid", "relay's converted device ID (for testing GCM stuff)" } ,{ CMD_RDEVID, true, "rdevid", "relay's converted device ID (for testing GCM stuff)" }
,{CMD_NOANONDEVID, false, "no-anon-devid",
"override default of using anonymous devid registration when no id provided" }
#endif #endif
,{ 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" }
@ -851,24 +856,28 @@ linShiftFocus( CommonGlobals* cGlobals, XP_Key key, const BoardObjectType* order
} /* linShiftFocus */ } /* linShiftFocus */
#endif #endif
void const XP_UCHAR*
sendRelayReg( LaunchParams* params, sqlite3* pDb ) linux_getDevID( LaunchParams* params, DevIDType* typ )
{ {
XP_UCHAR devIDBuf[64] = {0}; const XP_UCHAR* result = NULL;
XP_UCHAR* devID;
DevIDType typ = ID_TYPE_RELAY; /* commandline takes precedence over stored values */
if ( !!params->rDevID ) { if ( !!params->rDevID ) {
devID = params->rDevID; result = params->rDevID;
} else { *typ = ID_TYPE_RELAY;
db_fetch( pDb, KEY_RDEVID, devIDBuf, sizeof(devIDBuf) ); } else if ( !!params->devID ) {
if ( '\0' != devIDBuf[0] ) { result = params->devID;
devID = devIDBuf; *typ = ID_TYPE_LINUX;
} else { } else if ( db_fetch( params->pDb, KEY_RDEVID, params->devIDStore,
devID = params->devID; sizeof(params->devIDStore) ) ) {
typ = ID_TYPE_LINUX; result = params->devIDStore;
} *typ = ID_TYPE_RELAY;
} else if ( !params->noAnonDevid ) {
*typ = ID_TYPE_ANON;
result = "";
} }
relaycon_reg( params, devID, typ ); return result;
} }
#ifdef XWFEATURE_RELAY #ifdef XWFEATURE_RELAY
@ -1843,7 +1852,7 @@ main( int argc, char** argv )
short index; short index;
opt = getopt_long_only( argc, argv, "", longopts, NULL ); opt = getopt_long_only( argc, argv, "", longopts, NULL );
switch ( opt ) { switch ( opt ) {
case '?': case CMD_HELP:
usage(argv[0], NULL); usage(argv[0], NULL);
break; break;
case CMD_SKIP_GAMEOVER: case CMD_SKIP_GAMEOVER:
@ -1906,6 +1915,8 @@ main( int argc, char** argv )
case CMD_RDEVID: case CMD_RDEVID:
mainParams.rDevID = optarg; mainParams.rDevID = optarg;
break; break;
case CMD_NOANONDEVID:
mainParams.noAnonDevid = true;
#endif #endif
case CMD_GAMESEED: case CMD_GAMESEED:
mainParams.gameSeed = atoi(optarg); mainParams.gameSeed = atoi(optarg);

View file

@ -106,6 +106,7 @@ void gameGotBuf( CommonGlobals* globals, XP_Bool haveDraw,
const XP_U8* buf, XP_U16 len ); const XP_U8* buf, XP_U16 len );
gboolean app_socket_proc( GIOChannel* source, GIOCondition condition, gboolean app_socket_proc( GIOChannel* source, GIOCondition condition,
gpointer data ); gpointer data );
const XP_UCHAR* linux_getDevID( LaunchParams* params, DevIDType* typ );
/* void initParams( LaunchParams* params ); */ /* void initParams( LaunchParams* params ); */
/* void freeParams( LaunchParams* params ); */ /* void freeParams( LaunchParams* params ); */

View file

@ -32,6 +32,7 @@
#include "linuxutl.h" #include "linuxutl.h"
#include "main.h" #include "main.h"
#include "linuxdict.h" #include "linuxdict.h"
#include "linuxmain.h"
#include "LocalizedStrIncludes.h" #include "LocalizedStrIncludes.h"
#ifdef DEBUG #ifdef DEBUG
@ -349,19 +350,8 @@ linux_util_getUserString( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 code )
static const XP_UCHAR* static const XP_UCHAR*
linux_util_getDevID( XW_UtilCtxt* uc, DevIDType* typ ) linux_util_getDevID( XW_UtilCtxt* uc, DevIDType* typ )
{ {
XP_UCHAR* result;
CommonGlobals* cGlobals = (CommonGlobals*)uc->closure; CommonGlobals* cGlobals = (CommonGlobals*)uc->closure;
if ( !!cGlobals->params->rDevID ) { return linux_getDevID( cGlobals->params, typ );
*typ = ID_TYPE_RELAY;
result = cGlobals->params->rDevID;
} else if ( !!cGlobals->params->devID ) {
*typ = ID_TYPE_LINUX;
result = cGlobals->params->devID;
} else {
*typ = ID_TYPE_NONE;
result = NULL;
}
return result;
} }
static void static void

View file

@ -55,6 +55,7 @@ typedef struct LaunchParams {
GSList* dictDirs; GSList* dictDirs;
char* fileName; char* fileName;
char* dbName; char* dbName;
sqlite3* pDb; /* null unless opened */
XP_U16 saveFailPct; XP_U16 saveFailPct;
const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS]; const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS];
#ifdef USE_SQLITE #ifdef USE_SQLITE
@ -68,6 +69,8 @@ typedef struct LaunchParams {
#ifdef XWFEATURE_DEVID #ifdef XWFEATURE_DEVID
char* devID; char* devID;
char* rDevID; char* rDevID;
XP_Bool noAnonDevid;
XP_UCHAR devIDStore[16];
#endif #endif
VTableMgr* vtMgr; VTableMgr* vtMgr;
XP_U16 nLocalPlayers; XP_U16 nLocalPlayers;
@ -231,7 +234,6 @@ typedef struct _SourceData {
} SourceData; } SourceData;
typedef struct _GtkAppGlobals { typedef struct _GtkAppGlobals {
sqlite3* pDb;
GArray* selRows; GArray* selRows;
LaunchParams* params; LaunchParams* params;
GSList* globalsList; GSList* globalsList;

View file

@ -43,8 +43,11 @@ static ssize_t sendIt( RelayConStorage* storage, const XP_U8* msgbuf, XP_U16 len
static size_t addStrWithLength( XP_U8* buf, XP_U8* end, const XP_UCHAR* str ); static size_t addStrWithLength( XP_U8* buf, XP_U8* end, const XP_UCHAR* str );
static void getNetString( const XP_U8** ptr, XP_U16 len, XP_UCHAR* buf ); static void getNetString( const XP_U8** ptr, XP_U16 len, XP_UCHAR* buf );
static XP_U16 getNetShort( const XP_U8** ptr ); static XP_U16 getNetShort( const XP_U8** ptr );
static XP_U32 getNetLong( const XP_U8** ptr );
static int writeHeader( XP_U8* dest, XWRelayReg cmd ); static int writeHeader( XP_U8* dest, XWRelayReg cmd );
static bool readHeader( const XP_U8** buf, MsgHeader* header ); static bool readHeader( const XP_U8** buf, MsgHeader* header );
static size_t writeDevID( XP_U8* buf, size_t len, const XP_UCHAR* str );
void void
relaycon_init( LaunchParams* params, const RelayConnProcs* procs, relaycon_init( LaunchParams* params, const RelayConnProcs* procs,
@ -73,15 +76,10 @@ relaycon_reg( LaunchParams* params, const XP_UCHAR* devID, DevIDType typ )
int indx = 0; int indx = 0;
RelayConStorage* storage = getStorage( params ); RelayConStorage* storage = getStorage( params );
XP_ASSERT( !!devID ); XP_ASSERT( !!devID || typ == ID_TYPE_ANON );
XP_U16 idLen = XP_STRLEN( devID );
XP_U16 lenNBO = XP_HTONS( idLen );
indx += writeHeader( tmpbuf, XWPDEV_REG ); indx += writeHeader( tmpbuf, XWPDEV_REG );
tmpbuf[indx++] = typ; tmpbuf[indx++] = typ;
XP_MEMCPY( &tmpbuf[indx], &lenNBO, sizeof(lenNBO) ); indx += writeDevID( &tmpbuf[indx], sizeof(tmpbuf) - indx, devID );
indx += sizeof(lenNBO);
XP_MEMCPY( &tmpbuf[indx], devID, idLen );
indx += idLen;
sendIt( storage, tmpbuf, indx ); sendIt( storage, tmpbuf, indx );
} }
@ -154,6 +152,23 @@ relaycon_requestMsgs( LaunchParams* params, const XP_UCHAR* devID )
sendIt( storage, tmpbuf, indx ); sendIt( storage, tmpbuf, indx );
} }
void
relaycon_deleted( LaunchParams* params, const XP_UCHAR* devID,
XP_U32 gameToken )
{
LOG_FUNC();
RelayConStorage* storage = getStorage( params );
XP_U8 tmpbuf[128];
int indx = 0;
indx += writeHeader( tmpbuf, XWPDEV_DELGAME );
indx += writeDevID( &tmpbuf[indx], sizeof(tmpbuf) - indx, devID );
gameToken = htonl( gameToken );
memcpy( &tmpbuf[indx], &gameToken, sizeof(gameToken) );
indx += sizeof( gameToken );
sendIt( storage, tmpbuf, indx );
}
static void static void
sendAckIf( RelayConStorage* storage, const MsgHeader* header ) sendAckIf( RelayConStorage* storage, const MsgHeader* header )
{ {
@ -214,6 +229,11 @@ relaycon_receive( void* closure, int socket )
(*storage->procs.msgErrorMsg)( storage->procsClosure, buf ); (*storage->procs.msgErrorMsg)( storage->procsClosure, buf );
break; break;
} }
case XWPDEV_ACK: {
XP_U32 packetID = getNetLong( &ptr );
XP_LOGF( "got ack for packetID %ld", packetID );
break;
}
default: default:
XP_LOGF( "%s: Unexpected cmd %d", __func__, header.cmd ); XP_LOGF( "%s: Unexpected cmd %d", __func__, header.cmd );
XP_ASSERT( 0 ); XP_ASSERT( 0 );
@ -273,7 +293,7 @@ sendIt( RelayConStorage* storage, const XP_U8* msgbuf, XP_U16 len )
static size_t static size_t
addStrWithLength( XP_U8* buf, XP_U8* end, const XP_UCHAR* str ) addStrWithLength( XP_U8* buf, XP_U8* end, const XP_UCHAR* str )
{ {
XP_U16 len = XP_STRLEN( str ); XP_U16 len = !!str? XP_STRLEN( str ) : 0;
if ( buf + len + sizeof(len) <= end ) { if ( buf + len + sizeof(len) <= end ) {
XP_U16 lenNBO = htons( len ); XP_U16 lenNBO = htons( len );
XP_MEMCPY( buf, &lenNBO, sizeof(lenNBO) ); XP_MEMCPY( buf, &lenNBO, sizeof(lenNBO) );
@ -283,6 +303,12 @@ addStrWithLength( XP_U8* buf, XP_U8* end, const XP_UCHAR* str )
return len + sizeof(len); return len + sizeof(len);
} }
static size_t
writeDevID( XP_U8* buf, size_t len, const XP_UCHAR* str )
{
return addStrWithLength( buf, buf + len, str );
}
static XP_U16 static XP_U16
getNetShort( const XP_U8** ptr ) getNetShort( const XP_U8** ptr )
{ {
@ -292,6 +318,15 @@ getNetShort( const XP_U8** ptr )
return ntohs( result ); return ntohs( result );
} }
static XP_U32
getNetLong( const XP_U8** ptr )
{
XP_U32 result;
memcpy( &result, *ptr, sizeof(result) );
*ptr += sizeof(result);
return ntohl( result );
}
static void static void
getNetString( const XP_U8** ptr, XP_U16 len, XP_UCHAR* buf ) getNetString( const XP_U8** ptr, XP_U16 len, XP_UCHAR* buf )
{ {

View file

@ -40,6 +40,8 @@ XP_S16 relaycon_send( LaunchParams* params, const XP_U8* buf, XP_U16 buflen,
XP_S16 relaycon_sendnoconn( LaunchParams* params, const XP_U8* buf, XP_U16 buflen, XP_S16 relaycon_sendnoconn( LaunchParams* params, const XP_U8* buf, XP_U16 buflen,
const XP_UCHAR* relayID, XP_U32 gameToken ); const XP_UCHAR* relayID, XP_U32 gameToken );
void relaycon_requestMsgs( LaunchParams* params, const XP_UCHAR* devID ); void relaycon_requestMsgs( LaunchParams* params, const XP_UCHAR* devID );
void relaycon_deleted( LaunchParams* params, const XP_UCHAR* devID,
XP_U32 gameToken );
void relaycon_cleanup( LaunchParams* params ); void relaycon_cleanup( LaunchParams* params );
#endif #endif