diff --git a/xwords4/android/XWords4/jni/utilwrapper.c b/xwords4/android/XWords4/jni/utilwrapper.c index 794a1ddcd..791de092a 100644 --- a/xwords4/android/XWords4/jni/utilwrapper.c +++ b/xwords4/android/XWords4/jni/utilwrapper.c @@ -355,6 +355,15 @@ and_util_remSelected(XW_UtilCtxt* uc) UTIL_CBK_TAIL(); } +static void +and_util_setIsServer(XW_UtilCtxt* uc, XP_Bool isServer ) +{ + /* Change both the C and Java structs, which need to stay in sync */ + uc->gameInfo->serverRole = isServer? SERVER_ISSERVER : SERVER_ISCLIENT; + UTIL_CBK_HEADER("setIsServer", "(Z)V" ); + (*env)->CallVoidMethod( env, util->jutil, mid, isServer ); + UTIL_CBK_TAIL(); +} #ifndef XWFEATURE_STANDALONE_ONLY static void @@ -437,6 +446,7 @@ makeUtil( MPFORMAL JNIEnv** envp, jobject jutil, CurGameInfo* gi, SET_PROC(getUserString); SET_PROC(warnIllegalWord); SET_PROC(remSelected); + SET_PROC(setIsServer); #ifndef XWFEATURE_STANDALONE_ONLY SET_PROC(addrChange); diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 5d10df213..be9db722e 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -731,6 +731,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1redoReplacedTiles return result; } +JNIEXPORT void JNICALL +Java_org_eehouse_android_xw4_jni_XwJNI_server_1reset +(JNIEnv* env, jclass C, jint gamePtr ) +{ + XWJNI_START(); + server_reset( state->game.server, state->game.comms ); + XWJNI_END(); +} + JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_server_1handleUndo (JNIEnv* env, jclass C, jint gamePtr) diff --git a/xwords4/android/XWords4/res/drawable/refresh.png b/xwords4/android/XWords4/res/drawable/refresh.png new file mode 100644 index 000000000..2c47e0abd Binary files /dev/null and b/xwords4/android/XWords4/res/drawable/refresh.png differ diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index eadca9ba6..cb729bf89 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -604,6 +604,21 @@ public class BoardActivity extends Activity implements UtilCtxt { R.string.tiles_left_title ); } + public void setIsServer( boolean isServer ) + { + Utils.logf( "setIsServer(%s)", isServer?"true":"false" ); + DeviceRole newRole = isServer? DeviceRole.SERVER_ISSERVER + : DeviceRole.SERVER_ISCLIENT; + if ( newRole != m_gi.serverRole ) { + Utils.logf( "new role: %s; old role: %s", + newRole.toString(), m_gi.serverRole.toString() ); + m_gi.serverRole = newRole; + if ( !isServer ) { + m_jniThread.handle( JNIThread.JNICmd.CMD_SWITCHCLIENT ); + } + } + } + public void setTimer( int why, int when, int handle ) { if ( null != m_timers[why] ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java index 358b2cc18..0ff297737 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java @@ -459,7 +459,7 @@ public class GameConfig extends Activity implements View.OnClickListener, m_notNetworkedGame = m_notNetworkedGameCheckbx.isChecked(); m_gi.setServerRole( m_notNetworkedGame ? DeviceRole.SERVER_STANDALONE - : DeviceRole.SERVER_ISSERVER ); + : DeviceRole.SERVER_ISCLIENT ); loadPlayers(); } else if ( m_joinPublicCheck == view ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index e1862b294..f6bdc77d4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -44,6 +44,7 @@ public class JNIThread extends Thread { CMD_DRAW, CMD_LAYOUT, CMD_START, + CMD_SWITCHCLIENT, CMD_RESET, CMD_SAVE, CMD_DO, @@ -287,6 +288,13 @@ public class JNIThread extends Thread { } draw = XwJNI.server_do( m_jniGamePtr ); break; + + case CMD_SWITCHCLIENT: + XwJNI.server_reset( m_jniGamePtr ); + XwJNI.server_initClientConnection( m_jniGamePtr ); + draw = XwJNI.server_do( m_jniGamePtr ); + break; + case CMD_DO: if ( nextSame( JNICmd.CMD_DO ) ) { continue; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java index 339422c39..bc6a11b86 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java @@ -45,9 +45,10 @@ public interface UtilCtxt { public static final int TIMER_SLOWROBOT = 4; void setTimer( int why, int when, int handle ); void clearTimer( int why ); + void requestTime(); void remSelected(); - + void setIsServer( boolean isServer ); static final int STRD_ROBOT_TRADED = 1; static final int STR_ROBOT_MOVED = 2; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java index 4bcda57ac..c28004762 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java @@ -182,6 +182,7 @@ public class XwJNI { public static native int model_getNMoves( int gamePtr ); // Server + public static native void server_reset( int gamePtr ); public static native void server_handleUndo( int gamePtr ); public static native boolean server_do( int gamePtr ); public static native String server_formatDictCounts( int gamePtr, int nCols );