pass and use mqttid in game-connection code

To avoid inviteless relay games not having an mqtt channel (and so
yielding a crappy experience) pass the mqtt devid when device registers
and when server replies with all-here.
This commit is contained in:
Eric House 2020-08-22 16:02:31 -07:00
parent bd53824d95
commit 0f61a6d9f4
4 changed files with 71 additions and 5 deletions

View file

@ -1028,6 +1028,29 @@ comms_augmentHostAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr )
}
} /* comms_setHostAddr */
void comms_addMQTTDevID( CommsCtxt* comms, XP_PlayerAddr channelNo,
const MQTTDevID* devID )
{
XP_LOGFF( "(devID: " MQTTDevID_FMT ")", *devID );
XP_Bool found = XP_FALSE;
for ( AddressRecord* rec = comms->recs; !!rec && !found; rec = rec->next ) {
found = rec->channelNo == channelNo;
if ( found ) {
if ( addr_hasType( &rec->addr, COMMS_CONN_MQTT ) ) {
XP_ASSERT( *devID == rec->addr.u.mqtt.devID );
}
CommsAddrRec addr = {0};
addr_setType( &addr, COMMS_CONN_MQTT );
addr.u.mqtt.devID = *devID;
augmentAddr( &rec->addr, &addr );
}
}
if ( !found ) {
XP_LOGFF( "unable to augment address!!" );
}
}
void
comms_getAddrs( const CommsCtxt* comms, XWEnv XP_UNUSED_DBG(xwe),
CommsAddrRec addr[], XP_U16* nRecs )

View file

@ -165,6 +165,9 @@ XP_Bool comms_checkAddr( XWEnv xwe, DeviceRole role, const CommsAddrRec* addr,
void comms_getAddr( const CommsCtxt* comms, CommsAddrRec* addr );
void comms_augmentHostAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr );
void comms_addMQTTDevID( CommsCtxt* comms, XP_PlayerAddr channelNo,
const MQTTDevID* devID );
void comms_getAddrs( const CommsCtxt* comms, XWEnv xwe,
CommsAddrRec addr[], XP_U16* nRecs );
XP_Bool comms_formatRelayID( const CommsCtxt* comms, XP_U16 indx,

View file

@ -30,6 +30,7 @@
#include "util.h"
#include "pool.h"
#include "engine.h"
#include "device.h"
#include "strutils.h"
#include "dbgutil.h"
@ -652,6 +653,41 @@ server_countTilesInPool( ServerCtxt* server )
#define NAME_LEN_NBITS 6
#define MAX_NAME_LEN ((1<<(NAME_LEN_NBITS-1))-1)
#ifndef XWFEATURE_STANDALONE_ONLY
/* addMQTTDevID() and readMQTTDevID() exist to work around the case where
folks start games using agreed-upon relay room names rather than
invitations. In that case the MQTT devID hasn't been transmitted and so
only old-style relay communication is possible. This hack sends the mqtt
devIDs in the same host->guest message that sets the gameID. Guests will
start using mqtt to transmit and in so doing transmit their own devIDs to
the host.
*/
static void
addMQTTDevID( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
{
MQTTDevID devID;
dvc_getMQTTDevID( server->vol.dutil, xwe, &devID );
XP_UCHAR buf[32];
formatMQTTDevID( &devID, buf, VSIZE(buf) );
stringToStream( stream, buf );
}
static void
readMQTTDevID( ServerCtxt* server, XWStreamCtxt* stream )
{
if ( 0 < stream_getSize( stream ) ) {
XP_UCHAR buf[32];
stringFromStreamHere( stream, buf, VSIZE(buf) );
MQTTDevID devID;
if ( strToMQTTCDevID( buf, &devID ) ) {
XP_PlayerAddr channelNo = stream_getAddress( stream );
comms_addMQTTDevID( server->vol.comms, channelNo, &devID );
}
}
}
XP_Bool
server_initClientConnection( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
{
@ -1824,7 +1860,8 @@ client_readInitialMessage( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
// XP_ASSERT( streamVersion <= CUR_STREAM_VERS ); /* else do what? */
gameID = stream_getU32( stream );
XP_LOGF( "read gameID of %x; calling comms_setConnID", gameID );
XP_LOGFF( "read gameID of %x/%d; calling comms_setConnID (replacing %d)",
gameID, gameID, server->vol.gi->gameID );
server->vol.gi->gameID = gameID;
comms_setConnID( server->vol.comms, gameID );
@ -1917,6 +1954,8 @@ client_readInitialMessage( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
sortTilesIf( server, ii );
}
readMQTTDevID( server, stream );
syncPlayers( server );
SETSTATE( server, XWSTATE_INTURN );
@ -2013,6 +2052,8 @@ sendInitialMessage( ServerCtxt* server, XWEnv xwe )
}
}
addMQTTDevID( server, xwe, stream );
stream_destroy( stream, xwe );
}

View file

@ -471,10 +471,9 @@ def build_cmds(args):
for dev in range(2, NDEVS + 1):
PARAMS += [ '--invitee-sms-number', makeSMSPhoneNo(GAME, dev) ]
if args.ADD_MQTT:
PARAMS += [ '--mqtt-port', args.MQTT_PORT, '--mqtt-host', args.MQTT_HOST ]
if DEV == 1:
PARAMS += [ '--force-invite' ]
PARAMS += [ '--mqtt-port', args.MQTT_PORT, '--mqtt-host', args.MQTT_HOST ]
if args.ADD_MQTT and DEV == 1:
PARAMS += [ '--force-invite' ]
if args.UNDO_PCT > 0:
PARAMS += ['--undo-pct', args.UNDO_PCT]