fix so emailed invitations from current shipping version can be

received. I think NFC works too. Bluetooth doesn't, and isn't worth
the time to fix since users get a very clear "upgrade already"
message.
This commit is contained in:
Eric House 2015-02-26 21:39:21 -08:00
parent 3e27721ca4
commit 13b3905458
7 changed files with 131 additions and 73 deletions

View file

@ -286,7 +286,7 @@ public class BTService extends XWService {
public static void gotGameViaNFC( Context context, NetLaunchInfo bli ) public static void gotGameViaNFC( Context context, NetLaunchInfo bli )
{ {
Intent intent = getIntentTo( context, BTAction.NFCINVITE ); Intent intent = getIntentTo( context, BTAction.NFCINVITE );
intent.putExtra( GAMEID_KEY, bli.gameID ); intent.putExtra( GAMEID_KEY, bli.gameID() );
intent.putExtra( DICT_KEY, bli.dict ); intent.putExtra( DICT_KEY, bli.dict );
intent.putExtra( LANG_KEY, bli.lang ); intent.putExtra( LANG_KEY, bli.lang );
intent.putExtra( NTO_KEY, bli.nPlayersT ); intent.putExtra( NTO_KEY, bli.nPlayersT );
@ -370,7 +370,7 @@ public class BTService extends XWService {
break; break;
case INVITE: case INVITE:
String jsonData = intent.getStringExtra( GAMEDATA_KEY ); String jsonData = intent.getStringExtra( GAMEDATA_KEY );
NetLaunchInfo nli = new NetLaunchInfo( 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 ); // int gameID = intent.getIntExtra( GAMEID_KEY, -1 );
// String btAddr = intent.getStringExtra( ADDR_KEY ); // String btAddr = intent.getStringExtra( ADDR_KEY );
@ -545,7 +545,7 @@ public class BTService extends XWService {
{ {
BTCmd result; BTCmd result;
String asJson = is.readUTF(); String asJson = is.readUTF();
NetLaunchInfo nli = new NetLaunchInfo( asJson ); NetLaunchInfo nli = new NetLaunchInfo( context, asJson );
BluetoothDevice host = socket.getRemoteDevice(); BluetoothDevice host = socket.getRemoteDevice();
addAddr( host ); addAddr( host );
@ -1064,7 +1064,7 @@ public class BTService extends XWService {
DictFetchOwner.OWNER_BT ); DictFetchOwner.OWNER_BT );
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr ); // NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
MultiService.postMissingDictNotification( context, intent, MultiService.postMissingDictNotification( context, intent,
nli.gameID ); nli.gameID() );
result = BTCmd.INVITE_ACCPT; // ??? result = BTCmd.INVITE_ACCPT; // ???
} }
return result; return result;
@ -1074,7 +1074,7 @@ public class BTService extends XWService {
String sender, String senderAddress ) String sender, String senderAddress )
{ {
BTCmd result; BTCmd result;
long[] rowids = DBUtils.getRowIDsFor( BTService.this, nli.gameID ); long[] rowids = DBUtils.getRowIDsFor( BTService.this, nli.gameID() );
if ( null == rowids || 0 == rowids.length ) { if ( null == rowids || 0 == rowids.length ) {
CommsAddrRec addr = nli.makeAddrRec( context ); CommsAddrRec addr = nli.makeAddrRec( context );
long rowid = GameUtils.makeNewMultiGame( context, nli, m_btMsgSink ); long rowid = GameUtils.makeNewMultiGame( context, nli, m_btMsgSink );
@ -1088,7 +1088,7 @@ public class BTService extends XWService {
String body = LocUtils.getString( BTService.this, String body = LocUtils.getString( BTService.this,
R.string.new_bt_body_fmt, R.string.new_bt_body_fmt,
sender ); sender );
postNotification( nli.gameID, R.string.new_bt_title, body, rowid ); postNotification( nli.gameID(), R.string.new_bt_title, body, rowid );
sendResult( MultiEvent.BT_GAME_CREATED, rowid ); sendResult( MultiEvent.BT_GAME_CREATED, rowid );
} }
} else { } else {

View file

@ -1880,6 +1880,7 @@ public class BoardDelegate extends DelegateBase
pairs.m_paths, langName ); pairs.m_paths, langName );
} }
// XwJNI.game_summarize( m_jniGamePtr, m_summary );
DbgUtils.logf( "BoardDelegate:after makeFromStream: room name: %s", DbgUtils.logf( "BoardDelegate:after makeFromStream: room name: %s",
m_summary.roomName ); m_summary.roomName );

View file

@ -694,7 +694,7 @@ public class DBUtils {
{ {
Date result = null; Date result = null;
String selection = String.format("%s=%d", DBHelper.GAMEID, nli.gameID ); String selection = String.format("%s=%d", DBHelper.GAMEID, nli.gameID() );
String[] columns = { DBHelper.CREATE_TIME }; String[] columns = { DBHelper.CREATE_TIME };
initDB( context ); initDB( context );
@ -710,7 +710,7 @@ public class DBUtils {
cursor.close(); cursor.close();
db.close(); db.close();
} }
DbgUtils.logf( "getMostRecentCreate(%d) => %H", nli.gameID, result ); DbgUtils.logf( "getMostRecentCreate(%d) => %H", nli.gameID(), result );
return result; return result;
} }

View file

@ -471,7 +471,7 @@ public class GameUtils {
return makeNewMultiGame( context, sink, DBUtils.GROUPID_UNSPEC, addr, return makeNewMultiGame( context, sink, DBUtils.GROUPID_UNSPEC, addr,
new int[] {nli.lang}, new String[] { nli.dict }, new int[] {nli.lang}, new String[] { nli.dict },
nli.nPlayersT, nli.nPlayersH, nli.forceChannel, nli.nPlayersT, nli.nPlayersH, nli.forceChannel,
nli.inviteID(), nli.gameID, false ); nli.inviteID(), nli.gameID(), false );
} }
public static long makeNewMultiGame( Context context ) public static long makeNewMultiGame( Context context )
@ -1082,7 +1082,7 @@ public class GameUtils {
if ( XWApp.ATTACH_SUPPORTED ) { if ( XWApp.ATTACH_SUPPORTED ) {
byte[] data = nli.makeLaunchJSON().getBytes(); byte[] data = nli.makeLaunchJSON().getBytes();
File file = new File( dir, String.format("invite_%d", nli.gameID )); File file = new File( dir, String.format("invite_%d", nli.gameID() ));
try { try {
FileOutputStream fos = new FileOutputStream( file ); FileOutputStream fos = new FileOutputStream( file );
fos.write( data, 0, data.length ); fos.write( data, 0, data.length );

View file

@ -1775,7 +1775,7 @@ public class GamesListDelegate extends ListDelegateBase
{ {
NetLaunchInfo nli = null; NetLaunchInfo nli = null;
if ( MultiService.isMissingDictIntent( intent ) ) { if ( MultiService.isMissingDictIntent( intent ) ) {
nli = new NetLaunchInfo( intent ); nli = new NetLaunchInfo( m_activity, intent );
} else { } else {
Uri data = intent.getData(); Uri data = intent.getData();
if ( null != data ) { if ( null != data ) {
@ -1839,7 +1839,7 @@ public class GamesListDelegate extends ListDelegateBase
{ {
String data = NFCUtils.getFromIntent( intent ); String data = NFCUtils.getFromIntent( intent );
if ( null != data ) { if ( null != data ) {
NetLaunchInfo nli = new NetLaunchInfo( data ); NetLaunchInfo nli = new NetLaunchInfo( m_activity, data );
if ( nli.isValid() ) { if ( nli.isValid() ) {
startNewNetGame( nli ); startNewNetGame( nli );
} }

View file

@ -69,8 +69,7 @@ public class NetLaunchInfo {
protected boolean isGSM; protected boolean isGSM;
protected int osVers; protected int osVers;
protected int gameID; private int m_gameID = 0;
private CommsConnTypeSet m_addrs; private CommsConnTypeSet m_addrs;
private boolean m_valid; private boolean m_valid;
private String m_inviteID; private String m_inviteID;
@ -80,16 +79,16 @@ public class NetLaunchInfo {
m_addrs = new CommsConnTypeSet(); m_addrs = new CommsConnTypeSet();
} }
public NetLaunchInfo( String data ) public NetLaunchInfo( Context context, String data )
{ {
init( data ); init( context, data );
} }
public NetLaunchInfo( Intent intent ) public NetLaunchInfo( Context context, Intent intent )
{ {
String data = intent.getStringExtra( MultiService.NLI_DATA ); String data = intent.getStringExtra( MultiService.NLI_DATA );
Assert.assertNotNull( data ); Assert.assertNotNull( data );
init( data ); init( context, data );
} }
public NetLaunchInfo( Bundle bundle ) public NetLaunchInfo( Bundle bundle )
@ -102,7 +101,7 @@ public class NetLaunchInfo {
gameName = bundle.getString( MultiService.GAMENAME ); gameName = bundle.getString( MultiService.GAMENAME );
nPlayersT = bundle.getInt( MultiService.NPLAYERST ); nPlayersT = bundle.getInt( MultiService.NPLAYERST );
nPlayersH = bundle.getInt( MultiService.NPLAYERSH ); nPlayersH = bundle.getInt( MultiService.NPLAYERSH );
gameID = bundle.getInt( MultiService.GAMEID ); m_gameID = bundle.getInt( MultiService.GAMEID );
btName = bundle.getString( MultiService.BT_NAME ); btName = bundle.getString( MultiService.BT_NAME );
btAddress = bundle.getString( MultiService.BT_ADDRESS ); btAddress = bundle.getString( MultiService.BT_ADDRESS );
@ -128,22 +127,48 @@ public class NetLaunchInfo {
room = json.getString( MultiService.ROOM ); room = json.getString( MultiService.ROOM );
m_inviteID = json.getString( MultiService.INVITEID ); m_inviteID = json.getString( MultiService.INVITEID );
} else { } else {
int addrs = Integer.decode( data.getQueryParameter( ADDRS_KEY ) ); String val = data.getQueryParameter( ADDRS_KEY );
m_addrs = new CommsConnTypeSet( addrs ); boolean hasAddrs = null != val;
if ( hasAddrs ) {
m_addrs = new CommsConnTypeSet( Integer.decode( val ) );
} else {
m_addrs = new CommsConnTypeSet();
}
if ( m_addrs.contains( CommsConnType.COMMS_CONN_RELAY ) ) { CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
room = data.getQueryParameter( ROOM_KEY ); for ( CommsConnType typ : supported.getTypes() ) {
m_inviteID = data.getQueryParameter( ID_KEY ); if ( hasAddrs && !m_addrs.contains( typ ) ) {
} continue;
if ( m_addrs.contains( CommsConnType.COMMS_CONN_BT ) ) { }
btAddress = data.getQueryParameter( BTADDR_KEY ); boolean doAdd;
btName = data.getQueryParameter( BTNAME_KEY ); switch ( typ ) {
} case COMMS_CONN_BT:
if ( m_addrs.contains( CommsConnType.COMMS_CONN_SMS ) ) { btAddress = data.getQueryParameter( BTADDR_KEY );
phone = data.getQueryParameter( PHONE_KEY ); btName = data.getQueryParameter( BTNAME_KEY );
isGSM = 1 == Integer doAdd = !hasAddrs && null != btAddress;
.decode(data.getQueryParameter( GSM_KEY ) ); break;
osVers = Integer.decode(data.getQueryParameter(OSVERS_KEY)); case COMMS_CONN_RELAY:
room = data.getQueryParameter( ROOM_KEY );
m_inviteID = data.getQueryParameter( ID_KEY );
doAdd = !hasAddrs && null != room;
break;
case COMMS_CONN_SMS:
phone = data.getQueryParameter( PHONE_KEY );
val = data.getQueryParameter( GSM_KEY );
isGSM = null != val && 1 == Integer.decode( val );
val = data.getQueryParameter( OSVERS_KEY );
if ( null != val ) {
osVers = Integer.decode( val );
}
doAdd = !hasAddrs && null != phone;
break;
default:
doAdd = false;
Assert.fail();
}
if ( doAdd ) {
m_addrs.add( typ );
}
} }
dict = data.getQueryParameter( WORDLIST_KEY ); dict = data.getQueryParameter( WORDLIST_KEY );
@ -152,9 +177,11 @@ public class NetLaunchInfo {
String np = data.getQueryParameter( TOTPLAYERS_KEY ); String np = data.getQueryParameter( TOTPLAYERS_KEY );
nPlayersT = Integer.decode( np ); nPlayersT = Integer.decode( np );
String nh = data.getQueryParameter( HEREPLAYERS_KEY ); String nh = data.getQueryParameter( HEREPLAYERS_KEY );
nPlayersH = Integer.decode( nh ); nPlayersH = nh == null ? 1 : Integer.decode( nh );
gameID = Integer.decode( data.getQueryParameter( GID_KEY ) ); val = data.getQueryParameter( GID_KEY );
forceChannel = Integer.decode( data.getQueryParameter( FORCECHANNEL_KEY ) ); m_gameID = null == val ? 0 : Integer.decode( val );
val = data.getQueryParameter( FORCECHANNEL_KEY );
forceChannel = null == val ? 0 : Integer.decode( val );
} }
calcValid(); calcValid();
} catch ( Exception e ) { } catch ( Exception e ) {
@ -173,7 +200,7 @@ public class NetLaunchInfo {
lang = dictLang; lang = dictLang;
nPlayersT = nPlayers; nPlayersT = nPlayers;
nPlayersH = 1; nPlayersH = 1;
gameID = gamID; m_gameID = gamID;
} }
public NetLaunchInfo( GameSummary summary, CurGameInfo gi, int numHere, int fc ) public NetLaunchInfo( GameSummary summary, CurGameInfo gi, int numHere, int fc )
@ -220,12 +247,25 @@ public class NetLaunchInfo {
{ {
String result = m_inviteID; String result = m_inviteID;
if ( null == result ) { if ( null == result ) {
result = GameUtils.formatGameID( gameID ); result = GameUtils.formatGameID( m_gameID );
DbgUtils.logf( "inviteID(): m_inviteID null so substituting %s", result ); DbgUtils.logf( "inviteID(): m_inviteID null so substituting %s", result );
} }
return result; return result;
} }
public int gameID()
{
int result = m_gameID;
if ( 0 == result ) {
Assert.assertNotNull( m_inviteID );
result = Integer.parseInt( m_inviteID, 16 );
DbgUtils.logf( "gameID(): m_gameID -1 so substituting %d", result );
m_gameID = result;
}
Assert.assertTrue( 0 != result );
return result;
}
public void putSelf( Bundle bundle ) public void putSelf( Bundle bundle )
{ {
bundle.putString( MultiService.ROOM, room ); bundle.putString( MultiService.ROOM, room );
@ -235,7 +275,7 @@ public class NetLaunchInfo {
bundle.putString( MultiService.GAMENAME, gameName ); bundle.putString( MultiService.GAMENAME, gameName );
bundle.putInt( MultiService.NPLAYERST, nPlayersT ); bundle.putInt( MultiService.NPLAYERST, nPlayersT );
bundle.putInt( MultiService.NPLAYERSH, nPlayersH ); bundle.putInt( MultiService.NPLAYERSH, nPlayersH );
bundle.putInt( MultiService.GAMEID, gameID ); bundle.putInt( MultiService.GAMEID, gameID() );
bundle.putString( MultiService.BT_NAME, btName ); bundle.putString( MultiService.BT_NAME, btName );
bundle.putString( MultiService.BT_ADDRESS, btAddress ); bundle.putString( MultiService.BT_ADDRESS, btAddress );
bundle.putInt( MultiService.FORCECHANNEL, forceChannel ); bundle.putInt( MultiService.FORCECHANNEL, forceChannel );
@ -255,7 +295,7 @@ public class NetLaunchInfo {
.put( MultiService.GAMENAME, gameName ) .put( MultiService.GAMENAME, gameName )
.put( MultiService.NPLAYERST, nPlayersT ) .put( MultiService.NPLAYERST, nPlayersT )
.put( MultiService.NPLAYERSH, nPlayersH ) .put( MultiService.NPLAYERSH, nPlayersH )
.put( MultiService.GAMEID, gameID ) .put( MultiService.GAMEID, gameID() )
.put( MultiService.FORCECHANNEL, forceChannel ); .put( MultiService.FORCECHANNEL, forceChannel );
if ( m_addrs.contains( CommsConnType.COMMS_CONN_RELAY ) ) { if ( m_addrs.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
@ -307,44 +347,57 @@ public class NetLaunchInfo {
return result; return result;
} }
private void init( String data ) private void init( Context context, String data )
{ {
try { try {
JSONObject json = new JSONObject( data ); JSONObject json = new JSONObject( data );
int flags = json.getInt(ADDRS_KEY); int flags = json.optInt(ADDRS_KEY, -1);
m_addrs = new CommsConnTypeSet( flags ); boolean hasAddrs = -1 != flags;
m_addrs = hasAddrs ?
new CommsConnTypeSet( flags ) : new CommsConnTypeSet();
lang = json.optInt( MultiService.LANG, -1 ); lang = json.optInt( MultiService.LANG, -1 );
forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 ); forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 );
dict = json.optString( MultiService.DICT ); dict = json.optString( MultiService.DICT );
gameName = json.optString( MultiService.GAMENAME ); gameName = json.optString( MultiService.GAMENAME );
nPlayersT = json.optInt( MultiService.NPLAYERST, -1 ); nPlayersT = json.optInt( MultiService.NPLAYERST, -1 );
nPlayersH = json.optInt( MultiService.NPLAYERSH, -1 ); nPlayersH = json.optInt( MultiService.NPLAYERSH, 1 ); // absent ok
gameID = json.optInt( MultiService.GAMEID, -1 ); m_gameID = json.optInt( MultiService.GAMEID, 0 );
for ( CommsConnType typ : m_addrs.getTypes() ) { // Try each type
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
for ( CommsConnType typ : supported.getTypes() ) {
if ( hasAddrs && !m_addrs.contains( typ ) ) {
continue;
}
boolean doAdd;
switch ( typ ) { switch ( typ ) {
case COMMS_CONN_BT: case COMMS_CONN_BT:
btAddress = json.getString( MultiService.BT_ADDRESS ); btAddress = json.optString( MultiService.BT_ADDRESS );
btName = json.getString( MultiService.BT_NAME ); btName = json.optString( MultiService.BT_NAME );
doAdd = !hasAddrs && !btAddress.isEmpty();
break; break;
case COMMS_CONN_RELAY: case COMMS_CONN_RELAY:
room = json.getString( MultiService.ROOM ); room = json.getString( MultiService.ROOM );
m_inviteID = json.optString( MultiService.INVITEID ); m_inviteID = json.optString( MultiService.INVITEID );
doAdd = !hasAddrs && !room.isEmpty();
break; break;
case COMMS_CONN_SMS: case COMMS_CONN_SMS:
phone = json.getString( PHONE_KEY ); phone = json.optString( PHONE_KEY );
isGSM = json.getBoolean( GSM_KEY ); isGSM = json.optBoolean( GSM_KEY, false );
osVers = json.getInt( OSVERS_KEY ); osVers = json.optInt( OSVERS_KEY, 0 );
doAdd = !hasAddrs && !phone.isEmpty();
break; break;
default: default:
DbgUtils.logf( "Unexpected typ %s", typ.toString() ); doAdd = false;
break; Assert.fail();
}
if ( doAdd ) {
m_addrs.add( typ );
} }
} }
calcValid();
} catch ( JSONException jse ) { } catch ( JSONException jse ) {
DbgUtils.loge( jse ); DbgUtils.loge( jse );
} }
@ -368,7 +421,7 @@ public class NetLaunchInfo {
appendInt( ub, LANG_KEY, lang ); appendInt( ub, LANG_KEY, lang );
appendInt( ub, TOTPLAYERS_KEY, nPlayersT ); appendInt( ub, TOTPLAYERS_KEY, nPlayersT );
appendInt( ub, HEREPLAYERS_KEY, nPlayersH ); appendInt( ub, HEREPLAYERS_KEY, nPlayersH );
appendInt( ub, GID_KEY, gameID ); appendInt( ub, GID_KEY, gameID() );
appendInt( ub, FORCECHANNEL_KEY, forceChannel ); appendInt( ub, FORCECHANNEL_KEY, forceChannel );
appendInt( ub, ADDRS_KEY, addrs ); appendInt( ub, ADDRS_KEY, addrs );
@ -451,24 +504,28 @@ public class NetLaunchInfo {
return null != dict return null != dict
&& 0 < lang && 0 < lang
&& 0 < nPlayersT && 0 < nPlayersT
&& 0 != gameID; && 0 != gameID();
} }
private void calcValid() private void calcValid()
{ {
boolean valid = hasCommon(); boolean valid = hasCommon() && null != m_addrs;
for ( Iterator<CommsConnType> iter = m_addrs.iterator(); DbgUtils.logf( "calcValid(%s)", toString() );
valid && iter.hasNext(); ) { if ( valid ) {
switch ( iter.next() ) { for ( Iterator<CommsConnType> iter = m_addrs.iterator();
case COMMS_CONN_RELAY: valid && iter.hasNext(); ) {
valid = null != room && null != inviteID(); CommsConnType typ = iter.next();
break; switch ( typ ) {
case COMMS_CONN_BT: case COMMS_CONN_RELAY:
valid = null != btAddress && 0 != gameID; valid = null != room && null != inviteID();
break; break;
case COMMS_CONN_SMS: case COMMS_CONN_BT:
valid = null != phone && 0 < osVers; valid = null != btAddress;
break; break;
case COMMS_CONN_SMS:
valid = null != phone && 0 < osVers;
break;
}
} }
} }
m_valid = valid; m_valid = valid;

View file

@ -495,7 +495,7 @@ public class SMSService extends XWService {
switch( cmd ) { switch( cmd ) {
case INVITE: case INVITE:
String nliData = dis.readUTF(); String nliData = dis.readUTF();
NetLaunchInfo nli = new NetLaunchInfo( nliData ); NetLaunchInfo nli = new NetLaunchInfo( this, nliData );
if ( nli.isValid() ) { if ( nli.isValid() ) {
if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) { if ( DictLangCache.haveDict( this, nli.lang, nli.dict ) ) {
makeForInvite( phone, nli ); makeForInvite( phone, nli );
@ -621,8 +621,8 @@ public class SMSService extends XWService {
{ {
SMSMsgSink sink = new SMSMsgSink( this ); SMSMsgSink sink = new SMSMsgSink( this );
long rowid = GameUtils.makeNewMultiGame( this, nli, sink ); long rowid = GameUtils.makeNewMultiGame( this, nli, sink );
postNotification( phone, nli.gameID, rowid ); postNotification( phone, nli.gameID(), rowid );
ackInvite( phone, nli.gameID ); ackInvite( phone, nli.gameID() );
} }
private void makeForInvite( String phone, int gameID, String gameName, private void makeForInvite( String phone, int gameID, String gameName,