diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java index fde99368e..6e1d6f60e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java @@ -71,7 +71,7 @@ public class GameConfigDelegate extends DelegateBase private static final String DIS_MAP = "DIS_MAP"; static final String INTENT_KEY_GI = "key_gi"; - static final String INTENT_KEY_CAR = "key_car"; + static final String INTENT_KEY_SADDR = "key_saddr"; static final String INTENT_KEY_NAME = "key_name"; private Activity m_activity; @@ -906,7 +906,9 @@ public class GameConfigDelegate extends DelegateBase Intent intent = new Intent(); if ( m_isNewGame ) { intent.putExtra( INTENT_KEY_GI, m_gi ); - intent.putExtra( INTENT_KEY_CAR, m_car ); + // PENDING pass only types, not full addr. Types are defaults + // we can insert later. + intent.putExtra( INTENT_KEY_SADDR, m_car ); // Game name should be a field in this layout intent.putExtra( INTENT_KEY_NAME, "Config Me" ); } else { @@ -1284,13 +1286,14 @@ public class GameConfigDelegate extends DelegateBase m_gi.boardSize = positionToSize( position ); m_gi.traySize = Integer.parseInt( m_traysizeSpinner.getSelectedItem().toString() ); - m_car.conTypes = m_conTypes; + m_car = new CommsAddrRec( m_conTypes ) + .populate( m_activity ); } // saveChanges private void applyChanges( GameLock lock, boolean forceNew ) { if ( !m_isNewGame ) { - GameUtils.applyChanges( m_activity, m_gi, m_car, m_disabMap, + GameUtils.applyChanges1( m_activity, m_gi, m_car, m_disabMap, lock, forceNew ); DBUtils.saveThumbnail( m_activity, lock, null ); // clear it } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java index e28d5e209..ec02f61a3 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java @@ -413,9 +413,8 @@ public class GameUtils { tp ); if ( null == gamePtr ) { Assert.assertTrueNR( gi.serverRole != DeviceRole.SERVER_ISCLIENT ); - CommsAddrRec selfAddr = CommsAddrRec.getSelfAddr( context ); - CommsAddrRec hostAddr = null; - gamePtr = XwJNI.initNew( gi, selfAddr, hostAddr, + CommsAddrRec selfAddr = CommsAddrRec.getSelfAddr( context, gi ); + gamePtr = XwJNI.initNew( gi, selfAddr, (CommsAddrRec)null, (UtilCtxt)null, (DrawCtx)null, CommonPrefs.get(context), null ); } @@ -570,15 +569,27 @@ public class GameUtils { return DBUtils.saveNewGame( context, bytes, groupID, null ); } - public static long saveNew( Context context, CurGameInfo gi, long groupID, - String gameName ) + public static long saveNew( Context context, CurGameInfo gi, + long groupID, String gameName ) + { + Assert.assertTrueNR( DeviceRole.SERVER_STANDALONE == gi.serverRole ); + return saveNew( context, gi, null, null, groupID, gameName ); + } + + public static long saveNew( Context context, CurGameInfo gi, + CommsAddrRec selfAddr, CommsAddrRec hostAddr, + long groupID, String gameName ) { if ( DBUtils.GROUPID_UNSPEC == groupID ) { groupID = XWPrefs.getDefaultNewGameGroup( context ); } + GamePtr gamePtr = XwJNI. + initNew( gi, selfAddr, hostAddr, + (UtilCtxt)null, (DrawCtx)null, + CommonPrefs.get(context), (TransportProcs)null ); long rowid = DBUtils.ROWID_NOTFOUND; - byte[] bytes = XwJNI.gi_to_stream( gi ); + byte[] bytes = XwJNI.game_saveToStream( gamePtr, gi ); if ( null != bytes ) { try ( GameLock lock = DBUtils.saveNewGame( context, bytes, groupID, gameName ) ) { @@ -588,81 +599,90 @@ public class GameUtils { return rowid; } - public static long makeNewMultiGame( Context context, NetLaunchInfo nli ) + public static long makeNewMultiGame1( Context context, NetLaunchInfo nli ) { - return makeNewMultiGame( context, nli, (MultiMsgSink)null, - (UtilCtxt)null ); + return makeNewMultiGame2( context, nli, (MultiMsgSink)null, + (UtilCtxt)null ); } - public static long makeNewMultiGame( Context context, NetLaunchInfo nli, - MultiMsgSink sink, UtilCtxt util ) + public static long makeNewMultiGame2( Context context, NetLaunchInfo nli, + MultiMsgSink sink, UtilCtxt util ) { - Log.d( TAG, "makeNewMultiGame(nli=%s)", nli.toString() ); - CommsAddrRec addr = nli.makeAddrRec( context ); + // Log.d( TAG, "makeNewMultiGame(nli=%s)", nli.toString() ); + // Called to create a client in response to invitation from host. As + // client, it can be created knowing host's address, and with its own + // address based on the connection types the host is using. + CommsAddrRec hostAddr = nli.makeAddrRec( context ); + CommsAddrRec selfAddr = CommsAddrRec + .getSelfAddr( context, hostAddr.conTypes ); + boolean isHost = false; - return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC, - addr, new ISOCode[] {nli.isoCode()}, - new String[] { nli.dict }, null, nli.nPlayersT, - nli.nPlayersH, nli.forceChannel, - nli.inviteID(), nli.gameID(), - nli.gameName, false, nli.remotesAreRobots ); + return makeNewMultiGame6( context, sink, util, DBUtils.GROUPID_UNSPEC, + selfAddr, hostAddr, + new ISOCode[] {nli.isoCode()}, + new String[] { nli.dict }, null, nli.nPlayersT, + nli.nPlayersH, nli.forceChannel, + nli.inviteID(), nli.gameID(), + nli.gameName, isHost, nli.remotesAreRobots ); } - public static long makeNewMultiGame( Context context, long groupID, - String gameName ) + public static long makeNewMultiGame3( Context context, long groupID, + String gameName ) { - return makeNewMultiGame( context, groupID, null, null, null, - (CommsConnTypeSet)null, gameName ); + return makeNewMultiGame4( context, groupID, (String)null, + (ISOCode)null, (String)null, + (CommsConnTypeSet)null, gameName ); } - public static long makeNewMultiGame( Context context, long groupID, - String dict, ISOCode isoCode, - String jsonData, - CommsConnTypeSet addrSet, - String gameName ) + public static long makeNewMultiGame4( Context context, long groupID, + String dict, ISOCode isoCode, + String jsonData, + CommsConnTypeSet selfSet, + String gameName ) { String inviteID = makeRandomID(); - return makeNewMultiGame( context, groupID, inviteID, dict, isoCode, - jsonData, addrSet, gameName ); + return makeNewMultiGame5( context, groupID, inviteID, dict, isoCode, + jsonData, selfSet, gameName ); } - private static long makeNewMultiGame( Context context, long groupID, - String inviteID, String dict, - ISOCode isoCode, String jsonData, - CommsConnTypeSet addrSet, - String gameName ) + private static long makeNewMultiGame5( Context context, long groupID, + String inviteID, String dict, + ISOCode isoCode, String jsonData, + CommsConnTypeSet selfSet, + String gameName ) { ISOCode[] langArray = {isoCode}; String[] dictArray = {dict}; - if ( null == addrSet ) { - addrSet = XWPrefs.getAddrTypes( context ); + if ( null == selfSet ) { + selfSet = XWPrefs.getAddrTypes( context ); } // Silently add this to any networked game if our device supports // it. comms is unhappy if we later pass in a message using an address // type the game doesn't have in its set. if ( NFCUtils.nfcAvail( context )[0] ) { - addrSet.add( CommsConnType.COMMS_CONN_NFC ); + selfSet.add( CommsConnType.COMMS_CONN_NFC ); } - CommsAddrRec addr = new CommsAddrRec( addrSet ); - addr.populate( context ); + CommsAddrRec selfAddr = new CommsAddrRec( selfSet ) + .populate( context ); int forceChannel = 0; - return makeNewMultiGame( context, (MultiMsgSink)null, (UtilCtxt)null, - groupID, addr, langArray, dictArray, jsonData, - 2, 1, forceChannel, inviteID, 0, gameName, - true, false ); + return makeNewMultiGame6( context, (MultiMsgSink)null, (UtilCtxt)null, + groupID, selfAddr, (CommsAddrRec)null, + langArray, dictArray, jsonData, 2, 1, + forceChannel, inviteID, 0, gameName, + true, false ); } - private static long makeNewMultiGame( Context context, MultiMsgSink sink, - UtilCtxt util, long groupID, - CommsAddrRec addr, - ISOCode[] isoCode, String[] dict, - String jsonData, - int nPlayersT, int nPlayersH, - int forceChannel, String inviteID, - int gameID, String gameName, - boolean isHost, boolean localsRobots ) + private static long makeNewMultiGame6( Context context, MultiMsgSink sink, + UtilCtxt util, long groupID, + CommsAddrRec selfAddr, CommsAddrRec hostAddr, + ISOCode[] isoCode, String[] dict, + String jsonData, + int nPlayersT, int nPlayersH, + int forceChannel, String inviteID, + int gameID, String gameName, + boolean isHost, boolean localsRobots ) { long rowid = DBUtils.ROWID_NOTFOUND; @@ -684,23 +704,30 @@ public class GameUtils { // Will need to add a setNPlayers() method to gi to make this // work Assert.assertTrue( gi.nPlayers == nPlayersT ); - return makeNewMultiGame( context, sink, gi, util, groupID, gameName, addr ); + return makeNewMultiGame8( context, sink, gi, selfAddr, hostAddr, + util, groupID, gameName ); } - public static long makeNewMultiGame( Context context, CurGameInfo gi, - long groupID, String gameName, - CommsAddrRec selfAddr ) + public static long makeNewMultiGame7( Context context, CurGameInfo gi, + CommsConnTypeSet selfSet, String gameName ) { - return makeNewMultiGame( context, (MultiMsgSink)null, gi, (UtilCtxt)null, - groupID, gameName, selfAddr ); + CommsAddrRec selfAddr = new CommsAddrRec( selfSet ) + .populate( context ); + return makeNewMultiGame8( context, (MultiMsgSink)null, + gi, selfAddr, (CommsAddrRec)null, + (UtilCtxt)null, + DBUtils.GROUPID_UNSPEC, gameName ); } - private static long makeNewMultiGame( Context context, MultiMsgSink sink, - CurGameInfo gi, UtilCtxt util, - long groupID, String gameName, - CommsAddrRec selfAddr ) + private static long makeNewMultiGame8( Context context, MultiMsgSink sink, + CurGameInfo gi, CommsAddrRec selfAddr, + CommsAddrRec hostAddr, UtilCtxt util, + long groupID, String gameName ) { - long rowid = saveNew( context, gi, groupID, gameName ); + if ( null == selfAddr ) { + selfAddr = CommsAddrRec.getSelfAddr( context, gi ); + } + long rowid = saveNew( context, gi, selfAddr, hostAddr, groupID, gameName ); if ( null != sink ) { sink.setRowID( rowid ); } @@ -710,9 +737,9 @@ public class GameUtils { // succeed because we just created the rowid. try ( GameLock lock = GameLock.tryLock( rowid ) ) { Assert.assertNotNull( lock ); - applyChanges( context, sink, gi, util, selfAddr, - (Map)null, - lock, false /*forceNew*/ ); + applyChanges2( context, sink, gi, util, hostAddr, + (Map)null, + lock, false /*forceNew*/ ); } } @@ -1118,20 +1145,20 @@ public class GameUtils { return success; } // replaceDicts - public static void applyChanges( Context context, CurGameInfo gi, - CommsAddrRec car, - Map disab, - GameLock lock, boolean forceNew ) + public static void applyChanges1( Context context, CurGameInfo gi, + CommsAddrRec selfAddr, + Map disab, + GameLock lock, boolean forceNew ) { - applyChanges( context, (MultiMsgSink)null, gi, (UtilCtxt)null, car, - disab, lock, forceNew ); + applyChanges2( context, (MultiMsgSink)null, gi, (UtilCtxt)null, + selfAddr, disab, lock, forceNew ); } - public static void applyChanges( Context context, MultiMsgSink sink, - CurGameInfo gi, UtilCtxt util, - CommsAddrRec car, - Map disab, - GameLock lock, boolean forceNew ) + private static void applyChanges2( Context context, MultiMsgSink sink, + CurGameInfo gi, UtilCtxt util, + CommsAddrRec selfAddr, + Map disab, + GameLock lock, boolean forceNew ) { // This should be a separate function, commitChanges() or // somesuch. But: do we have a way to save changes to a gi @@ -1150,27 +1177,28 @@ public class GameUtils { new CurGameInfo(context), null, null, cp, null ) ) { if ( null != gamePtr ) { - applyChanges( context, sink, gi, car, disab, - lock, gamePtr ); + applyChangesImpl( context, sink, gi, disab, lock, gamePtr ); madeGame = true; } } } if ( forceNew || !madeGame ) { - try ( GamePtr gamePtr = XwJNI.initNew( gi, car, null, util, (DrawCtx)null, - cp, sink ) ) { + Assert.failDbg(); // Is this happening? selfAddr is sometimes + // hostAddr so it can't work. + try ( GamePtr gamePtr = XwJNI.initNew( gi, selfAddr, (CommsAddrRec)null, + util, (DrawCtx)null, cp, sink ) ) { if ( null != gamePtr ) { - applyChanges( context, sink, gi, car, disab, lock, gamePtr ); + applyChangesImpl( context, sink, gi, disab, lock, gamePtr ); } } } } - private static void applyChanges( Context context, MultiMsgSink sink, - CurGameInfo gi, CommsAddrRec car, - Map disab, - GameLock lock, GamePtr gamePtr ) + private static void applyChangesImpl( Context context, MultiMsgSink sink, + CurGameInfo gi, + Map disab, + GameLock lock, GamePtr gamePtr ) { if ( BuildConfig.DEBUG && null != disab ) { for ( CommsConnType typ : disab.keySet() ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 17276ce71..c1e7a4ec8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -1677,11 +1677,13 @@ public class GamesListDelegate extends ListDelegateBase } else { // new game case? CurGameInfo gi = (CurGameInfo) data.getSerializableExtra( GameConfigDelegate.INTENT_KEY_GI ); - CommsAddrRec selfAddr = (CommsAddrRec) - data.getSerializableExtra( GameConfigDelegate.INTENT_KEY_CAR ); - String name = data.getStringExtra( GameConfigDelegate.INTENT_KEY_NAME ); - long rowid = GameUtils.makeNewMultiGame( m_activity, gi, DBUtils.GROUPID_UNSPEC, - name, selfAddr ); + CommsAddrRec selfAddr = (CommsAddrRec)data + .getSerializableExtra( GameConfigDelegate.INTENT_KEY_SADDR ); + CommsConnTypeSet selfTypes = selfAddr.conTypes; + String name = data + .getStringExtra( GameConfigDelegate.INTENT_KEY_NAME ); + long rowid = GameUtils.makeNewMultiGame7( m_activity, gi, + selfTypes, name ); launchGame( rowid ); } } @@ -2481,10 +2483,12 @@ public class GamesListDelegate extends ListDelegateBase { boolean result = false; try { - CommsAddrRec addr = (CommsAddrRec)intent.getSerializableExtra( INVITEE_REC_EXTRA ); - if ( null != addr ) { + CommsAddrRec hostAddr = (CommsAddrRec)intent + .getSerializableExtra( INVITEE_REC_EXTRA ); + if ( null != hostAddr ) { + Assert.failDbg(); // make sure I'm called String name = intent.getStringExtra( REMATCH_NEWNAME_EXTRA ); - makeThenLaunchOrConfigure( name, false, false, addr ); + makeThenLaunchOrConfigure( name, false, false, hostAddr ); } } catch ( Exception ex ) { Log.ex( TAG, ex ); @@ -2714,8 +2718,8 @@ public class GamesListDelegate extends ListDelegateBase String mqttDevID = extras.getString( GameSummary.EXTRA_REMATCH_MQTT ); String json = extras.getString( REMATCH_PREFS_EXTRA ); - newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict, - isoCode, json, addrs, gameName ); + newid = GameUtils.makeNewMultiGame4( m_activity, groupID, dict, + isoCode, json, addrs, gameName ); DBUtils.addRematchInfo( m_activity, newid, btAddr, phone, p2pMacAddress, mqttDevID ); } @@ -2981,7 +2985,7 @@ public class GamesListDelegate extends ListDelegateBase private void makeNewNetGame( NetLaunchInfo nli ) { long rowid = ROWID_NOTFOUND; - rowid = GameUtils.makeNewMultiGame( m_activity, nli ); + rowid = GameUtils.makeNewMultiGame1( m_activity, nli ); launchGame( rowid, null ); } @@ -3127,7 +3131,7 @@ public class GamesListDelegate extends ListDelegateBase } private void makeThenLaunchOrConfigure( String name, boolean doConfigure, - boolean skipAsk, CommsAddrRec addr ) + boolean skipAsk, CommsAddrRec hostAddr ) { if ( skipAsk || !askingChangeName( name, doConfigure ) ) { @@ -3143,11 +3147,15 @@ public class GamesListDelegate extends ListDelegateBase : DBUtils.GROUPID_UNSPEC; if ( m_mySIS.nextIsSolo ) { + Assert.assertTrueNR( null == hostAddr ); rowID = GameUtils.saveNew( m_activity, new CurGameInfo( m_activity ), groupID, name ); } else { - rowID = GameUtils.makeNewMultiGame( m_activity, groupID, name ); + Assert.assertTrueNR( null != hostAddr ); + Assert.failDbg(); // make sure I'm called + rowID = GameUtils + .makeNewMultiGame3( m_activity, groupID, name ); } GameUtils.launchGame( getDelegator(), rowID ); } @@ -3197,10 +3205,10 @@ public class GamesListDelegate extends ListDelegateBase return intent; } - private void launchLikeRematch( CommsAddrRec addr, String name ) + private void launchLikeRematch( CommsAddrRec hostAddr, String name ) { Intent intent = makeSelfIntent( m_activity ) - .putExtra( INVITEE_REC_EXTRA, (Serializable)addr ) + .putExtra( INVITEE_REC_EXTRA, (Serializable)hostAddr ) .putExtra( REMATCH_NEWNAME_EXTRA, name ) ; startActivity( intent ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java index fcbc14ebc..a9d8a9fb2 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirService.java @@ -781,9 +781,9 @@ public class WiDirService extends XWService { long[] rowids = DBUtils.getRowIDsFor( this, nli.gameID() ); if ( 0 == rowids.length ) { CommsAddrRec addr = nli.makeAddrRec( this ); - long rowid = GameUtils.makeNewMultiGame( this, nli, - m_sink, - mHelper.getUtilCtxt() ); + long rowid = GameUtils.makeNewMultiGame2( this, nli, + m_sink, + mHelper.getUtilCtxt() ); if ( DBUtils.ROWID_NOTFOUND != rowid ) { if ( null != nli.gameName && 0 < nli.gameName.length() ) { DBUtils.setName( this, rowid, nli.gameName ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java index 2c5207055..5884a9529 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java @@ -157,9 +157,9 @@ abstract class XWServiceHelper { if ( success ) { if ( DictLangCache.haveDict( mContext, nli.isoCode(), nli.dict ) ) { - long rowid = GameUtils.makeNewMultiGame( mContext, nli, - getSink( 0 ), - getUtilCtxt() ); + long rowid = GameUtils.makeNewMultiGame2( mContext, nli, + getSink( 0 ), + getUtilCtxt() ); if ( null != nli.gameName && 0 < nli.gameName.length() ) { DBUtils.setName( mContext, rowid, nli.gameName ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java index e812f31e5..51c281eee 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java @@ -371,7 +371,7 @@ public class CommsAddrRec implements Serializable { return this; } - public void populate( Context context, CommsConnTypeSet newTypes ) + public CommsAddrRec populate( Context context, CommsConnTypeSet newTypes ) { for ( CommsConnType typ : newTypes.getTypes() ) { if ( ! conTypes.contains( typ ) ) { @@ -379,13 +379,15 @@ public class CommsAddrRec implements Serializable { addTypeDefaults( context, typ ); } } + return this; } - public void populate( Context context ) + public CommsAddrRec populate( Context context ) { for ( CommsConnType typ : conTypes.getTypes() ) { addTypeDefaults( context, typ ); } + return this; } public void remove( CommsConnType typ ) @@ -442,15 +444,26 @@ public class CommsAddrRec implements Serializable { } } + public static CommsAddrRec getSelfAddr( Context context, CommsConnTypeSet types ) + { + return new CommsAddrRec() + .populate( context, types ); + } + public static CommsAddrRec getSelfAddr( Context context ) { - CommsAddrRec result = new CommsAddrRec(); CommsConnTypeSet types = XWPrefs.getAddrTypes( context ); - result.populate( context, types ); + CommsAddrRec result = getSelfAddr( context, types ); Log.d( TAG, "getSelfAddr() => %s", result ); return result; } + public static CommsAddrRec getSelfAddr( Context context, CurGameInfo gi ) + { + return CurGameInfo.DeviceRole.SERVER_STANDALONE == gi.serverRole + ? null : getSelfAddr( context ); + } + private void copyFrom( CommsAddrRec src ) { conTypes = src.conTypes; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java index 65e6cafd3..85d53e975 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java @@ -238,12 +238,9 @@ public class JNIThread extends Thread implements AutoCloseable { // generic defaults, as the user should have configured an // address for the game. Assert.assertTrueNR( m_gi.serverRole != DeviceRole.SERVER_ISCLIENT ); - Assert.failDbg(); - CommsAddrRec selfAddr = null; + Assert.failDbg(); // Do I ever get here???? + CommsAddrRec selfAddr = CommsAddrRec.getSelfAddr( context, m_gi ); CommsAddrRec hostAddr = null; - if ( m_gi.serverRole == DeviceRole.SERVER_ISSERVER ) { - selfAddr = CommsAddrRec.getSelfAddr( context ); - } m_jniGamePtr = XwJNI.initNew( m_gi, selfAddr, hostAddr, utils, null, cp, m_xport ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java index 284742fc6..334ca196b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java @@ -256,11 +256,6 @@ public class XwJNI { public static native boolean timerFired( GamePtr gamePtr, int why, int when, int handle ); - public static byte[] gi_to_stream( CurGameInfo gi ) - { - return gi_to_stream( getJNI().m_ptrGlobals, gi ); - } - public static void gi_from_stream( CurGameInfo gi, byte[] stream ) { Assert.assertNotNull( stream ); @@ -320,7 +315,11 @@ public class XwJNI { initNew( CurGameInfo gi, CommsAddrRec selfAddr, CommsAddrRec hostAddr, UtilCtxt util, DrawCtx draw, CommonPrefs cp, TransportProcs procs ) { + Log.d( TAG, "initNew(self: %s; host: %s)", selfAddr, hostAddr ); + // Only standalone doesn't provide self address Assert.assertTrueNR( null != selfAddr || gi.serverRole == DeviceRole.SERVER_STANDALONE ); + // Only client should be providing host addr + Assert.assertTrueNR( null == hostAddr || gi.serverRole == DeviceRole.SERVER_ISCLIENT ); GamePtr gamePtr = initGameJNI( 0 ); game_makeNewGame( gamePtr, gi, selfAddr, hostAddr, util, draw, cp, procs ); return gamePtr; @@ -748,7 +747,6 @@ public class XwJNI { public static native String kplr_nameForMqttDev( long jniState, String mqttID ); private static native void cleanGlobals( long jniState ); - private static native byte[] gi_to_stream( long jniState, CurGameInfo gi ); private static native void gi_from_stream( long jniState, CurGameInfo gi, byte[] stream ); private static native byte[] nli_to_stream( long jniState, NetLaunchInfo nli ); diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index 51a9e732e..f5c48f1d1 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -861,28 +861,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_kplr_1nameForMqttDev } #endif -JNIEXPORT jbyteArray JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_gi_1to_1stream -( JNIEnv* env, jclass C, jlong jniGlobalPtr, jobject jgi ) -{ - jbyteArray result; - JNIGlobalState* globalState = (JNIGlobalState*)jniGlobalPtr; -#ifdef MEM_DEBUG - MemPoolCtx* mpool = GETMPOOL( globalState ); -#endif - CurGameInfo* gi = makeGI( MPPARM(mpool) env, jgi ); - XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) globalState->vtMgr, - NULL, 0, NULL ); - - game_saveToStream( NULL, env, gi, stream, 0 ); - destroyGI( MPPARM(mpool) &gi ); - - result = streamToBArray( env, stream ); - stream_destroy( stream, env ); - releaseMPool( globalState ); - return result; -} - JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_gi_1from_1stream ( JNIEnv* env, jclass C, jlong jniGlobalPtr, jobject jgi, jbyteArray jstream ) @@ -2226,21 +2204,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs return result; } -JNIEXPORT void JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_comms_1augmentHostAddr -( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jaddr ) -{ - XWJNI_START(); - if ( state->game.comms ) { - CommsAddrRec addr = {0}; - getJAddrRec( env, &addr, jaddr ); - comms_augmentHostAddr( state->game.comms, env, &addr ); - } else { - XP_LOGFF( "no comms this game" ); - } - XWJNI_END(); -} - JNIEXPORT jboolean JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage ( JNIEnv* env, jclass C, GamePtrType gamePtr, jbyteArray jstream, jobject jaddr ) diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index 4bc72c202..da69a8725 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -214,6 +214,7 @@ static XP_Bool channelToAddress( CommsCtxt* comms, XWEnv xwe, XP_PlayerAddr chan static AddressRecord* getRecordFor( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr, XP_PlayerAddr channelNo, XP_Bool maskChnl ); +static void augmentSelfAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr ); static XP_S16 sendMsg( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* elem, CommsConnType filter ); static MsgQueueElem* addToQueue( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* newMsgElem ); @@ -431,7 +432,7 @@ comms_make( MPFORMAL XWEnv xwe, XW_UtilCtxt* util, XP_Bool isServer, if ( !!selfAddr ) { logAddr( comms, xwe, selfAddr, __func__ ); - comms_augmentHostAddr( comms, xwe, selfAddr ); + augmentSelfAddr( comms, xwe, selfAddr ); } if ( !!hostAddr ) { XP_ASSERT( !isServer ); @@ -1173,8 +1174,8 @@ comms_getHostAddr( const CommsCtxt* comms, CommsAddrRec* addr ) return haveAddr; } /* comms_getAddr */ -void -comms_augmentHostAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr ) +static void +augmentSelfAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr ) { logAddr( comms, xwe, addr, __func__ ); XP_ASSERT( comms != NULL ); diff --git a/xwords4/common/comms.h b/xwords4/common/comms.h index 5e90840d4..79b5e1c91 100644 --- a/xwords4/common/comms.h +++ b/xwords4/common/comms.h @@ -169,7 +169,6 @@ void comms_setConnID( CommsCtxt* comms, XP_U32 connID ); void comms_getSelfAddr( const CommsCtxt* comms, CommsAddrRec* selfAddr ); XP_Bool comms_getHostAddr( const CommsCtxt* comms, CommsAddrRec* hostAddr ); -void comms_augmentHostAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr ); void comms_addMQTTDevID( CommsCtxt* comms, XP_PlayerAddr channelNo, const MQTTDevID* devID ); diff --git a/xwords4/common/game.c b/xwords4/common/game.c index fa7e234e7..94424824c 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -419,9 +419,12 @@ game_makeFromInvite( MPFORMAL XWEnv xwe, const NetLaunchInfo* nli, const XP_UCHAR* plyrName, XW_UtilCtxt* util, DrawCtx* draw, CommonPrefs* cp, const TransportProcs* procs ) { + XP_MEMSET( gi, 0, sizeof(*gi) ); gi_setNPlayers( gi, nli->nPlayersT, nli->nPlayersH ); + /* These will be set by host in respose to registration message */ gi->boardSize = 15; gi->traySize = gi->bingoMin = 7; + gi->gameID = nli->gameID; XP_STRNCPY( gi->isoCodeStr, nli->isoCodeStr, VSIZE(gi->isoCodeStr) ); gi->forceChannel = nli->forceChannel; @@ -435,11 +438,6 @@ game_makeFromInvite( MPFORMAL XWEnv xwe, const NetLaunchInfo* nli, nli_makeAddrRec( nli, &hostAddr ); XP_Bool success = game_makeNewGame( MPPARM(mpool) xwe, game, gi, selfAddr, &hostAddr, util, draw, cp, procs ); - if ( success ) { - CommsAddrRec returnAddr; - nli_makeAddrRec( nli, &returnAddr ); - comms_augmentHostAddr( game->comms, NULL, &returnAddr ); - } return success; } diff --git a/xwords4/linux/gamesdb.c b/xwords4/linux/gamesdb.c index 8325d62d9..864e187ce 100644 --- a/xwords4/linux/gamesdb.c +++ b/xwords4/linux/gamesdb.c @@ -660,20 +660,6 @@ gdb_loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid ) return loadBlobColumn( stream, pDb, rowid, "game" ); } -/* Used for rematch only. But do I need it? */ -void -gdb_saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid ) -{ - sqlite3_int64 row = writeBlobColumnStream( stream, pDb, rowid, "inviteInfo" ); - assert( row == rowid ); -} - -XP_Bool -gdb_loadInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid ) -{ - return loadBlobColumn( stream, pDb, rowid, "inviteInfo" ); -} - void gdb_deleteGame( sqlite3* pDb, sqlite3_int64 rowid ) { diff --git a/xwords4/linux/gamesdb.h b/xwords4/linux/gamesdb.h index 2f5a0b5d9..745231774 100644 --- a/xwords4/linux/gamesdb.h +++ b/xwords4/linux/gamesdb.h @@ -72,10 +72,6 @@ XP_Bool gdb_getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib ); void gdb_getRowsForGameID( sqlite3* pDb, XP_U32 gameID, sqlite3_int64* rowids, int* nRowIDs ); XP_Bool gdb_loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid ); -void gdb_saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, - sqlite3_int64 rowid ); -XP_Bool gdb_loadInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb, - sqlite3_int64 rowid ); void gdb_deleteGame( sqlite3* pDb, sqlite3_int64 rowid ); #define KEY_RDEVID "RDEVID" diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index 6d6957e0d..90232d86f 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -706,33 +706,6 @@ on_board_window_shown( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals ) gtkShowFinalScores( globals, XP_TRUE ); } - CommsCtxt* comms = cGlobals->game.comms; - if ( !!comms /*&& COMMS_CONN_NONE == comms_getConTypes( comms )*/ ) { - /* If it has pending invite info, send the invitation! */ - XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(cGlobals->util->mpool) - cGlobals->params->vtMgr ); - if ( gdb_loadInviteAddrs( stream, cGlobals->params->pDb, - cGlobals->rowid ) ) { - CommsAddrRec addr = {0}; - addrFromStream( &addr, stream ); - comms_augmentHostAddr( cGlobals->game.comms, NULL_XWE, &addr ); - - XP_U16 nRecs = stream_getU8( stream ); - XP_LOGF( "%s: got invite info: %d records", __func__, nRecs ); - for ( int ii = 0; ii < nRecs; ++ii ) { - XP_UCHAR relayID[32]; - stringFromStreamHere( stream, relayID, sizeof(relayID) ); - XP_LOGF( "%s: loaded relayID %s", __func__, relayID ); - - CommsAddrRec addr = {0}; - addrFromStream( &addr, stream ); - - send_invites( cGlobals, 1, &addr ); - } - } - stream_destroy( stream, NULL_XWE ); - } - resizeFromRowid( globals ); } /* on_board_window_shown */