finish chat fix to not crash when old messages come in

This commit is contained in:
Eric House 2024-02-20 15:52:44 -08:00
parent d446d3d463
commit fbad300e48
6 changed files with 21 additions and 25 deletions

View file

@ -847,9 +847,10 @@ deleteLocalRefs( JNIEnv* env, ... )
jobject jnext = va_arg( ap, jobject ); jobject jnext = va_arg( ap, jobject );
if ( DELETE_NO_REF == jnext ) { if ( DELETE_NO_REF == jnext ) {
break; break;
} } else if ( !!jnext ) {
deleteLocalRef( env, jnext ); deleteLocalRef( env, jnext );
} }
}
va_end( ap ); va_end( ap );
} }

View file

@ -575,17 +575,14 @@ and_util_notifyIllegalWords( XW_UtilCtxt* uc, XWEnv xwe, BadWordInfo* bwi,
#ifdef XWFEATURE_CHAT #ifdef XWFEATURE_CHAT
static void static void
and_util_showChat( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* msg, XP_S16 from, XP_U32 timestamp ) and_util_showChat( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* msg,
const XP_UCHAR* from, XP_U32 timestamp )
{ {
UTIL_CBK_HEADER( "showChat", "(Ljava/lang/String;ILjava/lang/String;I)V" ); UTIL_CBK_HEADER( "showChat", "(Ljava/lang/String;ILjava/lang/String;I)V" );
jstring jname = NULL;
if ( 0 <= from ) {
LocalPlayer* lp = &uc->gameInfo->players[from];
XP_ASSERT( !lp->isLocal );
jname = (*env)->NewStringUTF( env, lp->name );
}
jstring jname = !!from ? (*env)->NewStringUTF( env, from ) : NULL;
jstring jmsg = (*env)->NewStringUTF( env, msg ); jstring jmsg = (*env)->NewStringUTF( env, msg );
(*env)->CallVoidMethod( env, util->jutil, mid, jmsg, from, jname, timestamp ); (*env)->CallVoidMethod( env, util->jutil, mid, jmsg, from, jname, timestamp );
deleteLocalRefs( env, jmsg, jname, DELETE_NO_REF ); deleteLocalRefs( env, jmsg, jname, DELETE_NO_REF );
UTIL_CBK_TAIL(); UTIL_CBK_TAIL();

View file

@ -1106,7 +1106,9 @@ receiveChat( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* incoming )
XP_S16 from = -1; XP_S16 from = -1;
if ( 1 <= stream_getSize( incoming ) ) { if ( 1 <= stream_getSize( incoming ) ) {
from = stream_getU8( incoming ); from = stream_getU8( incoming );
XP_ASSERT( !server->vol.gi->players[from].isLocal ); if ( server->vol.gi->players[from].isLocal ) {
from = -1;
}
} }
XP_U32 timestamp = sizeof(timestamp) <= stream_getSize( incoming ) XP_U32 timestamp = sizeof(timestamp) <= stream_getSize( incoming )
@ -1116,7 +1118,11 @@ receiveChat( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* incoming )
sendChatToClientsExcept( server, xwe, sourceClientIndex, msg, from, sendChatToClientsExcept( server, xwe, sourceClientIndex, msg, from,
timestamp ); timestamp );
} }
util_showChat( server->vol.util, xwe, msg, from, timestamp ); const XP_UCHAR* sender = NULL;
if ( 0 <= from ) {
sender = server->vol.gi->players[from].name;
}
util_showChat( server->vol.util, xwe, msg, sender, timestamp );
XP_FREE( server->mpool, msg ); XP_FREE( server->mpool, msg );
return XP_TRUE; return XP_TRUE;
} }

View file

@ -186,7 +186,7 @@ typedef struct UtilVtable {
#ifdef XWFEATURE_CHAT #ifdef XWFEATURE_CHAT
void (*m_util_showChat)( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* const msg, void (*m_util_showChat)( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* const msg,
XP_S16 from, XP_U32 timestamp ); const XP_UCHAR* from, XP_U32 timestamp );
#endif #endif
#ifdef SHOW_PROGRESS #ifdef SHOW_PROGRESS

View file

@ -1251,17 +1251,13 @@ curses_util_informWordsBlocked( XW_UtilCtxt* XP_UNUSED(uc), XWEnv XP_UNUSED(xwe)
static void static void
curses_util_showChat( XW_UtilCtxt* uc, XWEnv XP_UNUSED(xwe), curses_util_showChat( XW_UtilCtxt* uc, XWEnv XP_UNUSED(xwe),
const XP_UCHAR* const XP_UNUSED_DBG(msg), const XP_UCHAR* const XP_UNUSED_DBG(msg),
XP_S16 XP_UNUSED_DBG(from), XP_U32 XP_UNUSED(timestamp) ) const XP_UCHAR* const XP_UNUSED_DBG(from),
XP_U32 XP_UNUSED(timestamp) )
{ {
CursesBoardGlobals* globals = (CursesBoardGlobals*)uc->closure; CursesBoardGlobals* globals = (CursesBoardGlobals*)uc->closure;
globals->nChatsSent = 0; globals->nChatsSent = 0;
# ifdef DEBUG # ifdef DEBUG
const XP_UCHAR* name = "<unknown>"; XP_LOGFF( "got \"%s\" from %s", msg, from );
if ( 0 <= from ) {
CommonGlobals* cGlobals = &globals->cGlobals;
name = cGlobals->gi->players[from].name;
}
XP_LOGFF( "got \"%s\" from %s", msg, name );
# endif # endif
} }
#endif #endif

View file

@ -1944,19 +1944,15 @@ gtk_util_getMQTTIDsFor( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 nRelayIDs,
#ifdef XWFEATURE_CHAT #ifdef XWFEATURE_CHAT
static void static void
gtk_util_showChat( XW_UtilCtxt* uc, XWEnv XP_UNUSED(xwe), gtk_util_showChat( XW_UtilCtxt* uc, XWEnv XP_UNUSED(xwe),
const XP_UCHAR* const msg, XP_S16 from, const XP_UCHAR* const msg,
XP_U32 tsSecs ) const XP_UCHAR* const from, XP_U32 tsSecs )
{ {
GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure; GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure;
XP_UCHAR buf[1024]; XP_UCHAR buf[1024];
XP_UCHAR* name = "<unknown>";
if ( 0 <= from ) {
name = globals->cGlobals.gi->players[from].name;
}
GDateTime* dt = g_date_time_new_from_unix_utc( tsSecs ); GDateTime* dt = g_date_time_new_from_unix_utc( tsSecs );
gchar* tsStr = g_date_time_format( dt, "%T" ); gchar* tsStr = g_date_time_format( dt, "%T" );
XP_SNPRINTF( buf, VSIZE(buf), "Quoth %s at %s: \"%s\"", name, tsStr, msg ); XP_SNPRINTF( buf, VSIZE(buf), "Quoth %s at %s: \"%s\"", from, tsStr, msg );
g_free( tsStr ); g_free( tsStr );
g_date_time_unref (dt); g_date_time_unref (dt);