From dbde9c87aef3d81a6673463213b7e1b14463c0b8 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 30 Sep 2020 10:10:43 -0700 Subject: [PATCH] list known player in invite info where known (for mqtt only) --- .../java/org/eehouse/android/xw4/DBUtils.java | 9 ++++++++ .../org/eehouse/android/xw4/jni/XwJNI.java | 8 +++++++ xwords4/android/jni/xwjni.c | 14 +++++++++++++ xwords4/common/knownplyr.c | 21 +++++++++++++++++++ xwords4/common/knownplyr.h | 3 +++ 5 files changed, 55 insertions(+) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java index e98ecb1ab..f8889c19f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java @@ -603,6 +603,15 @@ public class DBUtils { msg = LocUtils.getString( context, R.string.invit_expl_relay_fmt, timestamp ); break; + case MQTT: + String player = XwJNI.kplr_nameForMqttDev( target ); + if ( null != player ) { + msg = LocUtils.getString( context, + R.string.invit_expl_player_fmt, + player, timestamp ); + break; + } + // else FALLTHRU default: msg = LocUtils.getString( context, R.string.invit_expl_notarget_fmt, means.toString(), timestamp ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java index 3a912c688..1630fb958 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java @@ -204,6 +204,13 @@ public class XwJNI { : null; } + public static String kplr_nameForMqttDev( String mqttID ) + { + return BuildConfig.HAVE_KNOWN_PLAYERS + ? kplr_nameForMqttDev( getJNI().m_ptrGlobals, mqttID ) + : null; + } + private static void cleanGlobals() { synchronized( XwJNI.class ) { // let's be safe here @@ -724,6 +731,7 @@ public class XwJNI { String newName ); private static native void kplr_deletePlayer( long jniState, String player ); private static native CommsAddrRec kplr_getAddr( long jniState, String name ); + public static native String kplr_nameForMqttDev( long jniState, String mqttID ); private static native void cleanGlobals( long jniState ); private static native byte[] gi_to_stream( long jniState, CurGameInfo gi ); diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index 7a67686c9..f21568f5e 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -833,6 +833,20 @@ Java_org_eehouse_android_xw4_jni_XwJNI_kplr_1getAddr DVC_HEADER_END(); return jaddr; } + +JNIEXPORT jstring JNICALL +Java_org_eehouse_android_xw4_jni_XwJNI_kplr_1nameForMqttDev +( JNIEnv* env, jclass C, jlong jniGlobalPtr, jstring jDevID ) +{ + jstring result = NULL; + DVC_HEADER(jniGlobalPtr); + const char* devid = (*env)->GetStringUTFChars( env, jDevID, NULL ); + const XP_UCHAR* name = kplr_nameForMqttDev( globalState->dutil, env, devid ); + result = (*env)->NewStringUTF( env, name ); + (*env)->ReleaseStringUTFChars( env, jDevID, devid ); + DVC_HEADER_END(); + return result; +} #endif JNIEXPORT jbyteArray JNICALL diff --git a/xwords4/common/knownplyr.c b/xwords4/common/knownplyr.c index a4d9fdbe7..536588b75 100644 --- a/xwords4/common/knownplyr.c +++ b/xwords4/common/knownplyr.c @@ -292,6 +292,27 @@ kplr_getAddr( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* name, return found; } +const XP_UCHAR* +kplr_nameForMqttDev( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* mqttDevID ) +{ + const XP_UCHAR* name = NULL; + MQTTDevID devID; + if ( strToMQTTCDevID( mqttDevID, &devID ) ) { + KPState* state = loadState( dutil, xwe ); + for ( KnownPlayer* kp = state->players; !!kp && !name; kp = kp->next ) { + const CommsAddrRec* addr = &kp->addr; + if ( addr_hasType( addr, COMMS_CONN_MQTT ) ) { + if ( 0 == XP_MEMCMP( &addr->u.mqtt.devID, &devID, sizeof(devID) ) ) { + name = kp->name; + } + } + } + releaseState( dutil, xwe, state ); + } + LOG_RETURNF( "%s", name ); + return name; +} + static void freeKP( XW_DUtilCtxt* dutil, KnownPlayer* kp ) { diff --git a/xwords4/common/knownplyr.h b/xwords4/common/knownplyr.h index a08797440..04aee7af9 100644 --- a/xwords4/common/knownplyr.h +++ b/xwords4/common/knownplyr.h @@ -43,6 +43,9 @@ void kplr_getNames( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR** players, XP_U16* nFound ); XP_Bool kplr_getAddr( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* name, CommsAddrRec* addr ); +const XP_UCHAR* kplr_nameForMqttDev( XW_DUtilCtxt* dutil, XWEnv xwe, + const XP_UCHAR* mqttDevID ); + KP_Rslt kplr_renamePlayer( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* oldName, const XP_UCHAR* newName ); KP_Rslt kplr_deletePlayer( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* name );