track time of most recent turn start, and include it in summary table.

This commit is contained in:
Eric House 2012-09-27 06:55:46 -07:00
parent 6ddd4a61c1
commit 94103a4212
6 changed files with 33 additions and 5 deletions

View file

@ -1118,6 +1118,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
setBool( env, jsummary, "gameOver", gameOver );
setInt( env, jsummary, "turn",
server_getCurrentTurn( state->game.server ) );
setInt( env, jsummary, "lastMoveTime",
server_getLastMoveTime(state->game.server) );
if ( !!state->game.comms ) {
CommsAddrRec addr;

View file

@ -31,7 +31,7 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String TABLE_NAME_DICTBROWSE = "dictbrowse";
public static final String TABLE_NAME_DICTINFO = "dictinfo";
private static final String DB_NAME = "xwdb";
private static final int DB_VERSION = 13;
private static final int DB_VERSION = 14;
public static final String GAME_NAME = "GAME_NAME";
public static final String NUM_MOVES = "NUM_MOVES";
@ -62,6 +62,8 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String RELAYID = "RELAYID";
public static final String SEED = "SEED";
public static final String SMSPHONE = "SMSPHONE";
public static final String LASTMOVE = "LASTMOVE";
public static final String DICTNAME = "DICTNAME";
public static final String MD5SUM = "MD5SUM";
@ -118,6 +120,7 @@ public class DBHelper extends SQLiteOpenHelper {
+ CHAT_HISTORY + " TEXT,"
+ GAMEID + " INTEGER,"
+ REMOTEDEVS + " TEXT,"
+ LASTMOVE + " INTEGER DEFAULT 0,"
// HASMSGS: sqlite doesn't have bool; use 0 and 1
+ HASMSGS + " INTEGER DEFAULT 0,"
+ CONTRACTED + " INTEGER DEFAULT 0,"
@ -125,8 +128,8 @@ public class DBHelper extends SQLiteOpenHelper {
+ CREATE_TIME + " INTEGER,"
+ LASTPLAY_TIME + " INTEGER,"
+ SNAPSHOT + " BLOB"
+ ");" );
+ SNAPSHOT + " BLOB);"
);
}
private void onCreateObits( SQLiteDatabase db )
@ -193,6 +196,8 @@ public class DBHelper extends SQLiteOpenHelper {
addColumn( db, REMOTEDEVS, "TEXT" );
case 12:
onCreateDictsDB( db );
case 13:
addColumn( db, LASTMOVE, "INTEGER" );
// nothing yet
break;
default:
@ -204,7 +209,7 @@ public class DBHelper extends SQLiteOpenHelper {
}
}
public void addColumn( SQLiteDatabase db, String colName, String colType )
private void addColumn( SQLiteDatabase db, String colName, String colType )
{
String cmd = String.format( "ALTER TABLE %s ADD COLUMN %s %s;",
TABLE_NAME_SUM, colName, colType );

View file

@ -133,6 +133,7 @@ public class DBUtils {
DBHelper.DICTLANG, DBHelper.GAMEID,
DBHelper.SCORES, DBHelper.HASMSGS,
DBHelper.LASTPLAY_TIME, DBHelper.REMOTEDEVS,
DBHelper.LASTMOVE
};
String selection = String.format( ROW_ID_FMT, lock.getRowid() );
@ -176,6 +177,8 @@ public class DBUtils {
int tmp = cursor.getInt(cursor.
getColumnIndex(DBHelper.GAME_OVER));
summary.gameOver = tmp != 0;
summary.lastMoveTime =
cursor.getInt(cursor.getColumnIndex(DBHelper.LASTMOVE));
String scoresStr =
cursor.getString( cursor.getColumnIndex(DBHelper.SCORES));
@ -275,6 +278,8 @@ public class DBUtils {
values.put( DBHelper.DICTLANG, summary.dictLang );
values.put( DBHelper.GAMEID, summary.gameID );
values.put( DBHelper.GAME_OVER, summary.gameOver? 1 : 0 );
values.put( DBHelper.LASTMOVE, summary.lastMoveTime );
values.put( DBHelper.DICTLIST, summary.dictNames(DICTS_SEP) );
values.put( DBHelper.HASMSGS, summary.pendingMsgLevel );
if ( null != inviteID ) {

View file

@ -40,6 +40,7 @@ public class GameSummary {
public static final int MSG_FLAGS_GAMEOVER = 4;
public static final int MSG_FLAGS_ALL = 7;
public int lastMoveTime;
public int nMoves;
public int turn;
public int nPlayers;

View file

@ -80,6 +80,7 @@ typedef struct ServerVolatiles {
} ServerVolatiles;
typedef struct ServerNonvolatiles {
XP_U32 lastMoveTime; /* seconds of last turn change */
XP_U8 nDevices;
XW_State gameState;
XW_State stateAfterShow;
@ -276,6 +277,10 @@ getNV( XWStreamCtxt* stream, ServerNonvolatiles* nv, XP_U16 nPlayers )
XP_U16 ii;
XP_U16 version = stream_getVersion( stream );
if ( STREAM_VERS_DICTNAME <= version ) {
nv->lastMoveTime = stream_getU32( stream );
}
if ( version < STREAM_VERS_SERVER_SAVES_TOSHOW ) {
/* no longer used */
(void)stream_getBits( stream, 3 ); /* was npassesinrow */
@ -316,6 +321,8 @@ putNV( XWStreamCtxt* stream, const ServerNonvolatiles* nv, XP_U16 nPlayers )
{
XP_U16 ii;
stream_putU32( stream, nv->lastMoveTime );
/* number of players is upper limit on device count */
stream_putBits( stream, NDEVICES_NBITS, nv->nDevices-1 );
@ -629,7 +636,7 @@ server_sendChat( ServerCtxt* server, const XP_UCHAR const* msg )
#endif
static void
callTurnChangeListener( ServerCtxt* server )
callTurnChangeListener( const ServerCtxt* server )
{
if ( server->vol.turnChangeListener != NULL ) {
(*server->vol.turnChangeListener)( server->vol.turnChangeData );
@ -2380,6 +2387,12 @@ server_getMissingPlayers( const ServerCtxt* server )
return result;
}
XP_U32
server_getLastMoveTime( const ServerCtxt* server )
{
return server->nv.lastMoveTime;
}
static void
doEndGame( ServerCtxt* server )
{
@ -2463,6 +2476,7 @@ setTurn( ServerCtxt* server, XP_S16 turn )
{
if ( server->nv.currentTurn != turn ) {
server->nv.currentTurn = turn;
server->nv.lastMoveTime = util_getCurSeconds( server->vol.util );
callTurnChangeListener( server );
}
}

View file

@ -95,6 +95,7 @@ XP_S16 server_getCurrentTurn( ServerCtxt* server );
XP_Bool server_getGameIsOver( ServerCtxt* server );
/* return bitvector marking players still not arrived in networked game */
XP_U16 server_getMissingPlayers( const ServerCtxt* server );
XP_U32 server_getLastMoveTime( const ServerCtxt* server );
/* Signed in case no dictionary available */
XP_S16 server_countTilesInPool( ServerCtxt* server );