mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
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:
parent
59f9dd51b8
commit
4a4219bc9c
4 changed files with 38 additions and 17 deletions
|
@ -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,6 +1050,7 @@ public class BTService extends XWService {
|
|||
String btAddr )
|
||||
{
|
||||
BTCmd result;
|
||||
if ( checkNotDupe( nli ) ) {
|
||||
if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) {
|
||||
result = makeGame( nli, btName, btAddr );
|
||||
} else {
|
||||
|
@ -1066,6 +1062,9 @@ public class BTService extends XWService {
|
|||
nli.gameID() );
|
||||
result = BTCmd.INVITE_ACCPT; // ???
|
||||
}
|
||||
} else {
|
||||
result = BTCmd.INVITE_DUP_INVITE; // dupe of rematch
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -226,8 +226,10 @@ public class RelayService extends XWService
|
|||
{
|
||||
DbgUtils.logdf( "receiveInvitation: got nli from %d: %s", srcDevID,
|
||||
nli.toString() );
|
||||
if ( checkNotDupe( nli ) ) {
|
||||
makeOrNotify( nli );
|
||||
}
|
||||
}
|
||||
|
||||
private void makeOrNotify( NetLaunchInfo nli )
|
||||
{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<String> s_seen = new HashSet<String>();
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue