merge android_branch -> android_shipbt

This commit is contained in:
Eric House 2014-09-23 21:33:57 -07:00
commit 64b30b68d2
6 changed files with 72 additions and 18 deletions

View file

@ -83,6 +83,7 @@
#define STREAM_VERS_41B4 0x02 #define STREAM_VERS_41B4 0x02
#define STREAM_VERS_405 0x01 #define STREAM_VERS_405 0x01
/* search for FIX_NEXT_VERSION_CHANGE next time this is changed */
#define CUR_STREAM_VERS STREAM_VERS_COMMSBACKOFF #define CUR_STREAM_VERS STREAM_VERS_COMMSBACKOFF
typedef struct XP_Rect { typedef struct XP_Rect {

View file

@ -76,6 +76,7 @@ typedef struct ServerVolatiles {
void* turnChangeData; void* turnChangeData;
GameOverListener gameOverListener; GameOverListener gameOverListener;
void* gameOverData; void* gameOverData;
XP_U16 pendingRegistrations;
XP_Bool showPrevMove; XP_Bool showPrevMove;
} ServerVolatiles; } ServerVolatiles;
@ -86,7 +87,6 @@ typedef struct ServerNonvolatiles {
XW_State stateAfterShow; XW_State stateAfterShow;
XP_S8 currentTurn; /* invalid when game is over */ XP_S8 currentTurn; /* invalid when game is over */
XP_S8 quitter; /* -1 unless somebody resigned */ XP_S8 quitter; /* -1 unless somebody resigned */
XP_U8 pendingRegistrations;
XP_Bool showRobotScores; XP_Bool showRobotScores;
XP_Bool sortNewTiles; XP_Bool sortNewTiles;
#ifdef STREAM_VERS_BIGBOARD #ifdef STREAM_VERS_BIGBOARD
@ -206,21 +206,23 @@ logNewState( XW_State old, XW_State newst )
****************************************************************************/ ****************************************************************************/
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
static void static void
syncPlayers( ServerCtxt* server ) figureMissing( ServerCtxt* server )
{ {
XP_U16 pendingRegistrations = 0;
XP_U16 ii; XP_U16 ii;
CurGameInfo* gi = server->vol.gi; CurGameInfo* gi = server->vol.gi;
LocalPlayer* lp = gi->players; LocalPlayer* lp = gi->players;
ServerPlayer* player = server->players; ServerPlayer* player = server->players;
for ( ii = 0; ii < gi->nPlayers; ++ii, ++lp, ++player ) { for ( ii = 0; ii < gi->nPlayers; ++ii, ++lp, ++player ) {
if ( !lp->isLocal/* && !lp->name */ ) { if ( !lp->isLocal && !lp->name ) {
++server->nv.pendingRegistrations; ++pendingRegistrations;
} }
player->deviceIndex = lp->isLocal? SERVER_DEVICE : UNKNOWN_DEVICE; player->deviceIndex = lp->isLocal? SERVER_DEVICE : UNKNOWN_DEVICE;
} }
server->vol.pendingRegistrations = pendingRegistrations;
} }
#else #else
# define syncPlayers( server ) # define figureMissing( server )
#endif #endif
static XP_Bool static XP_Bool
@ -243,7 +245,7 @@ initServer( ServerCtxt* server )
SETSTATE( server, XWSTATE_BEGIN ); SETSTATE( server, XWSTATE_BEGIN );
} }
syncPlayers( server ); figureMissing( server );
server->nv.nDevices = 1; /* local device (0) is always there */ server->nv.nDevices = 1; /* local device (0) is always there */
#ifdef STREAM_VERS_BIGBOARD #ifdef STREAM_VERS_BIGBOARD
@ -302,7 +304,8 @@ getNV( XWStreamCtxt* stream, ServerNonvolatiles* nv, XP_U16 nPlayers )
if ( STREAM_VERS_DICTNAME <= version ) { if ( STREAM_VERS_DICTNAME <= version ) {
nv->quitter = (XP_S8)stream_getBits( stream, NPLAYERS_NBITS ) - 1; nv->quitter = (XP_S8)stream_getBits( stream, NPLAYERS_NBITS ) - 1;
} }
nv->pendingRegistrations = (XP_U8)stream_getBits( stream, NPLAYERS_NBITS ); /* FIX_NEXT_VERSION_CHANGE */
/*nv->pendingRegistrations = (XP_U8)*/ stream_getBits( stream, NPLAYERS_NBITS );
for ( ii = 0; ii < nPlayers; ++ii ) { for ( ii = 0; ii < nPlayers; ++ii ) {
nv->addresses[ii].channelNo = nv->addresses[ii].channelNo =
@ -337,7 +340,8 @@ putNV( XWStreamCtxt* stream, const ServerNonvolatiles* nv, XP_U16 nPlayers )
/* +1: make -1 (NOTURN) into a positive number */ /* +1: make -1 (NOTURN) into a positive number */
stream_putBits( stream, NPLAYERS_NBITS, nv->currentTurn+1 ); stream_putBits( stream, NPLAYERS_NBITS, nv->currentTurn+1 );
stream_putBits( stream, NPLAYERS_NBITS, nv->quitter+1 ); stream_putBits( stream, NPLAYERS_NBITS, nv->quitter+1 );
stream_putBits( stream, NPLAYERS_NBITS, nv->pendingRegistrations ); /* FIX_NEXT_VERSION_CHANGE */
stream_putBits( stream, NPLAYERS_NBITS, 0 /*nv->pendingRegistrations*/ );
for ( ii = 0; ii < nPlayers; ++ii ) { for ( ii = 0; ii < nPlayers; ++ii ) {
stream_putBits( stream, 16, nv->addresses[ii].channelNo ); stream_putBits( stream, 16, nv->addresses[ii].channelNo );
@ -416,9 +420,11 @@ server_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
server->nv.prevWordsStream = readStreamIf( server, stream ); server->nv.prevWordsStream = readStreamIf( server, stream );
} }
figureMissing( server );
util_informMissing( util, server->vol.gi->serverRole == SERVER_ISSERVER, util_informMissing( util, server->vol.gi->serverRole == SERVER_ISSERVER,
comms_getConType( comms ), comms_getConType( comms ),
server->nv.pendingRegistrations ); server->vol.pendingRegistrations );
return server; return server;
} /* server_makeFromStream */ } /* server_makeFromStream */
@ -699,7 +705,7 @@ handleRegistrationMsg( ServerCtxt* server, XWStreamCtxt* stream )
playersInMsg = (XP_U16)stream_getBits( stream, NPLAYERS_NBITS ); playersInMsg = (XP_U16)stream_getBits( stream, NPLAYERS_NBITS );
XP_ASSERT( playersInMsg > 0 ); XP_ASSERT( playersInMsg > 0 );
if ( server->nv.pendingRegistrations < playersInMsg ) { if ( server->vol.pendingRegistrations < playersInMsg ) {
util_userError( server->vol.util, ERR_REG_UNEXPECTED_USER ); util_userError( server->vol.util, ERR_REG_UNEXPECTED_USER );
success = XP_FALSE; success = XP_FALSE;
} else { } else {
@ -738,7 +744,7 @@ handleRegistrationMsg( ServerCtxt* server, XWStreamCtxt* stream )
} }
#endif #endif
if ( server->nv.pendingRegistrations == 0 ) { if ( server->vol.pendingRegistrations == 0 ) {
XP_ASSERT( ii == playersInMsg ); /* otherwise malformed */ XP_ASSERT( ii == playersInMsg ); /* otherwise malformed */
setStreamVersion( server ); setStreamVersion( server );
checkResizeBoard( server ); checkResizeBoard( server );
@ -1031,7 +1037,7 @@ server_do( ServerCtxt* server )
switch( server->nv.gameState ) { switch( server->nv.gameState ) {
case XWSTATE_BEGIN: case XWSTATE_BEGIN:
if ( server->nv.pendingRegistrations == 0 ) { /* all players on if ( server->vol.pendingRegistrations == 0 ) { /* all players on
device */ device */
assignTilesToAll( server ); assignTilesToAll( server );
SETSTATE( server, XWSTATE_INTURN ); SETSTATE( server, XWSTATE_INTURN );
@ -1126,7 +1132,7 @@ findFirstPending( ServerCtxt* server, ServerPlayer** playerP )
LocalPlayer* lp; LocalPlayer* lp;
CurGameInfo* gi = server->vol.gi; CurGameInfo* gi = server->vol.gi;
XP_U16 nPlayers = gi->nPlayers; XP_U16 nPlayers = gi->nPlayers;
XP_U16 nPending = server->nv.pendingRegistrations; XP_U16 nPending = server->vol.pendingRegistrations;
XP_ASSERT( nPlayers > 0 ); XP_ASSERT( nPlayers > 0 );
lp = gi->players + nPlayers; lp = gi->players + nPlayers;
@ -1160,7 +1166,7 @@ registerRemotePlayer( ServerCtxt* server, XWStreamCtxt* stream )
/* The player must already be there with a null name, or it's an error. /* The player must already be there with a null name, or it's an error.
Take the first empty slot. */ Take the first empty slot. */
XP_ASSERT( server->nv.pendingRegistrations > 0 ); XP_ASSERT( server->vol.pendingRegistrations > 0 );
/* find the slot to use */ /* find the slot to use */
lp = findFirstPending( server, &player ); lp = findFirstPending( server, &player );
@ -1179,7 +1185,7 @@ registerRemotePlayer( ServerCtxt* server, XWStreamCtxt* stream )
channelNo = stream_getAddress( stream ); channelNo = stream_getAddress( stream );
deviceIndex = getIndexForDevice( server, channelNo ); deviceIndex = getIndexForDevice( server, channelNo );
--server->nv.pendingRegistrations; --server->vol.pendingRegistrations;
if ( deviceIndex == -1 ) { if ( deviceIndex == -1 ) {
RemoteAddress* addr; RemoteAddress* addr;
@ -1350,7 +1356,7 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream )
sortTilesIf( server, ii ); sortTilesIf( server, ii );
} }
syncPlayers( server ); figureMissing( server );
SETSTATE( server, XWSTATE_INTURN ); SETSTATE( server, XWSTATE_INTURN );
@ -2427,7 +2433,7 @@ server_getMissingPlayers( const ServerCtxt* server )
} }
break; break;
case SERVER_ISSERVER: case SERVER_ISSERVER:
if ( 0 < server->nv.pendingRegistrations ) { if ( 0 < server->vol.pendingRegistrations ) {
XP_U16 nPlayers = server->vol.gi->nPlayers; XP_U16 nPlayers = server->vol.gi->nPlayers;
const ServerPlayer* players = server->players; const ServerPlayer* players = server->players;
for ( ii = 0; ii < nPlayers; ++ii ) { for ( ii = 0; ii < nPlayers; ++ii ) {
@ -2550,6 +2556,7 @@ tileCountsOk( const ServerCtxt* server )
static void static void
setTurn( ServerCtxt* server, XP_S16 turn ) setTurn( ServerCtxt* server, XP_S16 turn )
{ {
XP_ASSERT( -1 == turn || 0 == server->vol.pendingRegistrations );
if ( server->nv.currentTurn != turn ) { if ( server->nv.currentTurn != turn ) {
server->nv.currentTurn = turn; server->nv.currentTurn = turn;
server->nv.lastMoveTime = util_getCurSeconds( server->vol.util ); server->nv.lastMoveTime = util_getCurSeconds( server->vol.util );

View file

@ -145,6 +145,7 @@ endif
DEFINES += ${BLUETOOTH} DEFINES += ${BLUETOOTH}
DEFINES += -DXWFEATURE_RELAY DEFINES += -DXWFEATURE_RELAY
DEFINES += -DXWFEATURE_SMS -DXWFEATURE_BASE64 DEFINES += -DXWFEATURE_SMS -DXWFEATURE_BASE64
DEFINES += -DXWFEATURE_DIRECTIP
# Robot can be made to think, to simulate for relay mostly # Robot can be made to think, to simulate for relay mostly
DEFINES += -DXWFEATURE_SLOW_ROBOT DEFINES += -DXWFEATURE_SLOW_ROBOT

View file

@ -35,6 +35,8 @@ typedef struct _GtkConnsState {
GtkWidget* bthost; GtkWidget* bthost;
GtkWidget* smsphone; GtkWidget* smsphone;
GtkWidget* smsport; GtkWidget* smsport;
GtkWidget* iphost;
GtkWidget* ipport;
GtkWidget* bgScanButton; GtkWidget* bgScanButton;
GtkWidget* notebook; GtkWidget* notebook;
@ -80,7 +82,15 @@ handle_ok( GtkWidget* XP_UNUSED(widget), gpointer closure )
CommsConnType conType = pageNoToConnType( state, page ); CommsConnType conType = pageNoToConnType( state, page );
switch ( conType ) { switch ( conType ) {
#ifdef XWFEATURE_DIRECTIP
case COMMS_CONN_IP_DIRECT: case COMMS_CONN_IP_DIRECT:
txt = gtk_entry_get_text( GTK_ENTRY(state->iphost) );
XP_STRNCPY( state->addr->u.ip.hostName_ip, txt,
sizeof(state->addr->u.ip.hostName_ip) );
txt = gtk_entry_get_text( GTK_ENTRY(state->ipport) );
state->addr->u.ip.port_ip = atoi( txt );
break;
#endif
#ifdef XWFEATURE_RELAY #ifdef XWFEATURE_RELAY
case COMMS_CONN_RELAY: case COMMS_CONN_RELAY:
txt = gtk_entry_get_text( GTK_ENTRY(state->invite) ); txt = gtk_entry_get_text( GTK_ENTRY(state->invite) );
@ -224,6 +234,32 @@ makeBTPage( GtkConnsState* state )
return vbox; return vbox;
} /* makeBTPage */ } /* makeBTPage */
#ifdef XWFEATURE_DIRECTIP
static GtkWidget*
makeIPDirPage( GtkConnsState* state )
{
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
/* XP_UCHAR hostName_ip[MAX_HOSTNAME_LEN + 1]; */
/* XP_U16 port_ip; */
const gchar* name = COMMS_CONN_IP_DIRECT == state->addr->conType ?
state->addr->u.ip.hostName_ip : state->globals->cGlobals.params->connInfo.ip.hostName;
GtkWidget* hbox = makeLabeledField( "Hostname", &state->iphost, name );
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
hbox = makeLabeledField( "Relay port", &state->ipport, NULL );
if ( COMMS_CONN_IP_DIRECT == state->addr->conType ) {
char buf[16];
snprintf( buf, sizeof(buf), "%d", state->addr->u.ip.port_ip );
gtk_entry_set_text( GTK_ENTRY(state->ipport), buf );
}
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
return vbox;
}
#endif
static GtkWidget* static GtkWidget*
makeSMSPage( GtkConnsState* state ) makeSMSPage( GtkConnsState* state )
{ {
@ -279,6 +315,12 @@ gtkConnsDlg( GtkGameGlobals* globals, CommsAddrRec* addr, DeviceRole role,
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook), (void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
makeBTPage(&state), makeBTPage(&state),
gtk_label_new( "Bluetooth" ) ); gtk_label_new( "Bluetooth" ) );
#endif
#ifdef XWFEATURE_DIRECTIP
state.pageTypes[nTypes++] = COMMS_CONN_IP_DIRECT;
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
makeIPDirPage(&state),
gtk_label_new( "Direct" ) );
#endif #endif
state.pageTypes[nTypes++] = COMMS_CONN_SMS; state.pageTypes[nTypes++] = COMMS_CONN_SMS;
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook), (void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),

View file

@ -137,7 +137,7 @@ typedef struct LaunchParams {
bdaddr_t hostAddr; /* unused if a host */ bdaddr_t hostAddr; /* unused if a host */
} bt; } bt;
#endif #endif
#ifdef XWFEATURE_IP_DIRECT #if defined XWFEATURE_IP_DIRECT || defined XWFEATURE_DIRECTIP
struct { struct {
const char* hostName; const char* hostName;
int port; int port;

View file

@ -315,6 +315,9 @@ close_device() {
unset ROOMS[$ID] unset ROOMS[$ID]
unset APPS[$ID] unset APPS[$ID]
unset ARGS_DEVID[$ID] unset ARGS_DEVID[$ID]
COUNT=${#ARGS[*]}
echo "$COUNT devices left playing..."
} }
OBITS="" OBITS=""