send/handle all invitations at once

I'm trying to reproduce with initial invitations the stalls I'm seeing
with rematches (rarely)
This commit is contained in:
Eric House 2024-01-04 20:28:49 -08:00
parent 8388b27002
commit 6018392160
5 changed files with 61 additions and 44 deletions

View file

@ -283,7 +283,9 @@ game_makeRematch( const XWGame* oldGame, XWEnv xwe, XW_UtilCtxt* newUtil,
}
server_disposeRematchInfo( oldGame->server, &rip );
}
LOG_RETURNF( "%s", boolToStr(success) );
XP_LOGFF( "=> %s; game with gid %08X rematched to create game with gid %08X using ro %s",
boolToStr(success), oldGame->util->gameInfo->gameID,
newUtil->gameInfo->gameID, RO2Str(ro) );
return success;
}

View file

@ -689,8 +689,8 @@ cb_feedGame( CursesBoardState* cbState, XP_U32 gameID,
}
void
cb_addInvite( CursesBoardState* cbState, XP_U32 gameID, XP_U16 forceChannel,
const CommsAddrRec* destAddr )
cb_addInvites( CursesBoardState* cbState, XP_U32 gameID, XP_U16 nRemotes,
XP_U16 forceChannels[], const CommsAddrRec destAddrs[] )
{
CursesBoardGlobals* bGlobals = findOrOpenForGameID( cbState, gameID, NULL, NULL );
CommonGlobals* cGlobals = &bGlobals->cGlobals;
@ -699,10 +699,12 @@ cb_addInvite( CursesBoardState* cbState, XP_U32 gameID, XP_U16 forceChannel,
CommsAddrRec selfAddr;
comms_getSelfAddr( comms, &selfAddr );
NetLaunchInfo nli;
nli_init( &nli, cGlobals->gi, &selfAddr, 1, forceChannel );
for ( int ii = 0; ii < nRemotes; ++ii ) {
NetLaunchInfo nli;
nli_init( &nli, cGlobals->gi, &selfAddr, 1, forceChannels[ii] );
comms_invite( comms, NULL_XWE, &nli, destAddr, XP_TRUE );
comms_invite( comms, NULL_XWE, &nli, &destAddrs[ii], XP_TRUE );
}
}
XP_Bool

View file

@ -51,8 +51,8 @@ bool cb_feedRow( CursesBoardState* cbState, sqlite3_int64 rowid,
const CommsAddrRec* from );
void cb_feedGame( CursesBoardState* cbState, XP_U32 gameID,
const XP_U8* buf, XP_U16 len, const CommsAddrRec* from );
void cb_addInvite( CursesBoardState* cbState, XP_U32 gameID, XP_U16 forceChannel,
const CommsAddrRec* destAddr );
void cb_addInvites( CursesBoardState* cbState, XP_U32 gameID, XP_U16 nRemotes,
XP_U16 forceChannels[], const CommsAddrRec destAddrs[] );
XP_Bool cb_makeRematch( CursesBoardState* cbState, XP_U32 gameID,
RematchOrder ro, XP_U32* newGameID );
XP_Bool cb_makeMoveIf( CursesBoardState* cbState, XP_U32 gameID );

View file

@ -1549,37 +1549,42 @@ makeGameFromArgs( CursesAppGlobals* aGlobals, cJSON* args )
static XP_Bool
inviteFromArgs( CursesAppGlobals* aGlobals, cJSON* args )
{
/* char buf[1000]; */
/* if ( cJSON_PrintPreallocated( args, buf, sizeof(buf), 0 ) ) { */
/* XP_LOGFF( "(%s)", buf ); */
/* } */
XP_U32 gameID = gidFromObject( args );
cJSON* tmp = cJSON_GetObjectItem( args, "channel" );
XP_ASSERT( !!tmp );
XP_U16 channel = tmp->valueint;
XP_LOGFF( "read channel: %X", channel );
cJSON* remotes = cJSON_GetObjectItem( args, "remotes" );
int nRemotes = cJSON_GetArraySize(remotes);
CommsAddrRec destAddrs[nRemotes];
XP_MEMSET( destAddrs, 0, sizeof(destAddrs) );
XP_U16 channels[nRemotes];
XP_MEMSET( channels, 0, sizeof(channels) );
CommsAddrRec destAddr = {0};
cJSON* addr = cJSON_GetObjectItem( args, "addr" );
XP_ASSERT( !!addr );
tmp = cJSON_GetObjectItem( addr, "mqtt" );
if ( !!tmp ) {
XP_LOGFF( "parsing mqtt: %s", tmp->valuestring );
addr_addType( &destAddr, COMMS_CONN_MQTT );
XP_Bool success = strToMQTTCDevID( tmp->valuestring, &destAddr.u.mqtt.devID );
XP_ASSERT( success );
}
tmp = cJSON_GetObjectItem( addr, "sms" );
if ( !!tmp ) {
XP_LOGFF( "parsing sms: %s", tmp->valuestring );
addr_addType( &destAddr, COMMS_CONN_SMS );
XP_STRCAT( destAddr.u.sms.phone, tmp->valuestring );
destAddr.u.sms.port = 1;
for ( int ii = 0; ii < nRemotes; ++ii ) {
cJSON* item = cJSON_GetArrayItem( remotes, ii );
cJSON* tmp = cJSON_GetObjectItem( item, "channel" );
XP_ASSERT( !!tmp );
channels[ii] = tmp->valueint;
XP_LOGFF( "read channel: %X", channels[ii] );
cJSON* addr = cJSON_GetObjectItem( item, "addr" );
XP_ASSERT( !!addr );
tmp = cJSON_GetObjectItem( addr, "mqtt" );
if ( !!tmp ) {
XP_LOGFF( "parsing mqtt: %s", tmp->valuestring );
addr_addType( &destAddrs[ii], COMMS_CONN_MQTT );
XP_Bool success = strToMQTTCDevID( tmp->valuestring, &destAddrs[ii].u.mqtt.devID );
XP_ASSERT( success );
}
tmp = cJSON_GetObjectItem( addr, "sms" );
if ( !!tmp ) {
XP_LOGFF( "parsing sms: %s", tmp->valuestring );
addr_addType( &destAddrs[ii], COMMS_CONN_SMS );
XP_STRCAT( destAddrs[ii].u.sms.phone, tmp->valuestring );
destAddrs[ii].u.sms.port = 1;
}
}
cb_addInvite( aGlobals->cbState, gameID, channel, &destAddr );
cb_addInvites( aGlobals->cbState, gameID, nRemotes, channels, destAddrs );
LOG_RETURN_VOID();
return XP_TRUE;
}
@ -1725,6 +1730,7 @@ on_incoming_signal( GSocketService* XP_UNUSED(service),
XP_LOGFF( "called" );
CursesAppGlobals* aGlobals = (CursesAppGlobals*)user_data;
LaunchParams* params = aGlobals->cag.params;
XP_U32 startTime = dutil_getCurSeconds( params->dutil, NULL_XWE );
GInputStream* istream = g_io_stream_get_input_stream( G_IO_STREAM(connection) );
@ -1832,6 +1838,10 @@ on_incoming_signal( GSocketService* XP_UNUSED(service),
free( replyStr );
}
XP_U32 consumed = dutil_getCurSeconds( params->dutil, NULL_XWE ) - startTime;
if ( 0 < consumed ) {
XP_LOGFF( "took %d seconds", consumed );
}
LOG_RETURN_VOID();
return FALSE;
}

View file

@ -167,7 +167,7 @@ class GameStatus():
else:
arg3 = gameState.get('nTiles')
if arg3 > 0: GameStatus._tileCount += arg3
arg3 = 0 <= arg3 and '{: 3}'.format(arg3) or ' - '
arg3 = 0 <= arg3 and '{: 3}'.format(arg3) or '-'.rjust(3)
line = '{}{:3}{}'.format(hostMarker, initial, arg3)
results.append(line.center(len(gid)))
@ -199,7 +199,7 @@ class Device():
self.guestGames = []
self.script = '{}/{}.sh'.format(Device._logdir, host)
self.dbName = '{}/{}.db'.format(Device._logdir, host)
self.logfile = '{}/{}_logs.txt'.format(Device._logdir, host)
self.logfile = '{}/{}_log.txt'.format(Device._logdir, host)
self.cmdSocketName = '{}/{}.sock'.format(Device._logdir, host)
self._keyCur = 10000 * (1 + g_NAMES.index(host))
@ -359,21 +359,24 @@ class Device():
Device.getForPlayer(guest).expectInvite(newGid, rematchLevel)
def invite(self, game):
failed = False
remotes = []
guestDevs = []
for ii in reversed(range(len(game.guestNames))):
guestDev = Device.getForPlayer(game.guestNames[ii])
guestDevs.append(guestDev)
addr = {}
if self.args.WITH_MQTT: addr['mqtt'] = guestDev.mqttDevID
if self.args.WITH_SMS: addr['sms'] = guestDev.smsNumber
response = self._sendWaitReply('invite', gid=game.gid,
channel=ii+1, addr=addr)
remotes.append({'channel': ii+1, 'addr': addr})
if response['success']:
response = self._sendWaitReply('invite', gid=game.gid,
remotes=remotes)
if response['success']:
for guestDev in guestDevs:
guestDev.expectInvite(game.gid, game.rematchLevel)
else:
failed = True
if not failed: game.needsInvite = False
game.needsInvite = False
def expectInvite(self, gid, rematchLevel):
self.guestGames.append(GuestGameInfo(self, gid, rematchLevel))
@ -802,7 +805,7 @@ def initLogs():
shutil.move(logdir, '/tmp/{}_{}'.format(logdir, os.getpid()))
os.mkdir(logdir)
logfilepath = '{}/{}_log.txt'.format(logdir, scriptName)
logfilepath = '{}/{}_logs.txt'.format(logdir, scriptName)
global g_LOGFILE
g_LOGFILE = open(logfilepath, 'w')