From 096c13614a0c0fa0989f5177a81b3c247f2f679a Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 18 Dec 2022 16:17:05 -0800 Subject: [PATCH] use ifdefs to go back to using only old-style per-device topics --- .../src/main/java/org/eehouse/android/xw4/MQTTUtils.java | 8 ++++++++ xwords4/common/device.c | 8 +++++++- xwords4/linux/Makefile | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java index 556d46d99..479d04461 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java @@ -583,6 +583,14 @@ public class MQTTUtils extends Thread MQTTUtils instance = getOrStart( context ); if ( null != instance ) { String[] topics = XwJNI.dvc_getMQTTPubTopics( addressee, gameID ); + if ( BuildConfig.NON_RELEASE ) { + for ( String topic : topics ) { + if ( !topic.startsWith("xw4/device/") ) { + Log.d( TAG, "bad topic: %s", topic ); + Assert.failDbg(); + } + } + } instance.enqueue( topics, packet ); } } diff --git a/xwords4/common/device.c b/xwords4/common/device.c index f2d10daa8..99ed199d7 100644 --- a/xwords4/common/device.c +++ b/xwords4/common/device.c @@ -209,9 +209,11 @@ dvc_getMQTTSubTopics( XW_DUtilCtxt* dutil, XWEnv xwe, formatMQTTDevTopic( &devid, buf, VSIZE(buf) ); topics[count++] = appendToStorage( storage, &offset, buf ); +#ifdef MQTT_GAMEID_TOPICS /* Then the pattern that includes gameIDs */ XP_SNPRINTF( buf, VSIZE(buf), "%s/+", topics[0] ); topics[count++] = appendToStorage( storage, &offset, buf ); +#endif /* Finally, the control pattern */ formatMQTTCtrlTopic( &devid, buf, VSIZE(buf) ); @@ -242,7 +244,6 @@ dvc_getMQTTPubTopics( XW_DUtilCtxt* dutil, XWEnv xwe, int offset = 0; int count = 0; - XP_UCHAR buf[128]; XP_UCHAR devTopic[64]; /* used by two below */ formatMQTTDevTopic( devid, devTopic, VSIZE(devTopic) ); @@ -250,9 +251,14 @@ dvc_getMQTTPubTopics( XW_DUtilCtxt* dutil, XWEnv xwe, /* device topic; eventually goes away; but invites? */ topics[count++] = appendToStorage( storage, &offset, devTopic ); +#ifdef MQTT_GAMEID_TOPICS + XP_UCHAR buf[128]; /* gameid topic */ XP_SNPRINTF( buf, VSIZE(buf), "%s/%X", devTopic, gameID ); topics[count++] = appendToStorage( storage, &offset, buf ); +#else + XP_USE(gameID); +#endif XP_ASSERT( offset < storageLen ); XP_ASSERT( count <= *nTopics ); diff --git a/xwords4/linux/Makefile b/xwords4/linux/Makefile index 00bc60621..eb2e35f8a 100644 --- a/xwords4/linux/Makefile +++ b/xwords4/linux/Makefile @@ -167,6 +167,8 @@ DEFINES += -DXWFEATURE_SLOW_ROBOT -DXWFEATURE_ROBOTPHONIES DEFINES += -DXWFEATURE_DEVICE DEFINES += -DXWFEATURE_KNOWNPLAYERS +# DEFINES += -DMQTT_GAMEID_TOPICS + # Support device-to-device connection via UDP, e.g. using wifi on a # LAN or where the host/server isn't behind a firewall. # DEFINES += -DXWFEATURE_IP_DIRECT