diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java index f713f724a..43b32b7e5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java @@ -104,6 +104,7 @@ public class BTService extends XWService { MESG_DECL, MESG_GAMEGONE, REMOVE_FOR, + INVITE_DUP_INVITE, }; private class BTQueueElem { @@ -372,12 +373,6 @@ public class BTService extends XWService { String jsonData = intent.getStringExtra( GAMEDATA_KEY ); NetLaunchInfo nli = new NetLaunchInfo( this, jsonData ); 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 ); m_sender.add( new BTQueueElem( BTCmd.INVITE, nli, btAddr ) ); break; @@ -1055,16 +1050,20 @@ public class BTService extends XWService { String btAddr ) { BTCmd result; - if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) { - result = makeGame( nli, btName, btAddr ); + if ( checkNotDupe( nli ) ) { + 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 { - 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; // ??? + result = BTCmd.INVITE_DUP_INVITE; // dupe of rematch } return result; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java index 02d87dd04..270bc41df 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -226,7 +226,9 @@ public class RelayService extends XWService { DbgUtils.logdf( "receiveInvitation: got nli from %d: %s", srcDevID, nli.toString() ); - makeOrNotify( nli ); + if ( checkNotDupe( nli ) ) { + makeOrNotify( nli ); + } } private void makeOrNotify( NetLaunchInfo nli ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java index 43ef149a6..f6c06dac8 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java @@ -502,7 +502,7 @@ public class SMSService extends XWService { case INVITE: String nliData = dis.readUTF(); NetLaunchInfo nli = new NetLaunchInfo( this, nliData ); - if ( nli.isValid() ) { + if ( nli.isValid() && checkNotDupe( nli ) ) { if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) { makeForInvite( phone, nli ); } else { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWService.java index d2d466454..eb1be40ac 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWService.java @@ -24,12 +24,16 @@ import android.app.Service; import android.content.Intent; import android.os.IBinder; +import java.util.HashSet; +import java.util.Set; + import org.eehouse.android.xw4.MultiService.MultiEvent; public class XWService extends Service { protected static MultiService s_srcMgr = null; + private static Set s_seen = new HashSet(); @Override public IBinder onBind( Intent intent ) @@ -54,4 +58,20 @@ public class XWService extends Service { 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; + } }