consider channel when deciding if a game's present (and fix assign)

Rematch against self didn't work, and is useful for testing. So in
dutil method hasGame(), check if games with the same gameID are also
for the same channel. And when creating a new game for rematch, make
sure it's channel is 0.
This commit is contained in:
Eric House 2022-12-29 21:17:09 -08:00
parent 2b8c0194a2
commit 2942c140ee
5 changed files with 33 additions and 11 deletions

View file

@ -910,12 +910,6 @@ public class DBUtils {
return result; return result;
} }
public static boolean haveGame( Context context, int gameID )
{
long[] rows = getRowIDsFor( context, gameID );
return 0 < rows.length;
}
public static boolean haveGame( Context context, long rowid ) public static boolean haveGame( Context context, long rowid )
{ {
boolean result = false; boolean result = false;

View file

@ -253,6 +253,25 @@ public class GameUtils {
return getSummary( context, rowid, 0L ); return getSummary( context, rowid, 0L );
} }
public static boolean haveGame( Context context, int gameID, int channel )
{
long[] rows = DBUtils.getRowIDsFor( context, gameID );
boolean found = false;
for ( long rowid : rows ) {
GameSummary summary = getSummary( context, rowid );
// Most of the time if we can't open it we assume it matches. A
// non-matching game is a same-device thing I'm probably the only
// one doing.
if ( null == summary || channel == summary.getChannel() ) {
found = true;
break;
}
}
// Log.d( TAG, "haveGame(gameID=%X, channel=%d) => %b",
// gameID, channel, found );
return found;
}
public static long dupeGame( Context context, long rowidIn ) public static long dupeGame( Context context, long rowidIn )
{ {
return dupeGame( context, rowidIn, DBUtils.GROUPID_UNSPEC ); return dupeGame( context, rowidIn, DBUtils.GROUPID_UNSPEC );

View file

@ -290,7 +290,7 @@ public class DUtilCtxt {
// game in the same app. // game in the same app.
public boolean haveGame( int gameID, int channel ) public boolean haveGame( int gameID, int channel )
{ {
boolean result = DBUtils.haveGame( m_context, gameID ); boolean result = GameUtils.haveGame( m_context, gameID, channel );
Log.d( TAG, "haveGame(%d, %d) => %b", gameID, channel, result ); Log.d( TAG, "haveGame(%d, %d) => %b", gameID, channel, result );
return result; return result;
} }

View file

@ -45,6 +45,8 @@ import org.eehouse.android.xw4.loc.LocUtils;
/** Info we want to access when the game's closed that's not available /** Info we want to access when the game's closed that's not available
* in CurGameInfo * in CurGameInfo
*
* I assume it's Serializable so it can be passed as a parameter.
*/ */
public class GameSummary implements Serializable { public class GameSummary implements Serializable {
private static final String TAG = GameSummary.class.getSimpleName(); private static final String TAG = GameSummary.class.getSimpleName();
@ -377,6 +379,14 @@ public class GameSummary implements Serializable {
m_giFlags = new Integer( flags ); m_giFlags = new Integer( flags );
} }
public int getChannel()
{
int flags = giflags();
int channel = (flags >> FORCE_CHANNEL_OFFSET) & FORCE_CHANNEL_MASK;
// Log.d( TAG, "getChannel(id: %X) => %d", gameID, channel );
return channel;
}
public String summarizePlayer( Context context, long rowid, int indx ) public String summarizePlayer( Context context, long rowid, int indx )
{ {
String player = m_players[indx]; String player = m_players[indx];

View file

@ -246,6 +246,7 @@ game_makeRematch( const XWGame* oldGame, XWEnv xwe, XW_UtilCtxt* newUtil,
newGI->gameID = makeGameID( newUtil ); newGI->gameID = makeGameID( newUtil );
if ( SERVER_ISCLIENT == newGI->serverRole ) { if ( SERVER_ISCLIENT == newGI->serverRole ) {
newGI->serverRole = SERVER_ISSERVER; /* we'll be inviting */ newGI->serverRole = SERVER_ISSERVER; /* we'll be inviting */
newGI->forceChannel = 0;
} }
CommsAddrRec* selfAddrP = NULL; CommsAddrRec* selfAddrP = NULL;
@ -960,12 +961,10 @@ gi_readFromStream( MPFORMAL XWStreamCtxt* stream, CurGameInfo* gi )
if ( STREAM_VERS_MULTIADDR <= strVersion ) { if ( STREAM_VERS_MULTIADDR <= strVersion ) {
gi->forceChannel = stream_getBits( stream, 2 ); gi->forceChannel = stream_getBits( stream, 2 );
/* XP_LOGF( "%s: loaded forceChannel: %d", __func__, gi->forceChannel ); */
} }
gi->gameID = strVersion < STREAM_VERS_BLUETOOTH2 ? gi->gameID = strVersion < STREAM_VERS_BLUETOOTH2 ?
stream_getU16( stream ) : stream_getU32( stream ); stream_getU16( stream ) : stream_getU32( stream );
// XP_LOGFF( "read forceChannel: %d for gid %X", gi->forceChannel, gi->gameID );
if ( STREAM_VERS_GI_ISO <= strVersion ) { if ( STREAM_VERS_GI_ISO <= strVersion ) {
stringFromStreamHere( stream, gi->isoCodeStr, VSIZE(gi->isoCodeStr) ); stringFromStreamHere( stream, gi->isoCodeStr, VSIZE(gi->isoCodeStr) );
@ -1039,7 +1038,7 @@ gi_writeToStream( XWStreamCtxt* stream, const CurGameInfo* gi )
stream_putBits( stream, 1, gi->allowHintRect ); stream_putBits( stream, 1, gi->allowHintRect );
stream_putBits( stream, 1, gi->confirmBTConnect ); stream_putBits( stream, 1, gi->confirmBTConnect );
stream_putBits( stream, 2, gi->forceChannel ); stream_putBits( stream, 2, gi->forceChannel );
/* XP_LOGF( "%s: wrote forceChannel: %d", __func__, gi->forceChannel ); */ // XP_LOGFF( "wrote forceChannel: %d for gid %X", gi->forceChannel, gi->gameID );
if ( 0 ) { if ( 0 ) {
#ifdef STREAM_VERS_BIGBOARD #ifdef STREAM_VERS_BIGBOARD