changes to fix curses app test script

especially on the 'sms' side it was broken. Now Android's broken for sure.
This commit is contained in:
katianderic 2020-02-24 21:10:49 +01:00
parent 0486b956c8
commit 126172220f
13 changed files with 209 additions and 189 deletions

View file

@ -1,6 +1,6 @@
/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */
/*
* Copyright 2001 - 2014 by Eric House (xwords@eehouse.org). All rights
* Copyright 2001 - 2020 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
@ -190,8 +190,9 @@ static AddressRecord* rememberChannelAddress( CommsCtxt* comms,
XP_PlayerAddr channelNo,
XWHostID id,
const CommsAddrRec* addr );
static void augmentChannelAddr( CommsCtxt* comms, AddressRecord* rec,
const CommsAddrRec* addr, XWHostID hostID );
static void augmentChannelAddr( AddressRecord* rec, const CommsAddrRec* addr,
XWHostID hostID );
static void augmentAddr( CommsAddrRec* dest, const CommsAddrRec* src );
static XP_Bool channelToAddress( CommsCtxt* comms, XP_PlayerAddr channelNo,
const CommsAddrRec** addr );
static AddressRecord* getRecordFor( CommsCtxt* comms, const CommsAddrRec* addr,
@ -231,7 +232,6 @@ static void logAddrs( const CommsCtxt* comms, const char* caller );
# else
# define printQueue( comms )
# define logAddr( comms, addr, caller )
# endif
#endif
#if defined RELAY_HEARTBEAT || defined COMMS_HEARTBEAT
@ -828,7 +828,7 @@ sendConnect( CommsCtxt* comms, XP_Bool breakExisting )
}
setHeartbeatTimer( comms );
} /* comms_start */
} /* sendConnect */
static void
addrToStreamOne( XWStreamCtxt* stream, CommsConnType typ, const CommsAddrRec* addrP )
@ -994,17 +994,28 @@ comms_getAddr( const CommsCtxt* comms, CommsAddrRec* addr )
} /* comms_getAddr */
void
comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr )
comms_augmentHostAddr( CommsCtxt* comms, const CommsAddrRec* addr )
{
logAddr( comms, addr, __func__ );
XP_ASSERT( comms != NULL );
util_addrChange( comms->util, &comms->addr, addr );
XP_MEMCPY( &comms->addr, addr, sizeof(comms->addr) );
XP_Bool addingRelay = addr_hasType( addr, COMMS_CONN_RELAY )
&& ! addr_hasType( &comms->addr, COMMS_CONN_RELAY );
CommsAddrRec tmp = comms->addr;
augmentAddr( &tmp, addr );
util_addrChange( comms->util, &comms->addr, &tmp );
comms->addr = tmp;
logAddr( comms, &comms->addr, "after" );
#ifdef COMMS_HEARTBEAT
setDoHeartbeat( comms );
#endif
sendConnect( comms, XP_TRUE );
} /* comms_setAddr */
if ( addingRelay ) {
sendConnect( comms, XP_TRUE );
}
} /* comms_setHostAddr */
void
comms_getAddrs( const CommsCtxt* comms, CommsAddrRec addr[], XP_U16* nRecs )
@ -1210,7 +1221,7 @@ comms_getChannelSeed( CommsCtxt* comms )
result = XP_RANDOM() & ~CHANNEL_MASK;
result |= comms->forceChannel;
CNO_FMT( cbuf, result );
XP_LOGF( "%s: made seed: %s(%d)", __func__, cbuf, result );
XP_LOGFF( "made seed: %s(%d)", cbuf, result );
comms->channelSeed = result;
}
return result;
@ -1443,8 +1454,19 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem, const CommsConnType filter )
elem->len, cbuf, elem->checksum );
#endif
CommsAddrRec addr;
const CommsAddrRec* addrP;
(void)channelToAddress( comms, channelNo, &addrP );
if ( NULL == addrP ) {
XP_LOGF( TAGFMT() "no addr for channel so using comms'", TAGPRMS );
comms_getAddr( comms, &addr );
logAddr( comms, &addr, "default case" );
} else {
addr = *addrP;
}
CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( &comms->addr, &typ, &st ); ) {
for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) {
XP_S16 nSent = -1;
if ( comms_getAddrDisabled( comms, typ, XP_TRUE ) ) {
XP_LOGF( "%s: dropping message because %s disabled", __func__,
@ -1488,17 +1510,6 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem, const CommsConnType filter )
break;
#endif
default: {
CommsAddrRec addr;
const CommsAddrRec* addrP;
(void)channelToAddress( comms, channelNo, &addrP );
if ( NULL == addrP || !addr_hasType( addrP, typ ) ) {
XP_LOGF( TAGFMT() "no addr for channel or addr type %s"
" so using comms'", TAGPRMS, ConnType2Str(typ) );
comms_getAddr( comms, &addr );
} else {
addr = *addrP;
}
XP_ASSERT( addr_hasType( &addr, typ ) );
XP_ASSERT( !!comms->procs.send );
@ -1527,8 +1538,8 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem, const CommsConnType filter )
elem->sendCount );
}
CNO_FMT( cbuf1, elem->channelNo );
XP_LOGF( "%s(%s; msgID=" XP_LD ", len=%d)=>%d", __func__,
cbuf1, elem->msgID, elem->len, result );
XP_LOGFF( "(%s; msgID=" XP_LD ", len=%d)=>%d", cbuf1, elem->msgID,
elem->len, result );
XP_ASSERT( result < 0 || elem->len == result );
return result;
} /* sendMsg */
@ -2177,7 +2188,7 @@ validateInitialMessage( CommsCtxt* comms,
XP_LOGF( TAGFMT() "looking at %s", TAGPRMS, cbuf );
rec = getRecordFor( comms, addr, *channelNo, XP_TRUE );
if ( !!rec ) {
augmentChannelAddr( comms, rec, addr, senderID );
augmentChannelAddr( rec, addr, senderID );
/* reject: we've already seen init message on channel */
XP_LOGF( TAGFMT() "rejecting duplicate INIT message", TAGPRMS );
rec = NULL;
@ -2252,7 +2263,7 @@ validateChannelMessage( CommsCtxt* comms, const CommsAddrRec* addr,
if ( !!rec ) {
removeFromQueue( comms, channelNo, lastMsgRcd );
augmentChannelAddr( comms, rec, addr, senderID );
augmentChannelAddr( rec, addr, senderID );
if ( msgID == rec->lastMsgRcd + 1 ) {
XP_LOGF( TAGFMT() "expected %d AND got %d", TAGPRMS,
@ -2289,10 +2300,10 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
if ( comms_getAddrDisabled( comms, addrType, XP_FALSE ) ) {
XP_LOGF( "%s: dropping message because %s disabled", __func__,
ConnType2Str( addrType ) );
} else if (0 == (comms->addr._conTypes & retAddr->_conTypes)) {
/* we don't expect messages with that address type; drop it */
XP_LOGF( "%s: not expecting %s messages", __func__,
ConnType2Str( addrType ) );
/* } else if (0 == (comms->addr._conTypes & retAddr->_conTypes)) { */
/* /\* we don't expect messages with that address type; drop it *\/ */
/* XP_LOGF( "%s: not expecting %s messages", __func__, */
/* ConnType2Str( addrType ) ); */
} else {
XWHostID senderID = 0; /* unset; default for non-relay cases */
XP_Bool usingRelay = XP_FALSE;
@ -2808,59 +2819,57 @@ logAddrs( const CommsCtxt* comms, const char* caller )
#endif
static void
augmentChannelAddr( CommsCtxt* XP_UNUSED_DBG(comms), AddressRecord * const rec,
const CommsAddrRec* addr, XWHostID hostID )
augmentChannelAddr( AddressRecord * const rec, const CommsAddrRec* addr,
XWHostID hostID )
{
if ( !!addr ) {
XP_Bool augmented = XP_FALSE;
augmentAddr( &rec->addr, addr );
if ( addr_hasType( &rec->addr, COMMS_CONN_RELAY ) ) {
if ( 0 != hostID ) {
rec->rr.hostID = hostID;
XP_LOGF( "%s: set hostID for rec %p to %d", __func__, rec, hostID );
}
}
}
static void
augmentAddr( CommsAddrRec* destAddr, const CommsAddrRec* srcAddr )
{
if ( !!srcAddr ) {
CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( addr, &typ, &st ); ) {
if ( ! addr_hasType( &rec->addr, typ ) ) {
CNO_FMT( cbuf, rec->channelNo );
XP_LOGF( "%s: adding type %s to rec %p with %s", __func__,
ConnType2Str(typ), rec, cbuf );
}
if ( ! addr_hasType( &rec->addr, typ ) ) {
augmented = XP_TRUE;
logAddr( comms, &rec->addr, __func__ );
logAddr( comms, addr, __func__ );
addr_addType( &rec->addr, typ );
for ( XP_U32 st = 0; addr_iter( srcAddr, &typ, &st ); ) {
if ( ! addr_hasType( destAddr, typ ) ) {
XP_LOGFF( "adding new type %s to rec", ConnType2Str(typ) );
addr_addType( destAddr, typ );
}
const void* src = NULL;
void* dest = NULL;
XP_U32 siz;
size_t siz;
switch( typ ) {
case COMMS_CONN_RELAY:
dest = &rec->addr.u.ip_relay;
src = &addr->u.ip_relay;
siz = sizeof( rec->addr.u.ip_relay );
if ( 0 != hostID ) {
rec->rr.hostID = hostID;
XP_LOGF( "%s: set hostID for rec %p to %d", __func__, rec, hostID );
}
dest = &destAddr->u.ip_relay;
src = &srcAddr->u.ip_relay;
siz = sizeof( destAddr->u.ip_relay );
break;
case COMMS_CONN_SMS:
XP_ASSERT( 0 != addr->u.sms.port );
XP_ASSERT( '\0' != addr->u.sms.phone[0] );
dest = &rec->addr.u.sms;
src = &addr->u.sms;
siz = sizeof(rec->addr.u.sms);
XP_ASSERT( 0 != srcAddr->u.sms.port );
XP_ASSERT( '\0' != srcAddr->u.sms.phone[0] );
dest = &destAddr->u.sms;
src = &srcAddr->u.sms;
siz = sizeof(destAddr->u.sms);
break;
case COMMS_CONN_P2P:
XP_ASSERT( '\0' != addr->u.p2p.mac_addr[0] );
dest = &rec->addr.u.p2p;
src = &addr->u.p2p;
siz = sizeof(rec->addr.u.p2p);
XP_ASSERT( '\0' != srcAddr->u.p2p.mac_addr[0] );
dest = &destAddr->u.p2p;
src = &srcAddr->u.p2p;
siz = sizeof(destAddr->u.p2p);
break;
#ifdef XWFEATURE_BLUETOOTH
case COMMS_CONN_BT:
dest = &rec->addr.u.bt;
src = &addr->u.bt;
siz = sizeof(rec->addr.u.bt);
dest = &destAddr->u.bt;
src = &srcAddr->u.bt;
siz = sizeof(destAddr->u.bt);
break;
#endif
case COMMS_CONN_NFC:
@ -2871,15 +2880,11 @@ augmentChannelAddr( CommsCtxt* XP_UNUSED_DBG(comms), AddressRecord * const rec,
}
if ( !!dest ) {
if ( 0 != XP_MEMCMP( dest, src, siz ) ) {
XP_LOGF( "%s: actually changing addr info for typ %s",
__func__, ConnType2Str(typ) );
XP_LOGFF( "actually changing addr info for typ %s", ConnType2Str(typ) );
XP_MEMCPY( dest, src, siz );
}
}
}
if ( augmented ) {
logAddr( comms, &rec->addr, __func__ );
}
}
}

View file

@ -211,7 +211,7 @@ XP_Bool comms_checkAddr( DeviceRole role, const CommsAddrRec* addr,
XW_UtilCtxt* util );
void comms_getAddr( const CommsCtxt* comms, CommsAddrRec* addr );
void comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr );
void comms_augmentHostAddr( CommsCtxt* comms, const CommsAddrRec* addr );
void comms_getAddrs( const CommsCtxt* comms, CommsAddrRec addr[],
XP_U16* nRecs );
XP_Bool comms_formatRelayID( const CommsCtxt* comms, XP_U16 indx,

View file

@ -309,7 +309,7 @@ typedef struct _PlayerDicts {
#endif
#define LOG_FUNC() XP_LOGF( "IN: %s", __func__ )
#define LOG_FUNC() XP_LOGFF( "%s", "IN" )
#define LOG_RETURNF(fmt, ...) XP_LOGF( "%s => " fmt, __func__, __VA_ARGS__ )
#define LOG_RETURN_VOID() LOG_RETURNF("%s","void")
#define XP_LOGLOC() XP_LOGF( "%s(), line %d", __func__, __LINE__ )

View file

@ -549,7 +549,9 @@ gi_setNPlayers( CurGameInfo* gi, XP_U16 nTotal, XP_U16 nHere )
}
if ( nHere != curLocal ) {
XP_ASSERT(0);
/* This will happen when a device has more than on player. Not sure I
handle that correctly, but don't assert for now. */
XP_LOGFF( "nHere: %d; curLocal: %d; a problem?", nHere, curLocal );
/* for ( XP_U16 ii = 0; ii < nTotal; ++ii ) { */
/* gi->players[ii].isLocal = ii < nHere; */
/* } */

View file

@ -942,9 +942,17 @@ model_undoLatestMoves( ModelCtxt* model, PoolContext* pool,
const XP_U16 assignCount = model->vol.gi->inDuplicateMode
? 1 : model->nPlayers;
if ( (0 <= moveSought && moveSought >= nStackEntries)
|| ( nStackEntries < nMovesSought )
|| ( nStackEntries <= assignCount ) ) {
if ( 0 <= moveSought && moveSought >= nStackEntries ) {
XP_LOGFF( "BAD: moveSought (%d) >= nStackEntries (%d)", moveSought,
nStackEntries );
success = XP_FALSE;
} else if ( nStackEntries < nMovesSought ) {
XP_LOGFF( "BAD: nStackEntries (%d) < nMovesSought (%d)", nStackEntries,
nMovesSought );
success = XP_FALSE;
} else if ( nStackEntries <= assignCount ) {
XP_LOGFF( "BAD: nStackEntries (%d) <= assignCount (%d)", nStackEntries,
assignCount );
success = XP_FALSE;
} else {
XP_U16 nMovesUndone = 0;

View file

@ -2657,7 +2657,7 @@ sendMoveTo( ServerCtxt* server, XP_U16 devIndex, XP_U16 turn,
XP_ASSERT( version == server->nv.streamVersion );
XP_U32 hash = model_getHash( server->vol.model );
#ifdef DEBUG_HASHING
XP_LOGF( "%s: adding hash %X", __func__, (unsigned int)hash );
XP_LOGFF( "adding hash %X", (unsigned int)hash );
#endif
stream_putU32( stream, hash );
}
@ -4028,6 +4028,8 @@ server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incoming )
established. */
XP_LOGF( "%s: somebody's registering!!!", __func__ );
accepted = handleRegistrationMsg( server, incoming );
} else {
XP_LOGFF( "%s", "WTF: I'm not a server!!" );
}
break;
case XWPROTO_CLIENT_SETUP:

View file

@ -543,7 +543,7 @@ static void
addMessage( SMSProto* state, const XP_UCHAR* fromPhone, int msgID, int indx,
int count, const XP_U8* data, XP_U16 len )
{
XP_LOGF( "phone=%s, msgID=%d, %d/%d", fromPhone, msgID, indx, count );
XP_LOGFF( "phone=%s, msgID=%d, %d/%d", fromPhone, msgID, indx, count );
XP_ASSERT( 0 < len );
MsgIDRec* msgIDRec;
for ( ; ; ) {
@ -648,7 +648,7 @@ savePartials( SMSProto* state )
XP_U16 newSize = stream_getSize( stream );
if ( state->lastStoredSize == 2 && newSize == 2 ) {
XP_LOGF( "%s(): not storing empty again", __func__ );
XP_LOGFF( "%s", "not storing empty again" );
} else {
dutil_storeStream( state->dutil, KEY_PARTIALS, stream );
state->lastStoredSize = newSize;
@ -700,7 +700,7 @@ completeMsgs( SMSProto* state, SMSMsgArray* arr, const XP_UCHAR* fromPhone,
MsgIDRec* rec = getMsgIDRec( state, fromPhone, msgID, XP_FALSE,
&fromPhoneIndex, &msgIDIndex);
if ( !rec ) {
XP_LOGF( "%s(): no rec for phone %s, msgID %d", __func__, fromPhone, msgID );
XP_LOGFF( "no rec for phone %s, msgID %d", fromPhone, msgID );
XP_ASSERT( 0 );
}
@ -734,8 +734,7 @@ completeMsgs( SMSProto* state, SMSMsgArray* arr, const XP_UCHAR* fromPhone,
if ( stream_gotBytes( stream, msg.data, len ) && port == wantPort ) {
arr = appendLocMsg( state, arr, &msg );
} else {
XP_LOGF( "%s(): expected port %d, got %d", __func__,
wantPort, port );
XP_LOGFF( "expected port %d, got %d", wantPort, port );
XP_FREEP( state->mpool, &msg.data );
}
}
@ -773,8 +772,7 @@ toNetMsgs( SMSProto* state, ToPhoneRec* rec, XP_Bool forceOld )
if ( last > ii ) {
int nMsgs = last - ii;
if ( nMsgs > 1 ) {
XP_LOGF( "%s(): combining %d through %d (%d msgs)", __func__, ii,
last - 1, nMsgs );
XP_LOGFF( "combining %d through %d (%d msgs)", ii, last - 1, nMsgs );
}
int len = 1 + sum + (nMsgs * 2); /* 1: len & msgID */
SMSMsgNet newMsg = { .len = len,

View file

@ -571,7 +571,7 @@ setupBoard( CursesBoardGlobals* bGlobals )
static CursesBoardGlobals*
initNoDraw( CursesBoardState* cbState, sqlite3_int64 rowid,
const CurGameInfo* gi, const CommsAddrRec* addr )
const CurGameInfo* gi, const CommsAddrRec* returnAddr )
{
LOG_FUNC();
CursesBoardGlobals* result = commonInit( cbState, rowid, gi );
@ -591,7 +591,7 @@ initNoDraw( CursesBoardState* cbState, sqlite3_int64 rowid,
cGlobals->cp.robotTradePct = params->robotTradePct;
#endif
if ( linuxOpenGame( cGlobals, &result->procs, addr ) ) {
if ( linuxOpenGame( cGlobals, &result->procs, returnAddr ) ) {
result = ref( result );
} else {
disposeBoard( result );
@ -619,7 +619,7 @@ enableDraw( CursesBoardGlobals* bGlobals, const cb_dims* dims )
static CursesBoardGlobals*
findOrOpen( CursesBoardState* cbState, sqlite3_int64 rowid,
const CurGameInfo* gi, const CommsAddrRec* addr )
const CurGameInfo* gi, const CommsAddrRec* returnAddr )
{
CursesBoardGlobals* result = NULL;
for ( GSList* iter = cbState->games;
@ -631,7 +631,7 @@ findOrOpen( CursesBoardState* cbState, sqlite3_int64 rowid,
}
if ( !result ) {
result = initNoDraw( cbState, rowid, gi, addr );
result = initNoDraw( cbState, rowid, gi, returnAddr );
if ( !!result ) {
setupBoard( result );
cbState->games = g_slist_append( cbState->games, result );
@ -1243,6 +1243,7 @@ handleInvite( void* closure, int XP_UNUSED(key) )
} else {
ca_inform( bGlobals->boardWin, "Cannot invite via relayID or by \"sms phone\"." );
}
LOG_RETURNF( "%s", "TRUE" );
return XP_TRUE;
}

View file

@ -1170,7 +1170,8 @@ inviteReceivedCurses( CursesAppGlobals* aGlobals, const NetLaunchInfo* invite,
figureDims( aGlobals, &dims );
cb_newFor( aGlobals->cbState, invite, returnAddr, &dims );
} else {
XP_LOGFF( "%s", "Not accepting duplicate invitation" );
XP_LOGFF( "Not accepting duplicate invitation (nRowIDs(gameID=%d) was %d",
invite->gameID, nRowIDs );
}
}

View file

@ -74,7 +74,7 @@ openGamesDB( const char* dbName )
const char* createValuesStr =
"CREATE TABLE pairs ( key TEXT UNIQUE,value TEXT )";
result = sqlite3_exec( pDb, createValuesStr, NULL, NULL, NULL );
XP_LOGF( "sqlite3_exec=>%d", result );
XP_LOGFF( "sqlite3_exec=>%d", result );
XP_USE( result );
return pDb;
@ -84,14 +84,14 @@ void
closeGamesDB( sqlite3* pDb )
{
sqlite3_close( pDb );
XP_LOGF( "%s finished", __func__ );
LOG_RETURN_VOID();
}
static sqlite3_int64
writeBlobColumnData( const XP_U8* data, gsize len, XP_U16 strVersion, sqlite3* pDb,
sqlite3_int64 curRow, const char* column )
{
XP_LOGF( "%s(col=%s)", __func__, column );
XP_LOGFF( "(col=%s)", column );
int result;
char buf[256];
char* query;
@ -114,14 +114,14 @@ writeBlobColumnData( const XP_U8* data, gsize len, XP_U16 strVersion, sqlite3* p
assertPrintResult( pDb, result, SQLITE_OK );
result = sqlite3_step( stmt );
if ( SQLITE_DONE != result ) {
XP_LOGF( "%s: sqlite3_step => %s", __func__, sqliteErr2str( result ) );
XP_LOGFF( "sqlite3_step => %s", sqliteErr2str( result ) );
XP_ASSERT(0);
}
XP_USE( result );
if ( newGame ) { /* new row; need to insert blob first */
curRow = sqlite3_last_insert_rowid( pDb );
XP_LOGF( "%s: new rowid: %lld", __func__, curRow );
XP_LOGFF( "new rowid: %lld", curRow );
}
sqlite3_blob* blob;
@ -173,7 +173,7 @@ writeToDB( XWStreamCtxt* stream, void* closure )
if ( newGame ) { /* new row; need to insert blob first */
cGlobals->rowid = selRow;
XP_LOGF( "%s(): new game at row %lld", __func__, selRow );
XP_LOGFF( "new game at row %lld", selRow );
} else {
assert( selRow == cGlobals->rowid );
}
@ -315,13 +315,13 @@ summarize( CommonGlobals* cGlobals )
gchar* query = g_strdup_printf( "UPDATE games SET %s WHERE rowid=%lld",
vals, cGlobals->rowid );
g_free( vals );
XP_LOGF( "query: %s", query );
XP_LOGFF( "query: %s", query );
sqlite3_stmt* stmt = NULL;
int result = sqlite3_prepare_v2( cGlobals->params->pDb, query, -1, &stmt, NULL );
assertPrintResult( cGlobals->params->pDb, result, SQLITE_OK );
result = sqlite3_step( stmt );
if ( SQLITE_DONE != result ) {
XP_LOGF( "sqlite3_step=>%s", sqliteErr2str( result ) );
XP_LOGFF( "sqlite3_step=>%s", sqliteErr2str( result ) );
XP_ASSERT( 0 );
}
sqlite3_finalize( stmt );
@ -351,7 +351,7 @@ listGames( sqlite3* pDb )
{
sqlite3_int64* data = g_malloc( sizeof( *data ) );
*data = sqlite3_column_int64( ppStmt, 0 );
XP_LOGF( "%s: got a row; id=%lld", __func__, *data );
XP_LOGFF( "got a row; id=%lld", *data );
list = g_slist_append( list, data );
}
break;
@ -538,6 +538,7 @@ loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
return loadBlobColumn( stream, pDb, rowid, "game" );
}
/* Used for rematch only. But do I need it? */
void
saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid )
{
@ -703,7 +704,7 @@ assertPrintResult( sqlite3* pDb, int XP_UNUSED_DBG(result), int expect )
int code = sqlite3_errcode( pDb );
XP_ASSERT( code == result ); /* do I need to pass it? */
if ( code != expect ) {
XP_LOGF( "sqlite3 error: %s", sqlite3_errmsg( pDb ) );
XP_LOGFF( "sqlite3 error: %s", sqlite3_errmsg( pDb ) );
XP_ASSERT(0);
}
}

View file

@ -665,7 +665,7 @@ on_board_window_shown( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
if ( loadInviteAddrs( stream, cGlobals->params->pDb, cGlobals->rowid ) ) {
CommsAddrRec addr = {0};
addrFromStream( &addr, stream );
comms_setAddr( cGlobals->game.comms, &addr );
comms_augmentHostAddr( cGlobals->game.comms, &addr );
XP_U16 nRecs = stream_getU8( stream );
XP_LOGF( "%s: got invite info: %d records", __func__, nRecs );
@ -818,30 +818,12 @@ new_game_impl( GtkGameGlobals* globals, XP_Bool fireConnDlg )
#endif
};
if ( !game_reset( MEMPOOL &cGlobals->game, gi,
cGlobals->util,
&cGlobals->cp, &procs ) ) {
/* if ( NULL == globals->draw ) { */
/* globals->draw = (GtkDrawCtx*)gtkDrawCtxtMake( globals->drawing_area, */
/* globals ); */
/* } */
/* game_makeNewGame( MEMPOOL &globals->cGlobals.game, gi, */
/* globals->cGlobals.params->util, */
/* (DrawCtx*)globals->draw, */
/* &globals->cGlobals.cp, &procs, */
/* globals->cGlobals.params->gameSeed ); */
/* ModelCtxt* model = globals->cGlobals.game.model; */
/* if ( NULL == model_getDictionary( model ) ) { */
/* DictionaryCtxt* dict = */
/* linux_dictionary_make( MEMPOOL globals->cGlobals.params, */
/* gi->dictName, XP_TRUE ); */
/* model_setDictionary( model, dict ); */
/* } */
}
(void)game_reset( MEMPOOL &cGlobals->game, gi, cGlobals->util,
&cGlobals->cp, &procs );
#ifndef XWFEATURE_STANDALONE_ONLY
if ( !!cGlobals->game.comms ) {
comms_setAddr( cGlobals->game.comms, &addr );
comms_augmentHostAddr( cGlobals->game.comms, &addr );
} else if ( gi->serverRole != SERVER_STANDALONE ) {
XP_ASSERT(0);
}

View file

@ -1,6 +1,6 @@
/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
/*
* Copyright 2000 - 2011 by Eric House (xwords@eehouse.org). All rights
* Copyright 2000 - 2020 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
@ -179,7 +179,7 @@ canMakeFromGI( const CurGameInfo* gi )
bool
linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
const CommsAddrRec* addrP )
const CommsAddrRec* returnAddrP )
{
LOG_FUNC();
XWStreamCtxt* stream = NULL;
@ -207,6 +207,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
if ( !!stream ) {
if ( NULL == cGlobals->dict ) {
cGlobals->dict = makeDictForStream( cGlobals, stream );
XP_ASSERT( !!cGlobals->dict );
}
opened = game_makeFromStream( MEMPOOL stream, &cGlobals->game,
@ -221,13 +222,6 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
if ( !opened /* && canMakeFromGI( cGlobals->gi )*/ ) {
opened = XP_TRUE;
#ifdef XWFEATURE_RELAY
/* if ( addr.conType == COMMS_CONN_RELAY ) { */
/* XP_ASSERT( !!params->connInfo.relay.relayName ); */
/* globals->cGlobals.defaultServerName */
/* = params->connInfo.relay.relayName; */
/* } */
#endif
game_makeNewGame( MEMPOOL &cGlobals->game, cGlobals->gi,
cGlobals->util, cGlobals->draw,
&cGlobals->cp, procs
@ -236,70 +230,98 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
#endif
);
CommsAddrRec addr = !!addrP ? *addrP : cGlobals->addr;
// addr.conType = params->conType;
CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) {
if ( params->commsDisableds[typ][0] ) {
comms_setAddrDisabled( cGlobals->game.comms, typ, XP_FALSE, XP_TRUE );
}
if ( params->commsDisableds[typ][1] ) {
comms_setAddrDisabled( cGlobals->game.comms, typ, XP_TRUE, XP_TRUE );
}
switch( typ ) {
bool savedGame = false;
CommsAddrRec returnAddr = {0};
if ( !!returnAddrP ) {
returnAddr = *returnAddrP;
CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( &returnAddr, &typ, &st ); ) {
if ( params->commsDisableds[typ][0] ) {
comms_setAddrDisabled( cGlobals->game.comms, typ, XP_FALSE, XP_TRUE );
}
if ( params->commsDisableds[typ][1] ) {
comms_setAddrDisabled( cGlobals->game.comms, typ, XP_TRUE, XP_TRUE );
}
switch( typ ) {
#ifdef XWFEATURE_RELAY
case 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 ); */
break;
case 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 ); */
break;
#endif
#ifdef XWFEATURE_BLUETOOTH
case COMMS_CONN_BT:
XP_ASSERT( sizeof(addr.u.bt.btAddr)
>= sizeof(params->connInfo.bt.hostAddr));
XP_MEMCPY( &addr.u.bt.btAddr, &params->connInfo.bt.hostAddr,
sizeof(params->connInfo.bt.hostAddr) );
break;
case COMMS_CONN_BT:
XP_ASSERT( sizeof(returnAddr.u.bt.btAddr)
>= sizeof(params->connInfo.bt.hostAddr));
XP_MEMCPY( &returnAddr.u.bt.btAddr, &params->connInfo.bt.hostAddr,
sizeof(params->connInfo.bt.hostAddr) );
break;
#endif
#ifdef XWFEATURE_IP_DIRECT
case COMMS_CONN_IP_DIRECT:
XP_STRNCPY( addr.u.ip.hostName_ip, params->connInfo.ip.hostName,
sizeof(addr.u.ip.hostName_ip) - 1 );
addr.u.ip.port_ip = params->connInfo.ip.port;
break;
case COMMS_CONN_IP_DIRECT:
XP_STRNCPY( returnAddr.u.ip.hostName_ip, params->connInfo.ip.hostName,
sizeof(addr.u.ip.hostName_ip) - 1 );
returnAddr.u.ip.port_ip = params->connInfo.ip.port;
break;
#endif
#ifdef XWFEATURE_SMS
case COMMS_CONN_SMS:
XP_LOGF( "%s(): SMS is on at least", __func__ );
/* No! Don't overwrite what may be a return address with local
stuff */
/* XP_STRNCPY( addr.u.sms.phone, params->connInfo.sms.phone, */
/* sizeof(addr.u.sms.phone) - 1 ); */
/* addr.u.sms.port = params->connInfo.sms.port; */
break;
case COMMS_CONN_SMS:
XP_LOGF( "%s(): SMS is on at least", __func__ );
/* No! Don't overwrite what may be a return address with local
stuff */
/* XP_STRNCPY( addr.u.sms.phone, params->connInfo.sms.phone, */
/* sizeof(addr.u.sms.phone) - 1 ); */
/* addr.u.sms.port = params->connInfo.sms.port; */
break;
#endif
default:
break;
default:
break;
}
}
}
XP_ASSERT( !!cGlobals->dict );
model_setDictionary( cGlobals->game.model, cGlobals->dict );
setSquareBonuses( cGlobals );
model_setPlayerDicts( cGlobals->game.model, &cGlobals->dicts );
/* Need to save in order to have a valid selRow for the first send */
linuxSaveGame( cGlobals );
savedGame = true;
#ifndef XWFEATURE_STANDALONE_ONLY
/* This may trigger network activity */
if ( !!cGlobals->game.comms ) {
comms_setAddr( cGlobals->game.comms, &addr );
/* If this is to be a relay connected game, tell it so. Otherwise
let the invitation process and receipt of messages populate
comms' addressbook */
if ( cGlobals->gi->serverRole != SERVER_STANDALONE
&& addr_hasType( &params->addr, COMMS_CONN_RELAY ) ) {
if ( ! savedGame ) {
linuxSaveGame( cGlobals );
savedGame = true;
}
CommsAddrRec addr = {0};
comms_getInitialAddr( &addr, params->connInfo.relay.relayName,
params->connInfo.relay.defaultSendPort );
XP_MEMCPY( addr.u.ip_relay.invite, params->connInfo.relay.invite,
1 + XP_STRLEN(params->connInfo.relay.invite) );
addr.u.ip_relay.seeksPublicRoom = params->connInfo.relay.seeksPublicRoom;
addr.u.ip_relay.advertiseRoom = params->connInfo.relay.advertiseRoom;
comms_augmentHostAddr( cGlobals->game.comms, &addr ); /* sends stuff */
}
if ( !!returnAddrP ) {
/* This may trigger network activity */
CommsCtxt* comms = cGlobals->game.comms;
if ( !!comms ) {
comms_augmentHostAddr( cGlobals->game.comms, &returnAddr );
}
}
#endif
@ -317,7 +339,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
#ifndef XWFEATURE_STANDALONE_ONLY
DeviceRole serverRole = cGlobals->gi->serverRole;
XP_LOGF( "%s(): server role: %d", __func__, serverRole );
if ( serverRole == SERVER_ISCLIENT ) {
if ( /*!!returnAddrP && */serverRole == SERVER_ISCLIENT ) {
tryConnectToServer( cGlobals );
}
#endif
@ -331,7 +353,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs,
linuxSaveGame( cGlobals ); /* again, to include address etc. */
}
return opened;
}
} /* linuxOpenGame */
#ifdef USE_SQLITE
XWStreamCtxt*
@ -1491,7 +1513,7 @@ linux_reset( void* closure )
#endif
XP_S16
linux_send( const XP_U8* buf, XP_U16 buflen, const XP_UCHAR* XP_UNUSED_DBG(msgNo),
linux_send( const XP_U8* buf, XP_U16 buflen, const XP_UCHAR* msgNo,
const CommsAddrRec* addrRec, CommsConnType conType, XP_U32 gameID,
void* closure )
{

View file

@ -425,25 +425,23 @@ class Device():
# fi
# }
def makeSMSPhoneNo( game, dev ):
return '{:03d}{:03d}'.format( game, dev )
def build_cmds(args):
devs = []
COUNTER = 0
PLAT_PARMS = []
if not args.USE_GTK:
PLAT_PARMS += ['--curses']
for GAME in range(1, args.NGAMES + 1):
peers = set()
ROOM = 'ROOM_%.3d' % (GAME % args.NROOMS)
PHONE_BASE = '%.4d' % (GAME % args.NROOMS)
NDEVS = pick_ndevs(args)
LOCALS = figure_locals(args, NDEVS) # as array
NPLAYERS = sum(LOCALS)
assert(len(LOCALS) == NDEVS)
DICT = args.DICTS[GAME % len(args.DICTS)]
# make one in three games public
usePublic = random.randint(0, 3) == 0
usePublic = args.ADD_RELAY and random.randint(0, 3) == 0
useDupeMode = random.randint(0, 100) < args.DUP_PCT
DEV = 0
for NLOCALS in LOCALS:
@ -453,7 +451,7 @@ def build_cmds(args):
SCRIPT = '{}/start_{:02d}_{:02d}.sh'.format(args.LOGDIR, GAME, DEV)
PARAMS = player_params(args, NLOCALS, NPLAYERS, DEV)
PARAMS += PLAT_PARMS
if not args.USE_GTK: PARAMS += ['--curses']
PARAMS += ['--board-size', '15', '--trade-pct', args.TRADE_PCT, '--sort-tiles']
# We SHOULD support having both SMS and relay working...
@ -462,13 +460,13 @@ def build_cmds(args):
if random.randint(0, 100) < g_UDP_PCT_START:
PARAMS += ['--use-udp']
if args.ADD_SMS:
PARAMS += [ '--sms-number', PHONE_BASE + str(DEV - 1) ]
PARAMS += [ '--sms-number', makeSMSPhoneNo(GAME, DEV) ]
if args.SMS_FAIL_PCT > 0:
PARAMS += [ '--sms-fail-pct', args.SMS_FAIL_PCT ]
if DEV == 1:
PARAMS += [ '--force-invite' ]
for dev in range(2, NDEVS + 1):
PARAMS += [ '--invitee-sms-number', PHONE_BASE + str(dev - 1) ]
PARAMS += [ '--invitee-sms-number', makeSMSPhoneNo(GAME, dev) ]
if args.UNDO_PCT > 0:
PARAMS += ['--undo-pct', args.UNDO_PCT]