From 0486b956c86db8f33721b55e0af7381536959645 Mon Sep 17 00:00:00 2001 From: katianderic Date: Fri, 21 Feb 2020 17:18:52 +0100 Subject: [PATCH] better display of "sms" message passing --- xwords4/common/smsproto.c | 4 ++-- xwords4/linux/linuxmain.c | 2 +- xwords4/linux/linuxsms.c | 30 ++++++++++++++---------- xwords4/linux/linuxsms.h | 4 ++-- xwords4/linux/scripts/show_sms_inplay.sh | 10 +++++++- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/xwords4/common/smsproto.c b/xwords4/common/smsproto.c index d1f3e5598..904dbcb1a 100644 --- a/xwords4/common/smsproto.c +++ b/xwords4/common/smsproto.c @@ -478,8 +478,8 @@ addToOutRec( SMSProto* state, ToPhoneRec* rec, SMS_CMD cmd, rec->msgs = XP_REALLOC( state->mpool, rec->msgs, (1 + rec->nMsgs) * sizeof(*rec->msgs) ); rec->msgs[rec->nMsgs++] = mRec; rec->totalSize += len; - XP_LOGF( "%s(): added msg to %s of len %d; total now %d", __func__, rec->phone, - len, rec->totalSize ); + XP_LOGFF( "added msg to %s of len %d; total now %d", rec->phone, len, + rec->totalSize ); if ( rec->nMsgs == 1 ) { rec->createSeconds = nowSeconds; diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 253dabf22..ce2be3778 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -1547,7 +1547,7 @@ linux_send( const XP_U8* buf, XP_U16 buflen, const XP_UCHAR* XP_UNUSED_DBG(msgNo // use serverphone if I'm a client, else hope one's provided (this is // a reply) - nSent = linux_sms_send( cGlobals->params, buf, buflen, + nSent = linux_sms_send( cGlobals->params, buf, buflen, msgNo, addrRec->u.sms.phone, addrRec->u.sms.port, gameID ); } diff --git a/xwords4/linux/linuxsms.c b/xwords4/linux/linuxsms.c index dda037f62..6053305a5 100644 --- a/xwords4/linux/linuxsms.c +++ b/xwords4/linux/linuxsms.c @@ -71,7 +71,7 @@ typedef struct _LinSMSData { static gboolean retrySend( gpointer data ); static void sendOrRetry( LaunchParams* params, SMSMsgArray* arr, SMS_CMD cmd, XP_U16 waitSecs, const XP_UCHAR* phone, XP_U16 port, - XP_U32 gameID ); + XP_U32 gameID, const XP_UCHAR* msgNo ); static gint check_for_files( gpointer data ); static gint check_for_files_once( gpointer data ); @@ -107,7 +107,7 @@ unlock_queue( LinSMSData* storage ) static XP_S16 write_fake_sms( LaunchParams* params, const void* buf, XP_U16 buflen, - const XP_UCHAR* phone, XP_U16 port ) + const XP_UCHAR* msgNo, const XP_UCHAR* phone, XP_U16 port ) { XP_S16 nSent; XP_U16 pct = XP_RANDOM() % 100; @@ -132,11 +132,14 @@ write_fake_sms( LaunchParams* params, const void* buf, XP_U16 buflen, formatQueuePath( phone, port, path, sizeof(path) ); /* Random-number-based name is fine, as we pick based on age. */ - int rint = makeRandomInt(); g_mkdir_with_parents( path, 0777 ); /* just in case */ int len = strlen( path ); - snprintf( &path[len], sizeof(path)-len, "/%u", rint ); - + int rint = makeRandomInt(); + if ( !!msgNo ) { + snprintf( &path[len], sizeof(path)-len, "/%s_%u", msgNo, rint ); + } else { + snprintf( &path[len], sizeof(path)-len, "/%u", rint ); + } XP_UCHAR sms[buflen*2]; /* more like (buflen*4/3) */ XP_U16 smslen = sizeof(sms); binToSms( sms, &smslen, buf, buflen ); @@ -293,20 +296,21 @@ linux_sms_invite( LaunchParams* params, const NetLaunchInfo* nli, = smsproto_prepOutbound( storage->protoState, INVITE, nli->gameID, nli, sizeof(*nli), toPhone, toPort, XP_FALSE, &waitSecs ); - sendOrRetry( params, arr, INVITE, waitSecs, toPhone, toPort, nli->gameID ); + sendOrRetry( params, arr, INVITE, waitSecs, toPhone, toPort, + nli->gameID, "invite" ); } XP_S16 linux_sms_send( LaunchParams* params, const XP_U8* buf, - XP_U16 buflen, const XP_UCHAR* phone, XP_U16 port, - XP_U32 gameID ) + XP_U16 buflen, const XP_UCHAR* msgNo, const XP_UCHAR* phone, + XP_U16 port, XP_U32 gameID ) { LinSMSData* storage = getStorage( params ); XP_U16 waitSecs; SMSMsgArray* arr = smsproto_prepOutbound( storage->protoState, DATA, gameID, buf, buflen, phone, port, XP_TRUE, &waitSecs ); - sendOrRetry( params, arr, DATA, waitSecs, phone, port, gameID ); + sendOrRetry( params, arr, DATA, waitSecs, phone, port, gameID, msgNo ); return buflen; } @@ -315,19 +319,20 @@ typedef struct _RetryClosure { SMS_CMD cmd; XP_U16 port; XP_U32 gameID; + XP_UCHAR msgNo[32]; XP_UCHAR phone[32]; } RetryClosure; static void sendOrRetry( LaunchParams* params, SMSMsgArray* arr, SMS_CMD cmd, XP_U16 waitSecs, const XP_UCHAR* phone, XP_U16 port, - XP_U32 gameID ) + XP_U32 gameID, const XP_UCHAR* msgNo ) { if ( !!arr ) { for ( XP_U16 ii = 0; ii < arr->nMsgs; ++ii ) { const SMSMsgNet* msg = &arr->u.msgsNet[ii]; // doSend( params, msg->data, msg->len, phone, port, gameID ); - (void)write_fake_sms( params, msg->data, msg->len, + (void)write_fake_sms( params, msg->data, msg->len, msgNo, phone, port ); } @@ -338,6 +343,7 @@ sendOrRetry( LaunchParams* params, SMSMsgArray* arr, SMS_CMD cmd, sizeof(*closure) ); closure->params = params; XP_STRCAT( closure->phone, phone ); + XP_STRCAT( closure->msgNo, msgNo ); closure->port = port; closure->gameID = gameID; closure->cmd = cmd; @@ -356,7 +362,7 @@ retrySend( gpointer data ) closure->phone, closure->port, XP_TRUE, &waitSecs ); sendOrRetry( closure->params, arr, closure->cmd, waitSecs, closure->phone, - closure->port, closure->gameID ); + closure->port, closure->gameID, closure->msgNo ); XP_FREEP( closure->params->mpool, &closure ); return FALSE; } diff --git a/xwords4/linux/linuxsms.h b/xwords4/linux/linuxsms.h index fffc41c94..f251415d7 100644 --- a/xwords4/linux/linuxsms.h +++ b/xwords4/linux/linuxsms.h @@ -39,8 +39,8 @@ typedef struct _SMSProcs { void linux_sms_init( LaunchParams* params, const gchar* phone, XP_U16 port, const SMSProcs* procs, void* procClosure ); -XP_S16 linux_sms_send( LaunchParams* params, const XP_U8* buf, - XP_U16 buflen, const XP_UCHAR* phone, XP_U16 port, +XP_S16 linux_sms_send( LaunchParams* params, const XP_U8* buf, XP_U16 buflen, + const XP_UCHAR* msgNo, const XP_UCHAR* phone, XP_U16 port, XP_U32 gameID ); void linux_sms_invite( LaunchParams* params, const NetLaunchInfo* nli, const gchar* phone, int port ); diff --git a/xwords4/linux/scripts/show_sms_inplay.sh b/xwords4/linux/scripts/show_sms_inplay.sh index 2ea70f56b..81a99407f 100755 --- a/xwords4/linux/scripts/show_sms_inplay.sh +++ b/xwords4/linux/scripts/show_sms_inplay.sh @@ -1,3 +1,11 @@ #!/bin/sh -ls -l /tmp/xw_sms +for MSG in $(find /tmp/xw_sms/ -type f); do + NOLOCK=$(echo $MSG | sed 's,.lock,,') + if [ $NOLOCK = $MSG ]; then + basename $(dirname "$MSG") + echo -n "${MSG}: " + head -n 1 $MSG + fi +done +# ls -l /tmp/xw_sms/*