pass utilctxt when making new game in response to relay invitation so

the game can communicate. This lets the game reply and otherwise get
started the way BT- and SMS-invite-created ones do.
This commit is contained in:
Eric House 2015-07-16 06:46:39 -07:00
parent 9a7220554f
commit c9e8655eea
4 changed files with 31 additions and 21 deletions

View file

@ -1076,7 +1076,8 @@ public class BTService extends XWService {
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( BTService.this ); CommsAddrRec addr = nli.makeAddrRec( BTService.this );
long rowid = GameUtils.makeNewMultiGame( BTService.this, nli, m_btMsgSink ); long rowid = GameUtils.makeNewMultiGame( BTService.this, nli,
m_btMsgSink, null );
if ( DBUtils.ROWID_NOTFOUND == rowid ) { if ( DBUtils.ROWID_NOTFOUND == rowid ) {
result = BTCmd.INVITE_FAILED; result = BTCmd.INVITE_FAILED;
} else { } else {

View file

@ -463,18 +463,20 @@ public class GameUtils {
public static long makeNewMultiGame( Context context, NetLaunchInfo nli ) public static long makeNewMultiGame( Context context, NetLaunchInfo nli )
{ {
return makeNewMultiGame( context, nli, null ); return makeNewMultiGame( context, nli, (MultiMsgSink)null,
(UtilCtxt)null );
} }
public static long makeNewMultiGame( Context context, NetLaunchInfo nli, public static long makeNewMultiGame( Context context, NetLaunchInfo nli,
MultiMsgSink sink ) MultiMsgSink sink, UtilCtxt util )
{ {
DbgUtils.logf( "makeNewMultiGame(nli=%s)", nli.toString() ); DbgUtils.logf( "makeNewMultiGame(nli=%s)", nli.toString() );
CommsAddrRec addr = nli.makeAddrRec( context ); CommsAddrRec addr = nli.makeAddrRec( context );
return makeNewMultiGame( context, sink, DBUtils.GROUPID_UNSPEC, addr, return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC,
new int[] {nli.lang}, new String[] { nli.dict }, addr, new int[] {nli.lang},
nli.nPlayersT, nli.nPlayersH, nli.forceChannel, new String[] { nli.dict }, nli.nPlayersT,
nli.nPlayersH, nli.forceChannel,
nli.inviteID(), nli.gameID(), nli.gameName, nli.inviteID(), nli.gameID(), nli.gameName,
false ); false );
} }
@ -505,12 +507,14 @@ public class GameUtils {
CommsAddrRec addr = new CommsAddrRec( addrSet ); CommsAddrRec addr = new CommsAddrRec( addrSet );
addr.populate( context ); addr.populate( context );
int forceChannel = 0; int forceChannel = 0;
return makeNewMultiGame( context, null, groupID, addr, lang, dict, 2, 1, return makeNewMultiGame( context, (MultiMsgSink)null, (UtilCtxt)null,
groupID, addr, lang, dict, 2, 1,
forceChannel, inviteID, 0, gameName, true ); forceChannel, inviteID, 0, gameName, true );
} }
private static long makeNewMultiGame( Context context, MultiMsgSink sink, private static long makeNewMultiGame( Context context, MultiMsgSink sink,
long groupID, CommsAddrRec addr, UtilCtxt util, long groupID,
CommsAddrRec addr,
int[] lang, String[] dict, int[] lang, String[] dict,
int nPlayersT, int nPlayersH, int nPlayersT, int nPlayersH,
int forceChannel, String inviteID, int forceChannel, String inviteID,
@ -543,7 +547,7 @@ public class GameUtils {
if ( DBUtils.ROWID_NOTFOUND != rowid ) { if ( DBUtils.ROWID_NOTFOUND != rowid ) {
GameLock lock = new GameLock( rowid, true ).lock(); GameLock lock = new GameLock( rowid, true ).lock();
applyChanges( context, sink, gi, addr, inviteID, lock, false ); applyChanges( context, sink, gi, util, addr, inviteID, lock, false );
lock.unlock(); lock.unlock();
} }
@ -595,9 +599,10 @@ public class GameUtils {
addr = new CommsAddrRec( null, null ); addr = new CommsAddrRec( null, null );
} }
String inviteID = GameUtils.formatGameID( gameID ); String inviteID = GameUtils.formatGameID( gameID );
return makeNewMultiGame( context, sink, groupID, addr, langa, dicta, return makeNewMultiGame( context, sink, (UtilCtxt)null, groupID, addr,
nPlayersT, nPlayersH, forceChannel, langa, dicta, nPlayersT, nPlayersH,
inviteID, gameID, gameName, isHost ); forceChannel, inviteID, gameID, gameName,
isHost );
} }
public static void launchEmailInviteActivity( Activity activity, NetLaunchInfo nli ) public static void launchEmailInviteActivity( Activity activity, NetLaunchInfo nli )
@ -955,13 +960,14 @@ public class GameUtils {
CommsAddrRec car, String inviteID, CommsAddrRec car, String inviteID,
GameLock lock, boolean forceNew ) GameLock lock, boolean forceNew )
{ {
applyChanges( context, null, gi, car, inviteID, lock, forceNew ); applyChanges( context, (MultiMsgSink)null, gi, (UtilCtxt)null, car,
inviteID, lock, forceNew );
} }
public static void applyChanges( Context context, MultiMsgSink sink, public static void applyChanges( Context context, MultiMsgSink sink,
CurGameInfo gi, CommsAddrRec car, CurGameInfo gi, UtilCtxt util,
String inviteID, GameLock lock, CommsAddrRec car, String inviteID,
boolean forceNew ) GameLock lock, boolean forceNew )
{ {
// This should be a separate function, commitChanges() or // This should be a separate function, commitChanges() or
// somesuch. But: do we have a way to save changes to a gi // somesuch. But: do we have a way to save changes to a gi
@ -988,7 +994,9 @@ public class GameUtils {
} }
if ( forceNew || !madeGame ) { if ( forceNew || !madeGame ) {
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(context), XwJNI.game_makeNewGame( gamePtr, gi, util,
JNIUtilsImpl.get(context),
(DrawCtx)null,
cp, sink, dictNames, pairs.m_bytes, cp, sink, dictNames, pairs.m_bytes,
pairs.m_paths, langName ); pairs.m_paths, langName );
} }

View file

@ -1,6 +1,6 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */ /* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/* /*
* Copyright 2010 - 2012 by Eric House (xwords@eehouse.org). All * Copyright 2010 - 2015 by Eric House (xwords@eehouse.org). All
* rights reserved. * rights reserved.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -251,8 +251,9 @@ public class RelayService extends XWService
// connect to the inviting game, because it needs to be open to // connect to the inviting game, because it needs to be open to
// make the initial connection -- needs access to util. That // make the initial connection -- needs access to util. That
// should be fixable -- eventually. // should be fixable -- eventually.
RelayMsgSink sink = null; // new RelayMsgSink(); RelayMsgSink sink = new RelayMsgSink();
long rowid = GameUtils.makeNewMultiGame( this, nli, sink ); UtilCtxt util = new UtilCtxtImpl( this );
long rowid = GameUtils.makeNewMultiGame( this, nli, sink, util );
if ( DBUtils.ROWID_NOTFOUND != rowid ) { if ( DBUtils.ROWID_NOTFOUND != rowid ) {
if ( null != nli.gameName && 0 < nli.gameName.length() ) { if ( null != nli.gameName && 0 < nli.gameName.length() ) {
DBUtils.setName( this, rowid, nli.gameName ); DBUtils.setName( this, rowid, nli.gameName );

View file

@ -630,7 +630,7 @@ public class SMSService extends XWService {
private void makeForInvite( String phone, NetLaunchInfo nli ) private void makeForInvite( String phone, NetLaunchInfo nli )
{ {
SMSMsgSink sink = new SMSMsgSink( this ); SMSMsgSink sink = new SMSMsgSink( this );
long rowid = GameUtils.makeNewMultiGame( this, nli, sink ); long rowid = GameUtils.makeNewMultiGame( this, nli, sink, null );
postNotification( phone, nli.gameID() ); postNotification( phone, nli.gameID() );
ackInvite( phone, nli.gameID() ); ackInvite( phone, nli.gameID() );
} }