rematch invitations are sent simultaneously on all known channels, so

on recipient device check that we aren't trying to handle more than
one. The test is for duplicate inviteIDs, and won't catch them if
received other than close together, but the existing test against the
set of saved games (getRowIDsFor(gameID)) will catch that.
This commit is contained in:
Eric House 2015-07-22 06:52:53 -07:00
parent 59f9dd51b8
commit 4a4219bc9c
4 changed files with 38 additions and 17 deletions

View file

@ -104,6 +104,7 @@ public class BTService extends XWService {
MESG_DECL, MESG_DECL,
MESG_GAMEGONE, MESG_GAMEGONE,
REMOVE_FOR, REMOVE_FOR,
INVITE_DUP_INVITE,
}; };
private class BTQueueElem { private class BTQueueElem {
@ -372,12 +373,6 @@ public class BTService extends XWService {
String jsonData = intent.getStringExtra( GAMEDATA_KEY ); String jsonData = intent.getStringExtra( GAMEDATA_KEY );
NetLaunchInfo nli = new NetLaunchInfo( this, jsonData ); NetLaunchInfo nli = new NetLaunchInfo( this, jsonData );
DbgUtils.logf( "onStartCommand: nli: %s", nli.toString() ); DbgUtils.logf( "onStartCommand: nli: %s", nli.toString() );
// int gameID = intent.getIntExtra( GAMEID_KEY, -1 );
// String btAddr = intent.getStringExtra( ADDR_KEY );
// String gameName = intent.getStringExtra( GAMENAME_KEY );
// int lang = intent.getIntExtra( LANG_KEY, -1 );
// String dict = intent.getStringExtra( DICT_KEY );
// int nPlayersT = intent.getIntExtra( NTO_KEY, -1 );
String btAddr = intent.getStringExtra( ADDR_KEY ); String btAddr = intent.getStringExtra( ADDR_KEY );
m_sender.add( new BTQueueElem( BTCmd.INVITE, nli, btAddr ) ); m_sender.add( new BTQueueElem( BTCmd.INVITE, nli, btAddr ) );
break; break;
@ -1055,16 +1050,20 @@ public class BTService extends XWService {
String btAddr ) String btAddr )
{ {
BTCmd result; BTCmd result;
if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) { if ( checkNotDupe( nli ) ) {
result = makeGame( nli, btName, btAddr ); if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) {
result = makeGame( nli, btName, btAddr );
} else {
Intent intent = MultiService
.makeMissingDictIntent( this, nli,
DictFetchOwner.OWNER_BT );
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
MultiService.postMissingDictNotification( this, intent,
nli.gameID() );
result = BTCmd.INVITE_ACCPT; // ???
}
} else { } else {
Intent intent = MultiService result = BTCmd.INVITE_DUP_INVITE; // dupe of rematch
.makeMissingDictIntent( this, nli,
DictFetchOwner.OWNER_BT );
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
MultiService.postMissingDictNotification( this, intent,
nli.gameID() );
result = BTCmd.INVITE_ACCPT; // ???
} }
return result; return result;
} }

View file

@ -226,7 +226,9 @@ public class RelayService extends XWService
{ {
DbgUtils.logdf( "receiveInvitation: got nli from %d: %s", srcDevID, DbgUtils.logdf( "receiveInvitation: got nli from %d: %s", srcDevID,
nli.toString() ); nli.toString() );
makeOrNotify( nli ); if ( checkNotDupe( nli ) ) {
makeOrNotify( nli );
}
} }
private void makeOrNotify( NetLaunchInfo nli ) private void makeOrNotify( NetLaunchInfo nli )

View file

@ -502,7 +502,7 @@ public class SMSService extends XWService {
case INVITE: case INVITE:
String nliData = dis.readUTF(); String nliData = dis.readUTF();
NetLaunchInfo nli = new NetLaunchInfo( this, nliData ); NetLaunchInfo nli = new NetLaunchInfo( this, nliData );
if ( nli.isValid() ) { if ( nli.isValid() && checkNotDupe( nli ) ) {
if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) { if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) {
makeForInvite( phone, nli ); makeForInvite( phone, nli );
} else { } else {

View file

@ -24,12 +24,16 @@ import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import java.util.HashSet;
import java.util.Set;
import org.eehouse.android.xw4.MultiService.MultiEvent; import org.eehouse.android.xw4.MultiService.MultiEvent;
public class XWService extends Service { public class XWService extends Service {
protected static MultiService s_srcMgr = null; protected static MultiService s_srcMgr = null;
private static Set<String> s_seen = new HashSet<String>();
@Override @Override
public IBinder onBind( Intent intent ) public IBinder onBind( Intent intent )
@ -54,4 +58,20 @@ public class XWService extends Service {
DbgUtils.logf( "XWService.sendResult: dropping %s event", event.toString() ); DbgUtils.logf( "XWService.sendResult: dropping %s event", event.toString() );
} }
} }
// Check that we aren't already processing an invitation with this
// inviteID.
protected boolean checkNotDupe( NetLaunchInfo nli )
{
String inviteID = nli.inviteID();
boolean isDupe;
synchronized( s_seen ) {
isDupe = s_seen.contains( inviteID );
if ( !isDupe ) {
s_seen.add( inviteID );
}
}
DbgUtils.logf( "XWService.checkNotDupe(%s) => %b", inviteID, !isDupe );
return !isDupe;
}
} }