add fromRematch to existing api to avoid race condition

This commit is contained in:
Eric House 2023-12-23 07:54:26 -08:00
parent b5de43e3dc
commit 52a1de0463
9 changed files with 24 additions and 28 deletions

View file

@ -177,6 +177,7 @@ public class BoardDelegate extends DelegateBase
int nGuestDevs; int nGuestDevs;
CommsAddrRec hostAddr; CommsAddrRec hostAddr;
boolean inTrade; boolean inTrade;
boolean fromRematch;
StartAlertOrder mAlertOrder = StartAlertOrder.values()[0]; StartAlertOrder mAlertOrder = StartAlertOrder.values()[0];
} }
private MySIS m_mySIS; private MySIS m_mySIS;
@ -2049,7 +2050,7 @@ public class BoardDelegate extends DelegateBase
@Override @Override
public void informMissing( boolean isServer, CommsAddrRec hostAddr, public void informMissing( boolean isServer, CommsAddrRec hostAddr,
CommsConnTypeSet connTypes, int nDevs, CommsConnTypeSet connTypes, int nDevs,
int nMissing, int nInvited ) int nMissing, int nInvited, boolean fromRematch )
{ {
// Log.d( TAG, "informMissing(isServer: %b, nDevs: %d; nMissing: %d, " // Log.d( TAG, "informMissing(isServer: %b, nDevs: %d; nMissing: %d, "
// + " nInvited: %d", isServer, nDevs, nMissing, nInvited ); // + " nInvited: %d", isServer, nDevs, nMissing, nInvited );
@ -2057,6 +2058,7 @@ public class BoardDelegate extends DelegateBase
m_mySIS.nMissing = nMissing; // will be 0 unless isServer is true m_mySIS.nMissing = nMissing; // will be 0 unless isServer is true
m_mySIS.nInvited = nInvited; m_mySIS.nInvited = nInvited;
m_mySIS.nGuestDevs = nDevs; m_mySIS.nGuestDevs = nDevs;
m_mySIS.fromRematch = fromRematch;
m_mySIS.hostAddr = hostAddr; m_mySIS.hostAddr = hostAddr;
m_connTypes = connTypes; m_connTypes = connTypes;
@ -2583,10 +2585,8 @@ public class BoardDelegate extends DelegateBase
private void showOrHide( InvitesNeededAlert.Wrapper wrapper ) private void showOrHide( InvitesNeededAlert.Wrapper wrapper )
{ {
boolean fromRematch = null != m_jniGamePtr
&& XwJNI.server_isFromRematch( m_jniGamePtr );
wrapper.showOrHide( m_mySIS.hostAddr, m_mySIS.nMissing, wrapper.showOrHide( m_mySIS.hostAddr, m_mySIS.nMissing,
m_mySIS.nInvited, fromRematch ); m_mySIS.nInvited, m_mySIS.fromRematch );
} }
private InvitesNeededAlert.Wrapper mINAWrapper; private InvitesNeededAlert.Wrapper mINAWrapper;

View file

@ -110,7 +110,7 @@ public interface UtilCtxt {
void informMissing( boolean isServer, CommsAddrRec hostAddr, void informMissing( boolean isServer, CommsAddrRec hostAddr,
CommsConnTypeSet connTypes, int nDevs, CommsConnTypeSet connTypes, int nDevs,
int nMissingPlayers, int nInvited ); int nMissingPlayers, int nInvited, boolean fromRematch );
void notifyGameOver(); void notifyGameOver();
// Don't need this unless we have a scroll thumb to indicate position // Don't need this unless we have a scroll thumb to indicate position

View file

@ -228,7 +228,8 @@ public class UtilCtxtImpl implements UtilCtxt {
@Override @Override
public void informMissing( boolean isServer, CommsAddrRec hostAddr, public void informMissing( boolean isServer, CommsAddrRec hostAddr,
CommsConnTypeSet connTypes, int nDevices, CommsConnTypeSet connTypes, int nDevices,
int nMissingPlayers, int nInvited ) int nMissingPlayers, int nInvited,
boolean fromRematch )
{ {
subclassOverride( "informMissing" ); subclassOverride( "informMissing" );
} }

View file

@ -551,7 +551,6 @@ public class XwJNI {
public static native String server_writeFinalScores( GamePtr gamePtr ); public static native String server_writeFinalScores( GamePtr gamePtr );
public static native boolean server_initClientConnection( GamePtr gamePtr ); public static native boolean server_initClientConnection( GamePtr gamePtr );
public static native boolean server_canOfferRematch( GamePtr gamePtr ); public static native boolean server_canOfferRematch( GamePtr gamePtr );
public static native boolean server_isFromRematch( GamePtr gamePtr );
public static native void server_endGame( GamePtr gamePtr ); public static native void server_endGame( GamePtr gamePtr );
// hybrid to save work // hybrid to save work

View file

@ -694,11 +694,11 @@ static void
and_util_informMissing( XW_UtilCtxt* uc, XWEnv xwe, XP_Bool isServer, and_util_informMissing( XW_UtilCtxt* uc, XWEnv xwe, XP_Bool isServer,
const CommsAddrRec* hostAddr, const CommsAddrRec* hostAddr,
const CommsAddrRec* selfAddr, XP_U16 nDevs, const CommsAddrRec* selfAddr, XP_U16 nDevs,
XP_U16 nMissing, XP_U16 nInvited ) XP_U16 nMissing, XP_U16 nInvited, XP_Bool fromRematch )
{ {
UTIL_CBK_HEADER( "informMissing", UTIL_CBK_HEADER( "informMissing",
"(ZL" PKG_PATH("jni/CommsAddrRec") ";" "(ZL" PKG_PATH("jni/CommsAddrRec") ";"
"L" PKG_PATH("jni/CommsAddrRec$CommsConnTypeSet") ";III)V" ); "L" PKG_PATH("jni/CommsAddrRec$CommsConnTypeSet") ";IIIZ)V" );
jobject jHostAddr = NULL; jobject jHostAddr = NULL;
if ( !!hostAddr ) { if ( !!hostAddr ) {
jHostAddr = makeJAddr( env, hostAddr ); jHostAddr = makeJAddr( env, hostAddr );
@ -709,7 +709,7 @@ and_util_informMissing( XW_UtilCtxt* uc, XWEnv xwe, XP_Bool isServer,
jtypset = addrTypesToJ( env, selfAddr ); jtypset = addrTypesToJ( env, selfAddr );
} }
(*env)->CallVoidMethod( env, util->jutil, mid, isServer, jHostAddr, (*env)->CallVoidMethod( env, util->jutil, mid, isServer, jHostAddr,
jtypset, nDevs, nMissing, nInvited ); jtypset, nDevs, nMissing, nInvited, fromRematch );
deleteLocalRefs( env, jHostAddr, jtypset, DELETE_NO_REF ); deleteLocalRefs( env, jHostAddr, jtypset, DELETE_NO_REF );
UTIL_CBK_TAIL(); UTIL_CBK_TAIL();
} }

View file

@ -2202,17 +2202,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1initClientConnection
return result; return result;
} }
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1isFromRematch
( JNIEnv* env, jclass C, GamePtrType gamePtr )
{
jboolean result;
XWJNI_START_GLOBALS(gamePtr);
result = server_isFromRematch( state->game.server );
XWJNI_END();
return result;
}
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1canOfferRematch Java_org_eehouse_android_xw4_jni_XwJNI_server_1canOfferRematch
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, GamePtrType gamePtr )

View file

@ -571,6 +571,7 @@ informMissing( const ServerCtxt* server, XWEnv xwe )
XP_U16 nDevs = 0; XP_U16 nDevs = 0;
XP_U16 nPending = 0; XP_U16 nPending = 0;
XP_Bool fromRematch = XP_FALSE;
if ( XWSTATE_BEGIN < server->nv.gameState ) { if ( XWSTATE_BEGIN < server->nv.gameState ) {
/* do nothing */ /* do nothing */
} else if ( isHost ) { } else if ( isHost ) {
@ -582,11 +583,13 @@ informMissing( const ServerCtxt* server, XWEnv xwe )
nInvited = nPending; nInvited = nPending;
} }
} }
fromRematch = server_isFromRematch( server );
} else if ( SERVER_ISCLIENT == gi->serverRole ) { } else if ( SERVER_ISCLIENT == gi->serverRole ) {
nPending = gi->nPlayers - gi_countLocalPlayers( gi, XP_FALSE); nPending = gi->nPlayers - gi_countLocalPlayers( gi, XP_FALSE);
} }
util_informMissing( server->vol.util, xwe, isHost, util_informMissing( server->vol.util, xwe, isHost,
hostAddrP, selfAddrP, nDevs, nPending, nInvited ); hostAddrP, selfAddrP, nDevs, nPending, nInvited,
fromRematch );
} }
XP_U16 XP_U16

View file

@ -170,7 +170,8 @@ typedef struct UtilVtable {
void (*m_util_informMissing)( XW_UtilCtxt* uc, XWEnv xwe, XP_Bool isHost, void (*m_util_informMissing)( XW_UtilCtxt* uc, XWEnv xwe, XP_Bool isHost,
const CommsAddrRec* hostAddr, const CommsAddrRec* hostAddr,
const CommsAddrRec* selfAddr, XP_U16 nDevs, const CommsAddrRec* selfAddr, XP_U16 nDevs,
XP_U16 nMissing, XP_U16 nInvited ); XP_U16 nMissing, XP_U16 nInvited,
XP_Bool fromRematch );
void (*m_util_informWordsBlocked)( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 nBadWords, void (*m_util_informWordsBlocked)( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 nBadWords,
XWStreamCtxt* words, const XP_UCHAR* dictName ); XWStreamCtxt* words, const XP_UCHAR* dictName );
@ -305,8 +306,9 @@ struct XW_UtilCtxt {
(uc)->vtable->m_util_cellSquareHeld( (uc), (e), (s) ) (uc)->vtable->m_util_cellSquareHeld( (uc), (e), (s) )
#endif #endif
#define util_informMissing( uc, e, is, ha, sa, nd, nm, ni ) \ #define util_informMissing( uc, e, is, ha, sa, nd, nm, ni, fr ) \
(uc)->vtable->m_util_informMissing((uc), (e), (is), (ha), (sa), (nd), (nm), (ni) ) (uc)->vtable->m_util_informMissing((uc), (e), (is), (ha), (sa), \
(nd), (nm), (ni), (fr) )
#define util_informWordsBlocked(uc,e, c, w, d) \ #define util_informWordsBlocked(uc,e, c, w, d) \
(uc)->vtable->m_util_informWordsBlocked( (uc), (e), (c), (w), (d) ) (uc)->vtable->m_util_informWordsBlocked( (uc), (e), (c), (w), (d) )

View file

@ -1694,10 +1694,12 @@ linux_util_informMissing( XW_UtilCtxt* XP_UNUSED(uc), XWEnv XP_UNUSED(xwe),
const CommsAddrRec* XP_UNUSED_DBG(selfAddr), const CommsAddrRec* XP_UNUSED_DBG(selfAddr),
XP_U16 XP_UNUSED_DBG(nDevs), XP_U16 XP_UNUSED_DBG(nDevs),
XP_U16 XP_UNUSED_DBG(nMissing), XP_U16 XP_UNUSED_DBG(nMissing),
XP_U16 XP_UNUSED_DBG(nInvited) ) XP_U16 XP_UNUSED_DBG(nInvited),
XP_Bool XP_UNUSED_DBG(fromRematch) )
{ {
XP_LOGFF( "(isServer=%d, addr=%p, nDevs=%d, nMissing=%d, nInvited=%d)", XP_LOGFF( "(isServer=%d, addr=%p, nDevs=%d, nMissing=%d, "
isServer, selfAddr, nDevs, nMissing, nInvited ); "nInvited=%d, fromRematch=%s)", isServer, selfAddr,
nDevs, nMissing, nInvited, boolToStr(fromRematch) );
} }
unsigned int unsigned int