invitations work on linux

This commit is contained in:
Eric House 2022-12-20 09:20:02 -08:00
parent 233a9c465d
commit 6b029d5a85
3 changed files with 41 additions and 19 deletions

View file

@ -330,12 +330,33 @@ addProto3HeaderCmd( XW_DUtilCtxt* dutil, XWEnv xwe, MQTTCmd cmd,
#endif
void
dvc_makeMQTTInvite( XW_DUtilCtxt* dutil, XWEnv xwe, XWStreamCtxt* stream,
const NetLaunchInfo* nli, XP_U32 timestamp )
dvc_makeMQTTInvites( XW_DUtilCtxt* dutil, XWEnv xwe,
MsgAndTopicProc proc, void* closure,
const MQTTDevID* addressee,
const NetLaunchInfo* nli,
XP_U32 timestamp )
{
XP_UCHAR devTopic[64]; /* used by two below */
formatMQTTDevTopic( addressee, devTopic, VSIZE(devTopic) );
/* Stream format is identical for both topics */
XWStreamCtxt* stream = mkStream( dutil );
addHeaderGameIDAndCmd( dutil, xwe, CMD_INVITE, nli->gameID,
timestamp, stream );
nli_saveToStream( nli, stream );
#ifdef MQTT_DEV_TOPICS
(*proc)( closure, devTopic, stream );
#endif
#ifdef MQTT_GAMEID_TOPICS
XP_UCHAR gameTopic[64];
size_t siz = XP_SNPRINTF( gameTopic, VSIZE(gameTopic),
"%s/%X", devTopic, nli->gameID );
XP_ASSERT( siz < VSIZE(gameTopic) );
(*proc)(closure, gameTopic, stream );
#endif
stream_destroy( stream, xwe );
}
/* Ship with == 1, but increase to test */

View file

@ -30,6 +30,9 @@ void dvc_store( XW_DUtilCtxt* dctxt, XWEnv xwe );
# define dvc_store(dctxt, xwe)
# endif
typedef void (*MsgAndTopicProc)( void* closure, const XP_UCHAR* topic,
XWStreamCtxt* msg );
void dvc_getMQTTDevID( XW_DUtilCtxt* dutil, XWEnv xwe, MQTTDevID* devID );
void dvc_resetMQTTDevID( XW_DUtilCtxt* dutil, XWEnv xwe );
void dvc_getMQTTSubTopics( XW_DUtilCtxt* dutil, XWEnv xwe,
@ -39,11 +42,12 @@ void dvc_getMQTTPubTopics( XW_DUtilCtxt* dutil, XWEnv xwe,
const MQTTDevID* devid, XP_U32 gameID,
XP_UCHAR* storage, XP_U16 storageLen,
XP_U16* nTopics, XP_UCHAR* topics[] );
void dvc_makeMQTTInvite( XW_DUtilCtxt* dutil, XWEnv xwe, XWStreamCtxt* stream,
const NetLaunchInfo* nli, XP_U32 timestamp );
void dvc_makeMQTTInvites( XW_DUtilCtxt* dutil, XWEnv xwe,
MsgAndTopicProc proc, void* closure,
const MQTTDevID* addressee,
const NetLaunchInfo* nli,
XP_U32 timestamp );
typedef void (*MsgAndTopicProc)( void* closure, const XP_UCHAR* topic,
XWStreamCtxt* msg );
void dvc_makeMQTTMessages( XW_DUtilCtxt* dutil, XWEnv xwe,
MsgAndTopicProc proc, void* closure,
const MQTTDevID* addressee,

View file

@ -308,6 +308,14 @@ mqttc_getDevIDStr( LaunchParams* params )
return storage->clientIDStr;
}
static void
msgAndTopicProc( void* closure, const XP_UCHAR* topic, XWStreamCtxt* stream )
{
MQTTConStorage* storage = (MQTTConStorage*)closure;
(void)postOne( storage, topic, stream );
}
void
mqttc_invite( LaunchParams* params, XP_U32 timestamp, const NetLaunchInfo* nli,
const MQTTDevID* invitee )
@ -320,19 +328,8 @@ mqttc_invite( LaunchParams* params, XP_U32 timestamp, const NetLaunchInfo* nli,
#endif
XP_USE( timestamp );
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(params->mpool)
params->vtMgr );
dvc_makeMQTTInvite( params->dutil, NULL_XWE, stream, nli, 0 );
postMsg( storage, stream, nli->gameID, invitee );
}
static void
msgAndTopicProc( void* closure, const XP_UCHAR* topic, XWStreamCtxt* stream )
{
MQTTConStorage* storage = (MQTTConStorage*)closure;
(void)postOne( storage, topic, stream );
dvc_makeMQTTInvites( params->dutil, NULL_XWE, msgAndTopicProc, storage,
invitee, nli, 0 );
}
XP_S16