pass dict with bt invite and otherwise catch up with how invites work.

Can now invite and play a game.
This commit is contained in:
Eric House 2013-12-05 07:31:17 -08:00
parent 5fb2d9c82a
commit be28630109
4 changed files with 27 additions and 15 deletions

View file

@ -73,6 +73,7 @@ public class BTService extends XWService {
private static final String GAMEID_STR = "GMI";
private static final String LANG_STR = "LNG";
private static final String DICT_STR = "DCT";
private static final String NTO_STR = "TOT";
private static final String NHE_STR = "HER";
@ -102,16 +103,17 @@ public class BTService extends XWService {
String m_gameName;
int m_gameID;
int m_lang;
String m_dict;
int m_nPlayersT;
int m_nPlayersH;
public BTQueueElem( BTCmd cmd ) { m_cmd = cmd; m_failCount = 0; }
public BTQueueElem( BTCmd cmd, String targetName, String targetAddr,
int gameID, String gameName, int lang,
int nPlayersT, int nPlayersH ) {
String dict, int nPlayersT, int nPlayersH ) {
this( cmd, null, targetName, targetAddr, gameID );
m_lang = lang; m_nPlayersT = nPlayersT; m_nPlayersH = nPlayersH;
m_gameName = gameName;
m_lang = lang; m_dict = dict; m_nPlayersT = nPlayersT;
m_nPlayersH = nPlayersH; m_gameName = gameName;
}
public BTQueueElem( BTCmd cmd, byte[] buf, String targetName,
String targetAddr, int gameID ) {
@ -166,7 +168,7 @@ public class BTService extends XWService {
public static void inviteRemote( Context context, String hostName,
int gameID, String initialName,
int lang, int nPlayersT,
int lang, String dict, int nPlayersT,
int nPlayersH )
{
Intent intent = getIntentTo( context, INVITE );
@ -175,6 +177,7 @@ public class BTService extends XWService {
Assert.assertNotNull( initialName );
intent.putExtra( GAMENAME_STR, initialName );
intent.putExtra( LANG_STR, lang );
intent.putExtra( DICT_STR, dict );
intent.putExtra( NTO_STR, nPlayersT );
intent.putExtra( NHE_STR, nPlayersH );
@ -258,11 +261,12 @@ public class BTService extends XWService {
String gameName = intent.getStringExtra( GAMENAME_STR );
String addr = addrFor( target );
int lang = intent.getIntExtra( LANG_STR, -1 );
String dict = intent.getStringExtra( DICT_STR );
int nPlayersT = intent.getIntExtra( NTO_STR, -1 );
int nPlayersH = intent.getIntExtra( NHE_STR, -1 );
m_sender.add( new BTQueueElem( BTCmd.INVITE, target, addr,
gameID, gameName, lang,
nPlayersT, nPlayersH ) );
dict, nPlayersT, nPlayersH ) );
break;
case SEND:
byte[] buf = intent.getByteArrayExtra( MSG_STR );
@ -404,6 +408,7 @@ public class BTService extends XWService {
int gameID = is.readInt();
String gameName = is.readUTF();
int lang = is.readInt();
String dict = is.readUTF();
int nPlayersT = is.readInt();
int nPlayersH = is.readInt();
@ -415,7 +420,8 @@ public class BTService extends XWService {
String sender = host.getName();
CommsAddrRec addr = new CommsAddrRec( sender, host.getAddress() );
long rowid = GameUtils.makeNewBTGame( context, gameID, addr,
lang, nPlayersT, nPlayersH );
lang, dict, nPlayersT,
nPlayersH );
if ( DBUtils.ROWID_NOTFOUND == rowid ) {
result = BTCmd.INVITE_FAILED;
} else {
@ -680,6 +686,7 @@ public class BTService extends XWService {
outStream.writeInt( elem.m_gameID );
outStream.writeUTF( elem.m_gameName );
outStream.writeInt( elem.m_lang );
outStream.writeUTF( elem.m_dict );
outStream.writeInt( elem.m_nPlayersT );
outStream.writeInt( elem.m_nPlayersH );
outStream.flush();

View file

@ -2161,7 +2161,8 @@ public class BoardActivity extends XWActivity
case COMMS_CONN_BT:
BTService.inviteRemote( this, dev, m_gi.gameID,
gameName, m_gi.dictLang,
m_gi.nPlayers, 1 );
m_gi.dictName, m_gi.nPlayers,
1 );
break;
case COMMS_CONN_SMS:
SMSService.inviteRemote( this, dev, m_gi.gameID,

View file

@ -479,24 +479,28 @@ public class GameUtils {
public static long makeNewBTGame( Context context, int gameID,
CommsAddrRec addr, int lang,
int nPlayersT, int nPlayersH )
String dict, int nPlayersT,
int nPlayersH )
{
return makeNewBTGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
lang, nPlayersT, nPlayersH );
lang, dict, nPlayersT, nPlayersH );
}
public static long makeNewBTGame( Context context, long groupID,
int gameID, CommsAddrRec addr, int lang,
int nPlayersT, int nPlayersH )
String dict, int nPlayersT, int nPlayersH )
{
long rowid = -1;
int[] langa = { lang };
String[] dicta = { dict };
boolean isHost = null == addr;
if ( isHost ) {
addr = new CommsAddrRec( null, null );
}
return makeNewMultiGame( context, groupID, addr, langa, null,
nPlayersT, nPlayersH, null, gameID, isHost );
String inviteID = GameUtils.formatGameID( gameID );
return makeNewMultiGame( context, groupID, addr, langa, dicta,
nPlayersT, nPlayersH, inviteID, gameID,
isHost );
}
public static long makeNewSMSGame( Context context, int gameID,

View file

@ -230,7 +230,7 @@ public class NewGameActivity extends XWActivity {
if ( m_nameForBT ) {
BTService.inviteRemote( thiz, m_remoteDev,
m_gameID, m_gameName,
m_lang, 2, 1 );
m_lang, m_dict, 2, 1 );
startProgress( R.string.invite_progress );
} else {
SMSService.inviteRemote( thiz, m_remoteDev,
@ -294,7 +294,7 @@ public class NewGameActivity extends XWActivity {
long rowid =
GameUtils.makeNewBTGame( NewGameActivity.this,
m_groupID, gameID, null,
m_lang, 2, 1 );
m_lang, m_dict, 2, 1 );
DBUtils.setName( NewGameActivity.this,
rowid, m_gameName );
GameUtils.launchGame( NewGameActivity.this,
@ -365,7 +365,7 @@ public class NewGameActivity extends XWActivity {
if ( !useDefaults ) {
m_newRowID = GameUtils.makeNewBTGame( NewGameActivity.this,
m_groupID, gameID, null,
m_lang, 2, 1 );
m_lang, m_dict, 2, 1 );
Intent intent = new Intent( this, GameConfig.class );
intent.setAction( Intent.ACTION_EDIT );
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_newRowID );