mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
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:
parent
2b8c0194a2
commit
2942c140ee
5 changed files with 33 additions and 11 deletions
|
@ -910,12 +910,6 @@ public class DBUtils {
|
|||
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 )
|
||||
{
|
||||
boolean result = false;
|
||||
|
|
|
@ -253,6 +253,25 @@ public class GameUtils {
|
|||
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 )
|
||||
{
|
||||
return dupeGame( context, rowidIn, DBUtils.GROUPID_UNSPEC );
|
||||
|
|
|
@ -290,7 +290,7 @@ public class DUtilCtxt {
|
|||
// game in the same app.
|
||||
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 );
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* in CurGameInfo
|
||||
*
|
||||
* I assume it's Serializable so it can be passed as a parameter.
|
||||
*/
|
||||
public class GameSummary implements Serializable {
|
||||
private static final String TAG = GameSummary.class.getSimpleName();
|
||||
|
@ -377,6 +379,14 @@ public class GameSummary implements Serializable {
|
|||
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 )
|
||||
{
|
||||
String player = m_players[indx];
|
||||
|
|
|
@ -246,6 +246,7 @@ game_makeRematch( const XWGame* oldGame, XWEnv xwe, XW_UtilCtxt* newUtil,
|
|||
newGI->gameID = makeGameID( newUtil );
|
||||
if ( SERVER_ISCLIENT == newGI->serverRole ) {
|
||||
newGI->serverRole = SERVER_ISSERVER; /* we'll be inviting */
|
||||
newGI->forceChannel = 0;
|
||||
}
|
||||
|
||||
CommsAddrRec* selfAddrP = NULL;
|
||||
|
@ -960,12 +961,10 @@ gi_readFromStream( MPFORMAL XWStreamCtxt* stream, CurGameInfo* gi )
|
|||
|
||||
if ( STREAM_VERS_MULTIADDR <= strVersion ) {
|
||||
gi->forceChannel = stream_getBits( stream, 2 );
|
||||
/* XP_LOGF( "%s: loaded forceChannel: %d", __func__, gi->forceChannel ); */
|
||||
}
|
||||
|
||||
gi->gameID = strVersion < STREAM_VERS_BLUETOOTH2 ?
|
||||
stream_getU16( stream ) : stream_getU32( stream );
|
||||
|
||||
// XP_LOGFF( "read forceChannel: %d for gid %X", gi->forceChannel, gi->gameID );
|
||||
|
||||
if ( STREAM_VERS_GI_ISO <= strVersion ) {
|
||||
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->confirmBTConnect );
|
||||
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 ) {
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
|
|
Loading…
Reference in a new issue