mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
snapshot: relay test script works with a second address type set
(though with its actual transport stubbed out). Android doesn't even compile.
This commit is contained in:
parent
737af802b0
commit
fe4c7b52f2
10 changed files with 504 additions and 329 deletions
|
@ -153,7 +153,7 @@ struct CommsCtxt {
|
|||
MPSLOT
|
||||
};
|
||||
|
||||
#if defined XWFEATURE_IP_DIRECT
|
||||
#if defined XWFEATURE_IP_DIRECT || defined XWFEATURE_DIRECTIP
|
||||
typedef enum {
|
||||
BTIPMSG_NONE = 0
|
||||
,BTIPMSG_DATA
|
||||
|
@ -181,8 +181,6 @@ static void freeElem( const CommsCtxt* comms, MsgQueueElem* elem );
|
|||
|
||||
static XP_U16 countAddrRecs( const CommsCtxt* comms );
|
||||
static void sendConnect( CommsCtxt* comms, XP_Bool breakExisting );
|
||||
static XP_Bool addr_iter( const CommsAddrRec* addr, CommsConnType* typp,
|
||||
XP_U32* state );
|
||||
|
||||
#ifdef XWFEATURE_RELAY
|
||||
static XP_Bool relayConnect( CommsCtxt* comms );
|
||||
|
@ -211,9 +209,10 @@ static void setHeartbeatTimer( CommsCtxt* comms );
|
|||
#else
|
||||
# define setHeartbeatTimer( comms )
|
||||
#endif
|
||||
#if defined XWFEATURE_IP_DIRECT
|
||||
static XP_S16 send_via_bt_or_ip( CommsCtxt* comms, BTIPMsgType typ,
|
||||
#if defined XWFEATURE_IP_DIRECT || defined XWFEATURE_DIRECTIP
|
||||
static XP_S16 send_via_bt_or_ip( CommsCtxt* comms, BTIPMsgType msgTyp,
|
||||
XP_PlayerAddr channelNo,
|
||||
CommsConnType typ,
|
||||
void* data, int dlen );
|
||||
#endif
|
||||
|
||||
|
@ -457,7 +456,7 @@ comms_transportFailed( CommsCtxt* comms )
|
|||
{
|
||||
LOG_FUNC();
|
||||
XP_ASSERT( !!comms );
|
||||
if ( COMMS_CONN_RELAY == addr_getType(&comms->addr)
|
||||
if ( addr_hasType( &comms->addr, COMMS_CONN_RELAY )
|
||||
&& comms->rr.relayState != COMMS_RELAYSTATE_DENIED ) {
|
||||
relayDisconnect( comms );
|
||||
|
||||
|
@ -471,7 +470,7 @@ void
|
|||
comms_destroy( CommsCtxt* comms )
|
||||
{
|
||||
/* did I call comms_stop()? */
|
||||
XP_ASSERT( COMMS_CONN_RELAY != addr_getType(&comms->addr)
|
||||
XP_ASSERT( ! addr_hasType( &comms->addr, COMMS_CONN_RELAY )
|
||||
|| COMMS_RELAYSTATE_UNCONNECTED == comms->rr.relayState );
|
||||
|
||||
CommsAddrRec aNew = {0};
|
||||
|
@ -570,7 +569,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
|
|||
isServer = stream_getU8( stream );
|
||||
addrFromStream( &addr, stream );
|
||||
|
||||
if ( addr_getType( &addr ) == COMMS_CONN_RELAY ) {
|
||||
if ( addr_hasType( &addr, COMMS_CONN_RELAY ) ) {
|
||||
nPlayersHere = (XP_U16)stream_getBits( stream, 4 );
|
||||
nPlayersTotal = (XP_U16)stream_getBits( stream, 4 );
|
||||
} else {
|
||||
|
@ -597,7 +596,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
|
|||
comms->resendBackoff = stream_getU16( stream );
|
||||
comms->nextResend = stream_getU32( stream );
|
||||
}
|
||||
if ( addr_getType(&addr) == COMMS_CONN_RELAY ) {
|
||||
if ( addr_hasType(&addr, COMMS_CONN_RELAY ) ) {
|
||||
comms->rr.myHostID = stream_getU8( stream );
|
||||
stringFromStreamHere( stream, comms->rr.connName,
|
||||
sizeof(comms->rr.connName) );
|
||||
|
@ -618,7 +617,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
|
|||
rec->lastMsgAckd = stream_getU16( stream );
|
||||
}
|
||||
rec->channelNo = stream_getU16( stream );
|
||||
if ( addr_getType( &rec->addr ) == COMMS_CONN_RELAY ) {
|
||||
if ( addr_hasType( &rec->addr, COMMS_CONN_RELAY ) ) {
|
||||
rec->rr.hostID = stream_getU8( stream );
|
||||
}
|
||||
|
||||
|
@ -678,7 +677,7 @@ comms_start( CommsCtxt* comms )
|
|||
void
|
||||
comms_stop( CommsCtxt* comms )
|
||||
{
|
||||
if ( COMMS_CONN_RELAY == addr_getType( &comms->addr ) ) {
|
||||
if ( addr_hasType( &comms->addr, COMMS_CONN_RELAY ) ) {
|
||||
relayDisconnect( comms );
|
||||
}
|
||||
}
|
||||
|
@ -686,29 +685,34 @@ comms_stop( CommsCtxt* comms )
|
|||
static void
|
||||
sendConnect( CommsCtxt* comms, XP_Bool breakExisting )
|
||||
{
|
||||
switch( addr_getType( &comms->addr ) ) {
|
||||
// CommsAddrRec addr = comms->addr;
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( &comms->addr, &typ, &st ); ) {
|
||||
// addr._conTypes = typ;
|
||||
switch( typ ) {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
case COMMS_CONN_RELAY:
|
||||
if ( breakExisting
|
||||
|| COMMS_RELAYSTATE_UNCONNECTED == comms->rr.relayState ) {
|
||||
set_relay_state( comms, COMMS_RELAYSTATE_UNCONNECTED );
|
||||
if ( !relayConnect( comms ) ) {
|
||||
XP_LOGF( "%s: relayConnect failed", __func__ );
|
||||
set_reset_timer( comms );
|
||||
case COMMS_CONN_RELAY:
|
||||
if ( breakExisting
|
||||
|| COMMS_RELAYSTATE_UNCONNECTED == comms->rr.relayState ) {
|
||||
set_relay_state( comms, COMMS_RELAYSTATE_UNCONNECTED );
|
||||
if ( !relayConnect( comms ) ) {
|
||||
XP_LOGF( "%s: relayConnect failed", __func__ );
|
||||
set_reset_timer( comms );
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined XWFEATURE_IP_DIRECT || defined XWFEATURE_DIRECTIP
|
||||
case COMMS_CONN_BT:
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
/* This will only work on host side when there's a single guest! */
|
||||
(void)send_via_bt_or_ip( comms, BTIPMSG_RESET, CHANNEL_NONE, typ, NULL, 0 );
|
||||
(void)comms_resendAll( comms, XP_FALSE );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined XWFEATURE_IP_DIRECT
|
||||
case COMMS_CONN_BT:
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
/* This will only work on host side when there's a single guest! */
|
||||
(void)send_via_bt_or_ip( comms, BTIPMSG_RESET, CHANNEL_NONE, NULL, 0 );
|
||||
(void)comms_resendAll( comms, XP_FALSE );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
setHeartbeatTimer( comms );
|
||||
|
@ -773,7 +777,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
|||
|
||||
stream_putU8( stream, (XP_U8)comms->isServer );
|
||||
addrToStream( stream, &comms->addr );
|
||||
if ( COMMS_CONN_RELAY == addr_getType( &comms->addr ) ) {
|
||||
if ( addr_hasType( &comms->addr, COMMS_CONN_RELAY ) ) {
|
||||
stream_putBits( stream, 4, comms->rr.nPlayersHere );
|
||||
stream_putBits( stream, 4, comms->rr.nPlayersTotal );
|
||||
}
|
||||
|
@ -783,7 +787,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
|||
stream_putU16( stream, comms->channelSeed );
|
||||
stream_putU16( stream, comms->resendBackoff );
|
||||
stream_putU32( stream, comms->nextResend );
|
||||
if ( COMMS_CONN_RELAY == addr_getType( &comms->addr ) ) {
|
||||
if ( addr_hasType( &comms->addr, COMMS_CONN_RELAY ) ) {
|
||||
stream_putU8( stream, comms->rr.myHostID );
|
||||
stringToStream( stream, comms->rr.connName );
|
||||
}
|
||||
|
@ -803,7 +807,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
|||
stream_putU16( stream, (XP_U16)rec->lastMsgRcd );
|
||||
stream_putU16( stream, (XP_U16)rec->lastMsgAckd );
|
||||
stream_putU16( stream, rec->channelNo );
|
||||
if ( COMMS_CONN_RELAY == addr_getType( &rec->addr ) ) {
|
||||
if ( addr_hasType( &rec->addr, COMMS_CONN_RELAY ) ) {
|
||||
stream_putU8( stream, rec->rr.hostID ); /* unneeded unless RELAY */
|
||||
}
|
||||
}
|
||||
|
@ -952,7 +956,7 @@ comms_checkAddr( DeviceRole role, const CommsAddrRec* addr, XW_UtilCtxt* util )
|
|||
XP_Bool ok = XP_TRUE;
|
||||
/* make sure the user's given us enough information to make a connection */
|
||||
if ( role == SERVER_ISCLIENT ) {
|
||||
if ( COMMS_CONN_BT == addr_getType( addr ) ) {
|
||||
if ( addr_hasType( addr, COMMS_CONN_BT ) ) {
|
||||
XP_U32 empty = 0L; /* check four bytes to save some code */
|
||||
if ( !XP_MEMCMP( &empty, &addr->u.bt.btAddr, sizeof(empty) ) ) {
|
||||
ok = XP_FALSE;
|
||||
|
@ -965,12 +969,12 @@ comms_checkAddr( DeviceRole role, const CommsAddrRec* addr, XW_UtilCtxt* util )
|
|||
return ok;
|
||||
} /* comms_checkAddr */
|
||||
|
||||
CommsConnType
|
||||
comms_getConType( const CommsCtxt* comms )
|
||||
CommsConnTypes
|
||||
comms_getConTypes( const CommsCtxt* comms )
|
||||
{
|
||||
CommsConnType typ;
|
||||
if ( !!comms ) {
|
||||
typ = addr_getType( &comms->addr );
|
||||
typ = comms->addr._conTypes;
|
||||
} else {
|
||||
typ = COMMS_CONN_NONE;
|
||||
XP_LOGF( "%s: returning COMMS_CONN_NONE for null comms", __func__ );
|
||||
|
@ -1256,7 +1260,7 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
|
|||
XP_S16 result = -1;
|
||||
XP_PlayerAddr channelNo;
|
||||
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
||||
CommsConnType conType = comms_getConType( comms );
|
||||
// CommsConnType conType = comms_getConType( comms );
|
||||
#endif
|
||||
|
||||
channelNo = elem->channelNo;
|
||||
|
@ -1266,43 +1270,60 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
|
|||
elem->checksum );
|
||||
#endif
|
||||
|
||||
if ( 0 ) {
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( &comms->addr, &typ, &st ); ) {
|
||||
XP_LOGF( "%s: sending using typ %s", __func__, ConnType2Str(typ) );
|
||||
switch ( typ ) {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
} else if ( conType == COMMS_CONN_RELAY ) {
|
||||
XWHostID destID = getDestID( comms, channelNo );
|
||||
if ( haveRelayID( comms ) && sendNoConn( comms, elem, destID ) ) {
|
||||
/* do nothing */
|
||||
result = elem->len;
|
||||
} else if ( comms->rr.relayState >= COMMS_RELAYSTATE_CONNECTED ) {
|
||||
if ( send_via_relay( comms, XWRELAY_MSG_TORELAY, destID,
|
||||
elem->msg, elem->len ) ){
|
||||
case COMMS_CONN_RELAY: {
|
||||
XWHostID destID = getDestID( comms, channelNo );
|
||||
if ( haveRelayID( comms ) && sendNoConn( comms, elem, destID ) ) {
|
||||
/* do nothing */
|
||||
result = elem->len;
|
||||
} else if ( comms->rr.relayState >= COMMS_RELAYSTATE_CONNECTED ) {
|
||||
if ( send_via_relay( comms, XWRELAY_MSG_TORELAY, destID,
|
||||
elem->msg, elem->len ) ){
|
||||
result = elem->len;
|
||||
}
|
||||
} else {
|
||||
XP_LOGF( "%s: skipping message: not connected", __func__ );
|
||||
}
|
||||
} else {
|
||||
XP_LOGF( "%s: skipping message: not connected", __func__ );
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined XWFEATURE_IP_DIRECT
|
||||
} else if ( conType == COMMS_CONN_BT || conType == COMMS_CONN_IP_DIRECT ) {
|
||||
result = send_via_bt_or_ip( comms, BTIPMSG_DATA, channelNo,
|
||||
elem->msg, elem->len );
|
||||
case COMMS_CONN_BT:
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
result = send_via_ip( comms, BTIPMSG_DATA, channelNo,
|
||||
elem->msg, elem->len );
|
||||
#ifdef COMMS_HEARTBEAT
|
||||
setHeartbeatTimer( comms );
|
||||
setHeartbeatTimer( comms );
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
} else {
|
||||
CommsAddrRec addr;
|
||||
const CommsAddrRec* addrP;
|
||||
(void)channelToAddress( comms, channelNo, &addrP );
|
||||
default: {
|
||||
CommsAddrRec addr;
|
||||
const CommsAddrRec* addrP;
|
||||
(void)channelToAddress( comms, channelNo, &addrP );
|
||||
|
||||
if ( NULL == addrP ) {
|
||||
comms_getAddr( comms, &addr );
|
||||
addrP = &addr;
|
||||
if ( NULL == addrP ) {
|
||||
comms_getAddr( comms, &addr );
|
||||
} else {
|
||||
addr = *addrP;
|
||||
}
|
||||
|
||||
XP_U32 gameid = gameID( comms );
|
||||
XP_ASSERT( !!comms->procs.send );
|
||||
// addr._conTypes = 1 << (typ - 1);
|
||||
XP_S16 nSent = (*comms->procs.send)( elem->msg, elem->len, &addr,
|
||||
typ, gameid,
|
||||
comms->procs.closure );
|
||||
if ( nSent > result ) {
|
||||
result = nSent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
XP_ASSERT( !!comms->procs.send );
|
||||
result = (*comms->procs.send)( elem->msg, elem->len, addrP,
|
||||
gameID(comms), comms->procs.closure );
|
||||
} /* switch */
|
||||
}
|
||||
|
||||
if ( result == elem->len ) {
|
||||
|
@ -1677,25 +1698,28 @@ preProcess( CommsCtxt* comms, XWStreamCtxt* stream,
|
|||
XWHostID* XP_UNUSED_RELAY(senderID) )
|
||||
{
|
||||
XP_Bool consumed = XP_FALSE;
|
||||
switch ( addr_getType( &comms->addr ) ) {
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( &comms->addr, &typ, &st ); ) {
|
||||
switch ( typ ) {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
/* relayPreProcess returns true if consumes the message. May just eat the
|
||||
header and leave a regular message to be processed below. */
|
||||
case COMMS_CONN_RELAY:
|
||||
consumed = relayPreProcess( comms, stream, senderID );
|
||||
if ( !consumed ) {
|
||||
*usingRelay = COMMS_CONN_RELAY == addr_getType( &comms->addr );
|
||||
}
|
||||
break;
|
||||
/* relayPreProcess returns true if consumes the message. May just eat the
|
||||
header and leave a regular message to be processed below. */
|
||||
case COMMS_CONN_RELAY:
|
||||
consumed = relayPreProcess( comms, stream, senderID );
|
||||
if ( !consumed ) {
|
||||
*usingRelay = addr_hasType( &comms->addr, COMMS_CONN_RELAY );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined XWFEATURE_IP_DIRECT
|
||||
case COMMS_CONN_BT:
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
consumed = btIpPreProcess( comms, stream );
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
consumed = btIpPreProcess( comms, stream );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
LOG_RETURNF( "%d", consumed );
|
||||
return consumed;
|
||||
|
@ -2213,7 +2237,8 @@ rememberChannelAddress( CommsCtxt* comms, XP_PlayerAddr channelNo,
|
|||
XP_ASSERT( recs->rr.hostID == hostID );
|
||||
} else {
|
||||
XP_MEMSET( &recs->addr, 0, sizeof(recs->addr) );
|
||||
addr_setType( &recs->addr, addr_getType( &comms->addr ) );
|
||||
recs->addr._conTypes = comms->addr._conTypes;
|
||||
// addr_setTypes( &recs->addr, addr_getTypes( &comms->addr ) );
|
||||
}
|
||||
}
|
||||
return recs;
|
||||
|
@ -2249,7 +2274,7 @@ countAddrRecs( const CommsCtxt* comms )
|
|||
return count;
|
||||
} /* countAddrRecs */
|
||||
|
||||
static XP_Bool
|
||||
XP_Bool
|
||||
addr_iter( const CommsAddrRec* addr, CommsConnType* typp, XP_U32* state )
|
||||
{
|
||||
CommsConnType typ = *state;
|
||||
|
@ -2269,6 +2294,13 @@ addr_iter( const CommsAddrRec* addr, CommsConnType* typp, XP_U32* state )
|
|||
return found;
|
||||
}
|
||||
|
||||
XP_Bool
|
||||
addr_hasType( const CommsAddrRec* addr, CommsConnType type )
|
||||
{
|
||||
XP_ASSERT( COMMS_CONN_NONE != type );
|
||||
return 0 != (addr->_conTypes & (1 << (type - 1)));
|
||||
}
|
||||
|
||||
CommsConnType
|
||||
addr_getType( const CommsAddrRec* addr )
|
||||
{
|
||||
|
@ -2278,15 +2310,27 @@ addr_getType( const CommsAddrRec* addr )
|
|||
typ = COMMS_CONN_NONE;
|
||||
}
|
||||
XP_ASSERT( !addr_iter( addr, &typ, &st ) ); /* shouldn't be a second -- yet */
|
||||
LOG_RETURNF( "%s", ConnType2Str( typ ) );
|
||||
XP_LOGF( "%s(%p) => %s", __func__, addr, ConnType2Str( typ ) );
|
||||
return typ;
|
||||
}
|
||||
|
||||
void
|
||||
addr_addType( CommsAddrRec* addr, CommsConnType type )
|
||||
{
|
||||
XP_ASSERT( COMMS_CONN_NONE != type );
|
||||
addr->_conTypes |= 1 << (type - 1);
|
||||
}
|
||||
|
||||
/* Set of NONE is ok, but for anything else it's illegal to be adding a second
|
||||
bit. Use addr_addType() for that. */
|
||||
void
|
||||
addr_setType( CommsAddrRec* addr, CommsConnType type )
|
||||
{
|
||||
XP_LOGF( "%s(%p, %s)", __func__, addr, ConnType2Str(type) );
|
||||
XP_U16 flags = 0;
|
||||
if ( COMMS_CONN_NONE != type ) {
|
||||
XP_ASSERT( COMMS_CONN_NONE == addr_getType( addr ) ||
|
||||
type == addr_getType( addr ) );
|
||||
flags = 1 << (type - 1);
|
||||
}
|
||||
addr->_conTypes = flags;
|
||||
|
@ -2427,8 +2471,8 @@ send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd, XWHostID destID,
|
|||
|
||||
comms_getAddr( comms, &addr );
|
||||
XP_LOGF( "%s: passing %d bytes to sendproc", __func__, len );
|
||||
result = (*comms->procs.send)( stream_getPtr(tmpStream), len,
|
||||
&addr, gameID(comms),
|
||||
result = (*comms->procs.send)( stream_getPtr(tmpStream), len, &addr,
|
||||
COMMS_CONN_RELAY, gameID(comms),
|
||||
comms->procs.closure );
|
||||
success = result == len;
|
||||
if ( success ) {
|
||||
|
@ -2479,7 +2523,7 @@ relayConnect( CommsCtxt* comms )
|
|||
{
|
||||
XP_Bool success = XP_TRUE;
|
||||
LOG_FUNC();
|
||||
if ( addr_getType( &comms->addr ) == COMMS_CONN_RELAY && !comms->rr.connecting ) {
|
||||
if ( addr_hasType( &comms->addr, COMMS_CONN_RELAY ) && !comms->rr.connecting ) {
|
||||
comms->rr.connecting = XP_TRUE;
|
||||
success = send_via_relay( comms, comms->rr.connName[0]?
|
||||
XWRELAY_GAME_RECONNECT : XWRELAY_GAME_CONNECT,
|
||||
|
@ -2490,10 +2534,10 @@ relayConnect( CommsCtxt* comms )
|
|||
} /* relayConnect */
|
||||
#endif
|
||||
|
||||
#if defined XWFEATURE_IP_DIRECT
|
||||
#if defined XWFEATURE_IP_DIRECT || defined XWFEATURE_DIRECTIP
|
||||
static XP_S16
|
||||
send_via_bt_or_ip( CommsCtxt* comms, BTIPMsgType typ, XP_PlayerAddr channelNo,
|
||||
void* data, int dlen )
|
||||
send_via_bt_or_ip( CommsCtxt* comms, BTIPMsgType msgTyp, XP_PlayerAddr channelNo,
|
||||
CommsConnType typ, void* data, int dlen )
|
||||
{
|
||||
XP_S16 nSent;
|
||||
XP_U8* buf;
|
||||
|
@ -2504,12 +2548,12 @@ send_via_bt_or_ip( CommsCtxt* comms, BTIPMsgType typ, XP_PlayerAddr channelNo,
|
|||
const CommsAddrRec* addr;
|
||||
(void)channelToAddress( comms, channelNo, &addr );
|
||||
|
||||
buf[0] = typ;
|
||||
buf[0] = msgTyp;
|
||||
if ( dlen > 0 ) {
|
||||
XP_MEMCPY( &buf[1], data, dlen );
|
||||
}
|
||||
|
||||
nSent = (*comms->procs.send)( buf, dlen+1, addr, gameID(comms),
|
||||
nSent = (*comms->procs.send)( buf, dlen+1, addr, typ, gameID(comms),
|
||||
comms->procs.closure );
|
||||
XP_FREE( comms->mpool, buf );
|
||||
|
||||
|
@ -2526,7 +2570,7 @@ static void
|
|||
relayDisconnect( CommsCtxt* comms )
|
||||
{
|
||||
LOG_FUNC();
|
||||
if ( addr_getType( &comms->addr ) == COMMS_CONN_RELAY ) {
|
||||
if ( addr_hasType( &comms->addr, COMMS_CONN_RELAY ) ) {
|
||||
if ( comms->rr.relayState > COMMS_RELAYSTATE_CONNECT_PENDING ) {
|
||||
(void)send_via_relay( comms, XWRELAY_GAME_DISCONNECT, HOST_ID_NONE,
|
||||
NULL, 0 );
|
||||
|
|
|
@ -45,6 +45,8 @@ typedef enum {
|
|||
,COMMS_CONN_NTYPES
|
||||
} CommsConnType;
|
||||
|
||||
typedef XP_U8 CommsConnTypes;
|
||||
|
||||
typedef enum {
|
||||
COMMS_RELAYSTATE_UNCONNECTED
|
||||
, COMMS_RELAYSTATE_DENIED /* terminal; new game or reset required to
|
||||
|
@ -110,6 +112,7 @@ typedef struct _CommsAddrRec {
|
|||
|
||||
typedef XP_S16 (*TransportSend)( const XP_U8* buf, XP_U16 len,
|
||||
const CommsAddrRec* addr,
|
||||
CommsConnType conType,
|
||||
XP_U32 gameID, void* closure );
|
||||
#ifdef COMMS_HEARTBEAT
|
||||
typedef void (*TransportReset)( void* closure );
|
||||
|
@ -193,7 +196,7 @@ XP_U16 comms_countPendingPackets( const CommsCtxt* comms );
|
|||
XP_Bool comms_getRelayID( const CommsCtxt* comms, XP_UCHAR* buf, XP_U16* len );
|
||||
#endif
|
||||
|
||||
CommsConnType comms_getConType( const CommsCtxt* comms );
|
||||
CommsConnTypes comms_getConTypes( const CommsCtxt* comms );
|
||||
XP_Bool comms_getIsServer( const CommsCtxt* comms );
|
||||
|
||||
CommsCtxt* comms_makeFromStream( MPFORMAL XWStreamCtxt* stream,
|
||||
|
@ -223,6 +226,10 @@ XP_Bool comms_isConnected( const CommsCtxt* const comms );
|
|||
|
||||
CommsConnType addr_getType( const CommsAddrRec* addr );
|
||||
void addr_setType( CommsAddrRec* addr, CommsConnType type );
|
||||
void addr_addType( CommsAddrRec* addr, CommsConnType type );
|
||||
XP_Bool addr_hasType( const CommsAddrRec* addr, CommsConnType type );
|
||||
XP_Bool addr_iter( const CommsAddrRec* addr, CommsConnType* typp,
|
||||
XP_U32* state );
|
||||
|
||||
|
||||
# ifdef DEBUG
|
||||
|
|
|
@ -380,7 +380,7 @@ informMissing( const ServerCtxt* server )
|
|||
{
|
||||
XP_Bool isServer = amServer( server );
|
||||
util_informMissing( server->vol.util, isServer,
|
||||
comms_getConType( server->vol.comms ),
|
||||
comms_getConTypes( server->vol.comms ),
|
||||
isServer ? server->nv.pendingRegistrations : 0 );
|
||||
}
|
||||
|
||||
|
|
|
@ -981,6 +981,7 @@ cursesListenOnSocket( CursesAppGlobals* globals, int newSock
|
|||
#ifdef USE_GLIBLOOP
|
||||
GIOChannel* channel = g_io_channel_unix_new( newSock );
|
||||
XP_LOGF( "%s: created channel %p for socket %d", __func__, channel, newSock );
|
||||
XP_ASSERT( !!func );
|
||||
guint watch = g_io_add_watch( channel,
|
||||
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
|
||||
func, globals );
|
||||
|
@ -1040,6 +1041,7 @@ curses_stop_listening( CursesAppGlobals* globals, int sock )
|
|||
} /* curses_stop_listening */
|
||||
|
||||
#ifdef USE_GLIBLOOP
|
||||
#if 0
|
||||
static gboolean
|
||||
data_socket_proc( GIOChannel* source, GIOCondition condition, gpointer data )
|
||||
{
|
||||
|
@ -1054,30 +1056,43 @@ data_socket_proc( GIOChannel* source, GIOCondition condition, gpointer data )
|
|||
int nBytes;
|
||||
// CommsAddrRec addrRec;
|
||||
CommsAddrRec* addrp = NULL;
|
||||
// XP_Bool oneSent = XP_FALSE;
|
||||
|
||||
/* It's a normal data socket */
|
||||
switch ( globals->cGlobals.params->conType ) {
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0;
|
||||
addr_iter( &globals->cGlobals.params->addr, &typ, &st ); ) {
|
||||
switch ( typ ) {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
case COMMS_CONN_RELAY:
|
||||
nBytes = linux_relay_receive( &globals->cGlobals, buf,
|
||||
sizeof(buf) );
|
||||
break;
|
||||
case COMMS_CONN_RELAY:
|
||||
nBytes = linux_relay_receive( &globals->cGlobals, buf,
|
||||
sizeof(buf) );
|
||||
break;
|
||||
#endif
|
||||
#ifdef XWFEATURE_SMS
|
||||
case COMMS_CONN_SMS:
|
||||
XP_ASSERT(0);
|
||||
/* addrp = &addrRec; */
|
||||
/* nBytes = linux_sms_receive( &globals->cGlobals, fd, */
|
||||
/* buf, sizeof(buf), addrp ); */
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
XP_ASSERT(0);
|
||||
/* addrp = &addrRec; */
|
||||
/* nBytes = linux_sms_receive( &globals->cGlobals, fd, */
|
||||
/* buf, sizeof(buf), addrp ); */
|
||||
break;
|
||||
#endif
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
case COMMS_CONN_BT:
|
||||
nBytes = linux_bt_receive( fd, buf, sizeof(buf) );
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
nBytes = linux_bt_receive( fd, buf, sizeof(buf) );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
XP_ASSERT( 0 ); /* fired */
|
||||
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
XP_LOGF( "OOPS: need separate data procs per address type!!" );
|
||||
XP_ASSERT( 0 );
|
||||
break;
|
||||
case COMMS_CONN_NONE:
|
||||
break;
|
||||
|
||||
default:
|
||||
XP_ASSERT( 0 ); /* fired */
|
||||
}
|
||||
}
|
||||
|
||||
if ( nBytes != -1 ) {
|
||||
|
@ -1106,10 +1121,11 @@ data_socket_proc( GIOChannel* source, GIOCondition condition, gpointer data )
|
|||
return keep;
|
||||
} /* data_socket_proc */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void
|
||||
curses_socket_changed( void* closure, int oldSock, int newSock,
|
||||
void** XP_UNUSED(storage) )
|
||||
GIOFunc func, void** XP_UNUSED(storage) )
|
||||
{
|
||||
CursesAppGlobals* globals = (CursesAppGlobals*)closure;
|
||||
if ( oldSock != -1 ) {
|
||||
|
@ -1118,7 +1134,7 @@ curses_socket_changed( void* closure, int oldSock, int newSock,
|
|||
if ( newSock != -1 ) {
|
||||
cursesListenOnSocket( globals, newSock
|
||||
#ifdef USE_GLIBLOOP
|
||||
, data_socket_proc
|
||||
, func
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
@ -1971,7 +1987,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
|||
initFromParams( &g_globals.cGlobals, params );
|
||||
|
||||
#ifdef XWFEATURE_RELAY
|
||||
if ( params->conType == COMMS_CONN_RELAY ) {
|
||||
if ( addr_hasType( ¶ms->addr, COMMS_CONN_RELAY ) ) {
|
||||
g_globals.cGlobals.defaultServerName
|
||||
= params->connInfo.relay.relayName;
|
||||
}
|
||||
|
@ -2128,34 +2144,50 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
|||
if ( cGlobals->game.comms ) {
|
||||
CommsAddrRec addr = {0};
|
||||
|
||||
if ( 0 ) {
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( ¶ms->addr, &typ, &st ); ) {
|
||||
switch( typ ) {
|
||||
# ifdef XWFEATURE_RELAY
|
||||
} else if ( params->conType == COMMS_CONN_RELAY ) {
|
||||
addr_setType( &addr, COMMS_CONN_RELAY );
|
||||
addr.u.ip_relay.ipAddr = 0; /* ??? */
|
||||
addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort;
|
||||
addr.u.ip_relay.seeksPublicRoom = params->connInfo.relay.seeksPublicRoom;
|
||||
addr.u.ip_relay.advertiseRoom = params->connInfo.relay.advertiseRoom;
|
||||
XP_STRNCPY( addr.u.ip_relay.hostName, params->connInfo.relay.relayName,
|
||||
sizeof(addr.u.ip_relay.hostName) - 1 );
|
||||
XP_STRNCPY( addr.u.ip_relay.invite, params->connInfo.relay.invite,
|
||||
sizeof(addr.u.ip_relay.invite) - 1 );
|
||||
case COMMS_CONN_RELAY:
|
||||
addr_addType( &addr, COMMS_CONN_RELAY );
|
||||
addr.u.ip_relay.ipAddr = 0; /* ??? */
|
||||
addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort;
|
||||
addr.u.ip_relay.seeksPublicRoom = params->connInfo.relay.seeksPublicRoom;
|
||||
addr.u.ip_relay.advertiseRoom = params->connInfo.relay.advertiseRoom;
|
||||
XP_STRNCPY( addr.u.ip_relay.hostName, params->connInfo.relay.relayName,
|
||||
sizeof(addr.u.ip_relay.hostName) - 1 );
|
||||
XP_STRNCPY( addr.u.ip_relay.invite, params->connInfo.relay.invite,
|
||||
sizeof(addr.u.ip_relay.invite) - 1 );
|
||||
break;
|
||||
# endif
|
||||
# ifdef XWFEATURE_SMS
|
||||
} else if ( params->conType == COMMS_CONN_SMS ) {
|
||||
addr_setType( &addr, COMMS_CONN_SMS );
|
||||
XP_STRNCPY( addr.u.sms.phone, params->connInfo.sms.phone,
|
||||
sizeof(addr.u.sms.phone) - 1 );
|
||||
addr.u.sms.port = params->connInfo.sms.port;
|
||||
case COMMS_CONN_SMS:
|
||||
addr_addType( &addr, COMMS_CONN_SMS );
|
||||
XP_STRNCPY( addr.u.sms.phone, params->connInfo.sms.phone,
|
||||
sizeof(addr.u.sms.phone) - 1 );
|
||||
addr.u.sms.port = params->connInfo.sms.port;
|
||||
break;
|
||||
# endif
|
||||
# ifdef XWFEATURE_BLUETOOTH
|
||||
} else if ( params->conType == COMMS_CONN_BT ) {
|
||||
addr_setType( &addr, COMMS_CONN_BT );
|
||||
XP_ASSERT( sizeof(addr.u.bt.btAddr)
|
||||
>= sizeof(params->connInfo.bt.hostAddr));
|
||||
XP_MEMCPY( &addr.u.bt.btAddr, ¶ms->connInfo.bt.hostAddr,
|
||||
sizeof(params->connInfo.bt.hostAddr) );
|
||||
case COMMS_CONN_BT:
|
||||
addr_addType( &addr, COMMS_CONN_BT );
|
||||
XP_ASSERT( sizeof(addr.u.bt.btAddr)
|
||||
>= sizeof(params->connInfo.bt.hostAddr));
|
||||
XP_MEMCPY( &addr.u.bt.btAddr, ¶ms->connInfo.bt.hostAddr,
|
||||
sizeof(params->connInfo.bt.hostAddr) );
|
||||
break;
|
||||
# endif
|
||||
#ifdef XWFEATURE_DIRECTIP
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
addr_addType( &addr, COMMS_CONN_IP_DIRECT );
|
||||
XP_MEMCPY( addr.u.ip.hostName_ip, ¶ms->connInfo.ip.hostName,
|
||||
sizeof(addr.u.ip.hostName_ip) );
|
||||
addr.u.ip.port_ip = params->connInfo.ip.hostPort;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
comms_setAddr( cGlobals->game.comms, &addr );
|
||||
}
|
||||
|
|
|
@ -130,27 +130,36 @@ summarize( CommonGlobals* cGlobals )
|
|||
CommsAddrRec addr = {0};
|
||||
gchar* room = "";
|
||||
|
||||
gchar* connvia = "local";
|
||||
// gchar* connvia = "local";
|
||||
gchar connvia[128] = {0};
|
||||
|
||||
if ( !!cGlobals->game.comms ) {
|
||||
nMissing = server_getMissingPlayers( cGlobals->game.server );
|
||||
comms_getAddr( cGlobals->game.comms, &addr );
|
||||
switch( addr_getType( &addr ) ) {
|
||||
case COMMS_CONN_RELAY:
|
||||
room = addr.u.ip_relay.invite;
|
||||
connvia = "Relay";
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
connvia = "SMS";
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
connvia = "Bluetooth";
|
||||
break;
|
||||
default:
|
||||
// XP_ASSERT(0);
|
||||
break;
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) {
|
||||
switch( typ) {
|
||||
case COMMS_CONN_RELAY:
|
||||
room = addr.u.ip_relay.invite;
|
||||
strcat( connvia, ", Relay" );
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
strcat( connvia, ", SMS" );
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
strcat( connvia, ", Bluetooth" );
|
||||
break;
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
strcat( connvia, ", IP" );
|
||||
break;
|
||||
default:
|
||||
XP_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
seed = comms_getChannelSeed( cGlobals->game.comms );
|
||||
} else {
|
||||
strcat( connvia, "local" );
|
||||
}
|
||||
|
||||
const char* fmt = "UPDATE games "
|
||||
|
|
|
@ -1476,33 +1476,37 @@ handle_invite_button( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
|
|||
CommsCtxt* comms = globals->cGlobals.game.comms;
|
||||
XP_ASSERT( comms );
|
||||
comms_getAddr( comms, &addr );
|
||||
switch ( comms_getConType( comms ) ) {
|
||||
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) {
|
||||
switch ( typ ) {
|
||||
#ifdef XWFEATURE_SMS
|
||||
case COMMS_CONN_SMS: {
|
||||
gchar* phone = NULL;
|
||||
gchar* portstr = NULL;
|
||||
AskMInfo infos[] = {
|
||||
{ "Remote phone#", &phone },
|
||||
{ "Remote port", &portstr },
|
||||
};
|
||||
if ( gtkaskm( "Invite whom?", infos, VSIZE(infos) ) ) {
|
||||
int port = atoi( portstr );
|
||||
XP_LOGF( "need to invite using number %s and port %d", phone, port );
|
||||
XP_ASSERT( 0 != port );
|
||||
const CurGameInfo* gi = globals->cGlobals.gi;
|
||||
gchar gameName[64];
|
||||
snprintf( gameName, VSIZE(gameName), "Game %d", gi->gameID );
|
||||
linux_sms_invite( globals->cGlobals.params, gi, gameName, 1,
|
||||
phone, port );
|
||||
case COMMS_CONN_SMS: {
|
||||
gchar* phone = NULL;
|
||||
gchar* portstr = NULL;
|
||||
AskMInfo infos[] = {
|
||||
{ "Remote phone#", &phone },
|
||||
{ "Remote port", &portstr },
|
||||
};
|
||||
if ( gtkaskm( "Invite whom?", infos, VSIZE(infos) ) ) {
|
||||
int port = atoi( portstr );
|
||||
XP_LOGF( "need to invite using number %s and port %d", phone, port );
|
||||
XP_ASSERT( 0 != port );
|
||||
const CurGameInfo* gi = globals->cGlobals.gi;
|
||||
gchar gameName[64];
|
||||
snprintf( gameName, VSIZE(gameName), "Game %d", gi->gameID );
|
||||
linux_sms_invite( globals->cGlobals.params, gi, gameName, 1,
|
||||
phone, port );
|
||||
}
|
||||
g_free( phone );
|
||||
g_free( portstr );
|
||||
}
|
||||
g_free( phone );
|
||||
g_free( portstr );
|
||||
}
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
XP_ASSERT( 0 );
|
||||
break;
|
||||
default:
|
||||
XP_ASSERT( 0 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* handle_commit_button */
|
||||
|
||||
|
@ -2284,6 +2288,7 @@ setupGtkUtilCallbacks( GtkGameGlobals* globals, XW_UtilCtxt* util )
|
|||
} /* setupGtkUtilCallbacks */
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
#if 0
|
||||
static gboolean
|
||||
newConnectionInput( GIOChannel *source,
|
||||
GIOCondition condition,
|
||||
|
@ -2379,7 +2384,7 @@ newConnectionInput( GIOChannel *source,
|
|||
#endif
|
||||
if ( 0 ) {
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
} else if ( COMMS_CONN_BT == globals->cGlobals.params->conType ) {
|
||||
} else if ( COMMS_CONN_BT == addr_getType( &globals->cGlobals.params->addr ) ) {
|
||||
linux_bt_socketclosed( &globals->cGlobals, sock );
|
||||
#endif
|
||||
#ifdef XWFEATURE_IP_DIRECT
|
||||
|
@ -2392,6 +2397,7 @@ newConnectionInput( GIOChannel *source,
|
|||
|
||||
return keepSource; /* FALSE means to remove event source */
|
||||
} /* newConnectionInput */
|
||||
#endif
|
||||
|
||||
typedef struct _SockInfo {
|
||||
GIOChannel* channel;
|
||||
|
@ -2400,7 +2406,8 @@ typedef struct _SockInfo {
|
|||
} SockInfo;
|
||||
|
||||
static void
|
||||
gtk_socket_changed( void* closure, int oldSock, int newSock, void** storage )
|
||||
gtk_socket_changed( void* closure, int oldSock, int newSock, GIOFunc proc,
|
||||
void** storage )
|
||||
{
|
||||
GtkGameGlobals* globals = (GtkGameGlobals*)closure;
|
||||
SockInfo* info = (SockInfo*)*storage;
|
||||
|
@ -2416,14 +2423,14 @@ gtk_socket_changed( void* closure, int oldSock, int newSock, void** storage )
|
|||
oldSock );
|
||||
}
|
||||
if ( newSock != -1 ) {
|
||||
XP_ASSERT( !!proc );
|
||||
info = (SockInfo*)XP_MALLOC( globals->cGlobals.util->mpool,
|
||||
sizeof(*info) );
|
||||
GIOChannel* channel = g_io_channel_unix_new( newSock );
|
||||
g_io_channel_set_close_on_unref( channel, TRUE );
|
||||
guint result = g_io_add_watch( channel,
|
||||
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI,
|
||||
newConnectionInput,
|
||||
globals );
|
||||
proc, globals );
|
||||
info->channel = channel;
|
||||
info->watch = result;
|
||||
*storage = info;
|
||||
|
@ -2434,7 +2441,10 @@ gtk_socket_changed( void* closure, int oldSock, int newSock, void** storage )
|
|||
#endif
|
||||
/* A hack for the bluetooth case. */
|
||||
CommsCtxt* comms = globals->cGlobals.game.comms;
|
||||
if ( (comms != NULL) && (comms_getConType(comms) == COMMS_CONN_BT) ) {
|
||||
|
||||
CommsAddrRec addr;
|
||||
comms_getAddr( comms, &addr );
|
||||
if ( (comms != NULL) && (addr_hasType( &addr, COMMS_CONN_BT) ) ) {
|
||||
comms_resendAll( comms, XP_FALSE );
|
||||
}
|
||||
LOG_RETURN_VOID();
|
||||
|
|
|
@ -70,6 +70,9 @@ typedef struct LinBtStuff {
|
|||
XP_Bool amMaster;
|
||||
} LinBtStuff;
|
||||
|
||||
static gboolean bt_socket_proc( GIOChannel* source, GIOCondition condition,
|
||||
gpointer data );
|
||||
|
||||
static LinBtStuff*
|
||||
lbt_make( MPFORMAL XP_Bool amMaster )
|
||||
{
|
||||
|
@ -184,8 +187,8 @@ lbt_connectSocket( LinBtStuff* btStuff, const CommsAddrRec* addrP )
|
|||
// connect to server
|
||||
&& (0 == connect( sock, (struct sockaddr *)&saddr, sizeof(saddr) )) ) {
|
||||
CommonGlobals* globals = btStuff->globals;
|
||||
(*globals->socketChanged)( globals->socketChangedClosure,
|
||||
-1, sock, &btStuff->sockStorage );
|
||||
(*globals->socketChanged)( globals->socketChangedClosure, -1, sock,
|
||||
bt_socket_proc, &btStuff->sockStorage );
|
||||
btStuff->socket = sock;
|
||||
} else {
|
||||
XP_LOGF( "%s: connect->%s; closing socket %d", __func__, strerror(errno), sock );
|
||||
|
@ -214,8 +217,8 @@ lbt_accept( int listener, void* ctxt )
|
|||
|
||||
success = sock >= 0;
|
||||
if ( success ) {
|
||||
(*globals->socketChanged)( globals->socketChangedClosure,
|
||||
-1, sock, &btStuff->sockStorage );
|
||||
(*globals->socketChanged)( globals->socketChangedClosure, -1, sock,
|
||||
bt_socket_proc, &btStuff->sockStorage );
|
||||
XP_ASSERT( btStuff->socket == -1 );
|
||||
btStuff->socket = sock;
|
||||
} else {
|
||||
|
@ -411,7 +414,8 @@ linux_bt_close( CommonGlobals* globals )
|
|||
|
||||
if ( btStuff->socket != -1 ) {
|
||||
(*globals->socketChanged)( globals->socketChangedClosure,
|
||||
btStuff->socket, -1, &btStuff->sockStorage );
|
||||
btStuff->socket, -1, NULL,
|
||||
&btStuff->sockStorage );
|
||||
(void)close( btStuff->socket );
|
||||
}
|
||||
|
||||
|
@ -603,4 +607,21 @@ linux_bt_scan()
|
|||
return list;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
bt_socket_proc( GIOChannel* source, GIOCondition condition, gpointer data )
|
||||
{
|
||||
XP_USE( data );
|
||||
int fd = g_io_channel_unix_get_fd( source );
|
||||
if ( 0 != (G_IO_IN & condition) ) {
|
||||
unsigned char buf[1024];
|
||||
XP_S16 nBytes = linux_bt_receive( fd, buf, sizeof(buf) );
|
||||
XP_ASSERT(nBytes==2 || XP_TRUE);
|
||||
|
||||
XP_ASSERT(0); /* not implemented beyond this point */
|
||||
} else {
|
||||
XP_ASSERT(0); /* not implemented beyond this point */
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif /* XWFEATURE_BLUETOOTH */
|
||||
|
|
|
@ -582,6 +582,8 @@ typedef enum {
|
|||
,CMD_SKIP_GAMEOVER
|
||||
,CMD_SHOW_OTHERSCORES
|
||||
,CMD_HOSTIP
|
||||
,CMD_HOSTPORT
|
||||
,CMD_MYPORT
|
||||
,CMD_DICT
|
||||
#ifdef XWFEATURE_WALKDICT
|
||||
,CMD_TESTDICT
|
||||
|
@ -613,7 +615,7 @@ typedef enum {
|
|||
,CMD_PICKTILESFACEUP
|
||||
,CMD_PLAYERNAME
|
||||
,CMD_REMOTEPLAYER
|
||||
,CMD_PORT
|
||||
,CMD_RELAY_PORT
|
||||
,CMD_ROBOTNAME
|
||||
,CMD_LOCALSMARTS
|
||||
,CMD_SORTNEW
|
||||
|
@ -684,7 +686,9 @@ static CmdInfoRec CmdInfoRecs[] = {
|
|||
{ CMD_HELP, false, "help", "print this message" }
|
||||
,{ CMD_SKIP_GAMEOVER, false, "skip-final", "skip final scores display" }
|
||||
,{ CMD_SHOW_OTHERSCORES, false, "show-other", "show robot/remote scores" }
|
||||
,{ CMD_HOSTIP, true, "hostip", "remote host ip address (for direct connect)" }
|
||||
,{ CMD_HOSTIP, true, "host-ip", "remote host ip address (for direct connect)" }
|
||||
,{ CMD_HOSTPORT, true, "host-port", "remote host ip address (for direct connect)" }
|
||||
,{ CMD_MYPORT, true, "my-port", "remote host ip address (for direct connect)" }
|
||||
,{ CMD_DICT, true, "game-dict", "dictionary name for game" }
|
||||
#ifdef XWFEATURE_WALKDICT
|
||||
,{ CMD_TESTDICT, true, "test-dict", "dictionary to be used for iterator test" }
|
||||
|
@ -720,7 +724,7 @@ static CmdInfoRec CmdInfoRecs[] = {
|
|||
,{ CMD_PICKTILESFACEUP, false, "pick-face-up", "allow to pick tiles" }
|
||||
,{ CMD_PLAYERNAME, true, "name", "name of local, non-robot player" }
|
||||
,{ CMD_REMOTEPLAYER, false, "remote-player", "add an expected player" }
|
||||
,{ CMD_PORT, true, "port", "port to connect to on host" }
|
||||
,{ CMD_RELAY_PORT, true, "relay-port", "port to connect to on relay" }
|
||||
,{ CMD_ROBOTNAME, true, "robot", "name of local, robot player" }
|
||||
,{ CMD_LOCALSMARTS, true, "robot-iq", "smarts for robot (in sequence)" }
|
||||
,{ CMD_SORTNEW, false, "sort-tiles", "sort tiles each time assigned" }
|
||||
|
@ -1004,7 +1008,7 @@ send_or_close( CommonGlobals* cGlobals, const XP_U8* buf, size_t len )
|
|||
close( cGlobals->relaySocket );
|
||||
(*cGlobals->socketChanged)( cGlobals->socketChangedClosure,
|
||||
cGlobals->relaySocket, -1,
|
||||
&cGlobals->storage );
|
||||
NULL, &cGlobals->storage );
|
||||
cGlobals->relaySocket = -1;
|
||||
|
||||
/* delete all pending packets since the socket's bad */
|
||||
|
@ -1074,8 +1078,50 @@ send_per_params( const XP_U8* buf, const XP_U16 buflen,
|
|||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
linux_relay_ioproc( GIOChannel* source, GIOCondition condition, gpointer data )
|
||||
{
|
||||
gboolean keep = TRUE;
|
||||
if ( 0 != ((G_IO_HUP|G_IO_ERR|G_IO_NVAL) & condition) ) {
|
||||
XP_LOGF( "%s: got error condition; returning FALSE", __func__ );
|
||||
keep = FALSE;
|
||||
} else if ( 0 != (G_IO_IN & condition) ) {
|
||||
CommonGlobals* cGlobals = (CommonGlobals*)data;
|
||||
unsigned char buf[1024];
|
||||
XP_ASSERT( cGlobals->relaySocket == g_io_channel_unix_get_fd( source ) );
|
||||
|
||||
int nBytes = linux_relay_receive( cGlobals, buf, sizeof(buf) );
|
||||
|
||||
if ( nBytes != -1 ) {
|
||||
XWStreamCtxt* inboundS;
|
||||
XP_Bool redraw = XP_FALSE;
|
||||
|
||||
inboundS = stream_from_msgbuf( cGlobals, buf, nBytes );
|
||||
if ( !!inboundS ) {
|
||||
CommsAddrRec* addrp = NULL;
|
||||
if ( comms_checkIncomingStream( cGlobals->game.comms,
|
||||
inboundS, addrp ) ) {
|
||||
redraw = server_receiveMessage( cGlobals->game.server,
|
||||
inboundS );
|
||||
}
|
||||
stream_destroy( inboundS );
|
||||
}
|
||||
|
||||
/* if there's something to draw resulting from the
|
||||
message, we need to give the main loop time to reflect
|
||||
that on the screen before giving the server another
|
||||
shot. So just call the idle proc. */
|
||||
if ( redraw ) {
|
||||
util_requestTime( cGlobals->util );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return keep;
|
||||
}
|
||||
|
||||
static XP_S16
|
||||
linux_tcp_send( CommonGlobals* cGlobals, const XP_U8* buf, XP_U16 buflen,
|
||||
linux_relay_send( CommonGlobals* cGlobals, const XP_U8* buf, XP_U16 buflen,
|
||||
const CommsAddrRec* addrRec )
|
||||
{
|
||||
XP_S16 result = 0;
|
||||
|
@ -1094,7 +1140,8 @@ linux_tcp_send( CommonGlobals* cGlobals, const XP_U8* buf, XP_U16 buflen,
|
|||
if ( sock != -1 ) {
|
||||
assert( cGlobals->relaySocket == sock );
|
||||
(*cGlobals->socketChanged)( cGlobals->socketChangedClosure,
|
||||
-1, sock, &cGlobals->storage );
|
||||
-1, sock, linux_relay_ioproc,
|
||||
(void*)cGlobals );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1112,7 +1159,7 @@ linux_tcp_send( CommonGlobals* cGlobals, const XP_U8* buf, XP_U16 buflen,
|
|||
}
|
||||
}
|
||||
return result;
|
||||
} /* linux_tcp_send */
|
||||
} /* linux_relay_send */
|
||||
#endif /* XWFEATURE_RELAY */
|
||||
|
||||
#ifdef COMMS_HEARTBEAT
|
||||
|
@ -1153,46 +1200,51 @@ linux_reset( void* closure )
|
|||
|
||||
XP_S16
|
||||
linux_send( const XP_U8* buf, XP_U16 buflen, const CommsAddrRec* addrRec,
|
||||
XP_U32 gameID, void* closure )
|
||||
CommsConnType conType, XP_U32 gameID, void* closure )
|
||||
{
|
||||
XP_S16 nSent = -1;
|
||||
CommonGlobals* cGlobals = (CommonGlobals*)closure;
|
||||
CommsConnType conType;
|
||||
|
||||
if ( !!addrRec ) {
|
||||
conType = addr_getType( addrRec );
|
||||
} else {
|
||||
conType = cGlobals->params->conType;
|
||||
}
|
||||
/* if ( !!addrRec ) { */
|
||||
/* conType = addr_getType( addrRec ); */
|
||||
/* } else { */
|
||||
/* conType = addr_getType( &cGlobals->params->addr ); */
|
||||
/* } */
|
||||
|
||||
if ( 0 ) {
|
||||
switch ( conType ) {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
} else if ( conType == COMMS_CONN_RELAY ) {
|
||||
nSent = linux_tcp_send( cGlobals, buf, buflen, addrRec );
|
||||
case COMMS_CONN_RELAY:
|
||||
nSent = linux_relay_send( cGlobals, buf, buflen, addrRec );
|
||||
if ( nSent == buflen && cGlobals->params->duplicatePackets ) {
|
||||
#ifdef DEBUG
|
||||
XP_S16 sentAgain =
|
||||
#endif
|
||||
linux_tcp_send( cGlobals, buf, buflen, addrRec );
|
||||
linux_relay_send( cGlobals, buf, buflen, addrRec );
|
||||
XP_ASSERT( sentAgain == nSent );
|
||||
}
|
||||
|
||||
break;
|
||||
#endif
|
||||
#if defined XWFEATURE_BLUETOOTH
|
||||
} else if ( conType == COMMS_CONN_BT ) {
|
||||
case COMMS_CONN_BT: {
|
||||
XP_Bool isServer = comms_getIsServer( cGlobals->game.comms );
|
||||
linux_bt_open( cGlobals, isServer );
|
||||
nSent = linux_bt_send( buf, buflen, addrRec, cGlobals );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined XWFEATURE_IP_DIRECT
|
||||
} else if ( conType == COMMS_CONN_IP_DIRECT ) {
|
||||
#if defined XWFEATURE_IP_DIRECT || defined XWFEATURE_DIRECTIP
|
||||
case COMMS_CONN_IP_DIRECT: {
|
||||
CommsAddrRec addr;
|
||||
comms_getAddr( cGlobals->game.comms, &addr );
|
||||
linux_udp_open( cGlobals, &addr );
|
||||
nSent = linux_udp_send( buf, buflen, addrRec, cGlobals );
|
||||
XP_LOGF( "%s: given %d bytes to send via IP_DIRECT -- which isn't implemented",
|
||||
__func__, buflen );
|
||||
// linux_udp_open( cGlobals, &addr );
|
||||
// nSent = linux_udp_send( buf, buflen, addrRec, cGlobals );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined XWFEATURE_SMS
|
||||
} else if ( COMMS_CONN_SMS == conType ) {
|
||||
case COMMS_CONN_SMS: {
|
||||
CommsAddrRec addr;
|
||||
if ( !addrRec ) {
|
||||
comms_getAddr( cGlobals->game.comms, &addr );
|
||||
|
@ -1201,8 +1253,10 @@ linux_send( const XP_U8* buf, XP_U16 buflen, const CommsAddrRec* addrRec,
|
|||
nSent = linux_sms_send( cGlobals->params, buf, buflen,
|
||||
addrRec->u.sms.phone, addrRec->u.sms.port,
|
||||
gameID );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
} else {
|
||||
default:
|
||||
XP_ASSERT(0);
|
||||
}
|
||||
return nSent;
|
||||
|
@ -1216,7 +1270,7 @@ linux_close_socket( CommonGlobals* cGlobals )
|
|||
int socket = cGlobals->relaySocket;
|
||||
|
||||
(*cGlobals->socketChanged)( cGlobals->socketChangedClosure,
|
||||
socket, -1, &cGlobals->storage );
|
||||
socket, -1, NULL, &cGlobals->storage );
|
||||
|
||||
XP_ASSERT( -1 == cGlobals->relaySocket );
|
||||
|
||||
|
@ -1411,29 +1465,32 @@ linux_util_addrChange( XW_UtilCtxt* uc,
|
|||
const CommsAddrRec* newAddr )
|
||||
{
|
||||
CommonGlobals* cGlobals = (CommonGlobals*)uc->closure;
|
||||
switch ( addr_getType( newAddr ) ) {
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( newAddr, &typ, &st ); ) {
|
||||
switch ( typ ) {
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
case COMMS_CONN_BT: {
|
||||
XP_Bool isServer = comms_getIsServer( cGlobals->game.comms );
|
||||
linux_bt_open( cGlobals, isServer );
|
||||
}
|
||||
break;
|
||||
case COMMS_CONN_BT: {
|
||||
XP_Bool isServer = comms_getIsServer( cGlobals->game.comms );
|
||||
linux_bt_open( cGlobals, isServer );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef XWFEATURE_IP_DIRECT
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
linux_udp_open( cGlobals, newAddr );
|
||||
break;
|
||||
case COMMS_CONN_IP_DIRECT:
|
||||
linux_udp_open( cGlobals, newAddr );
|
||||
break;
|
||||
#endif
|
||||
#ifdef XWFEATURE_SMS
|
||||
case COMMS_CONN_SMS:
|
||||
/* nothing to do??? */
|
||||
// XP_ASSERT(0);
|
||||
// linux_sms_init( cGlobals, newAddr );
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
/* nothing to do??? */
|
||||
// XP_ASSERT(0);
|
||||
// linux_sms_init( cGlobals, newAddr );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
// XP_ASSERT(0);
|
||||
break;
|
||||
default:
|
||||
// XP_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1827,36 +1884,45 @@ initFromParams( CommonGlobals* cGlobals, LaunchParams* params )
|
|||
/* addr */
|
||||
CommsAddrRec* addr = &cGlobals->addr;
|
||||
XP_MEMSET( addr, 0, sizeof(*addr) );
|
||||
if ( 0 ) {
|
||||
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( ¶ms->addr, &typ, &st ); ) {
|
||||
switch( typ ) {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
} else if ( params->conType == COMMS_CONN_RELAY ) {
|
||||
addr_setType( addr, COMMS_CONN_RELAY );
|
||||
addr->u.ip_relay.ipAddr = 0; /* ??? */
|
||||
addr->u.ip_relay.port = params->connInfo.relay.defaultSendPort;
|
||||
addr->u.ip_relay.seeksPublicRoom =
|
||||
params->connInfo.relay.seeksPublicRoom;
|
||||
addr->u.ip_relay.advertiseRoom = params->connInfo.relay.advertiseRoom;
|
||||
XP_STRNCPY( addr->u.ip_relay.hostName,
|
||||
params->connInfo.relay.relayName,
|
||||
sizeof(addr->u.ip_relay.hostName) - 1 );
|
||||
XP_STRNCPY( addr->u.ip_relay.invite, params->connInfo.relay.invite,
|
||||
sizeof(addr->u.ip_relay.invite) - 1 );
|
||||
case COMMS_CONN_RELAY:
|
||||
addr_addType( addr, COMMS_CONN_RELAY );
|
||||
addr->u.ip_relay.ipAddr = 0; /* ??? */
|
||||
addr->u.ip_relay.port = params->connInfo.relay.defaultSendPort;
|
||||
addr->u.ip_relay.seeksPublicRoom =
|
||||
params->connInfo.relay.seeksPublicRoom;
|
||||
addr->u.ip_relay.advertiseRoom = params->connInfo.relay.advertiseRoom;
|
||||
XP_STRNCPY( addr->u.ip_relay.hostName,
|
||||
params->connInfo.relay.relayName,
|
||||
sizeof(addr->u.ip_relay.hostName) - 1 );
|
||||
XP_STRNCPY( addr->u.ip_relay.invite, params->connInfo.relay.invite,
|
||||
sizeof(addr->u.ip_relay.invite) - 1 );
|
||||
break;
|
||||
#endif
|
||||
#ifdef XWFEATURE_SMS
|
||||
} else if ( params->conType == COMMS_CONN_SMS ) {
|
||||
addr_setType( addr, COMMS_CONN_SMS );
|
||||
XP_STRNCPY( addr->u.sms.phone, params->connInfo.sms.phone,
|
||||
sizeof(addr->u.sms.phone) - 1 );
|
||||
addr->u.sms.port = params->connInfo.sms.port;
|
||||
case COMMS_CONN_SMS:
|
||||
addr_addType( addr, COMMS_CONN_SMS );
|
||||
XP_STRNCPY( addr->u.sms.phone, params->connInfo.sms.phone,
|
||||
sizeof(addr->u.sms.phone) - 1 );
|
||||
addr->u.sms.port = params->connInfo.sms.port;
|
||||
break;
|
||||
#endif
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
} else if ( params->conType == COMMS_CONN_BT ) {
|
||||
addr_setType( addr, COMMS_CONN_BT );
|
||||
XP_ASSERT( sizeof(addr->u.bt.btAddr)
|
||||
>= sizeof(params->connInfo.bt.hostAddr));
|
||||
XP_MEMCPY( &addr->u.bt.btAddr, ¶ms->connInfo.bt.hostAddr,
|
||||
sizeof(params->connInfo.bt.hostAddr) );
|
||||
case COMMS_CONN_BT:
|
||||
addr_addType( addr, COMMS_CONN_BT );
|
||||
XP_ASSERT( sizeof(addr->u.bt.btAddr)
|
||||
>= sizeof(params->connInfo.bt.hostAddr));
|
||||
XP_MEMCPY( &addr->u.bt.btAddr, ¶ms->connInfo.bt.hostAddr,
|
||||
sizeof(params->connInfo.bt.hostAddr) );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1927,8 +1993,8 @@ main( int argc, char** argv )
|
|||
int opt;
|
||||
int totalPlayerCount = 0;
|
||||
XP_Bool isServer = XP_FALSE;
|
||||
char* portNum = NULL;
|
||||
char* hostName = "localhost";
|
||||
// char* portNum = NULL;
|
||||
// char* hostName = "localhost";
|
||||
unsigned int seed = defaultRandomSeed();
|
||||
LaunchParams mainParams;
|
||||
XP_U16 nPlayerDicts = 0;
|
||||
|
@ -1950,9 +2016,9 @@ main( int argc, char** argv )
|
|||
sigaction( SIGINT, &act, NULL );
|
||||
sigaction( SIGTERM, &act, NULL );
|
||||
|
||||
CommsConnType conType = COMMS_CONN_NONE;
|
||||
// CommsConnType conType = COMMS_CONN_NONE;
|
||||
#ifdef XWFEATURE_SMS
|
||||
char* phone = NULL;
|
||||
// char* phone = NULL;
|
||||
#endif
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
const char* btaddr = NULL;
|
||||
|
@ -1985,6 +2051,9 @@ main( int argc, char** argv )
|
|||
#ifdef XWFEATURE_IP_DIRECT
|
||||
mainParams.connInfo.ip.port = DEFAULT_PORT;
|
||||
mainParams.connInfo.ip.hostName = "localhost";
|
||||
#endif
|
||||
#ifdef XWFEATURE_SMS
|
||||
mainParams.connInfo.sms.port = 1;
|
||||
#endif
|
||||
mainParams.pgi.boardSize = 15;
|
||||
mainParams.quitAfter = -1;
|
||||
|
@ -2046,18 +2115,22 @@ main( int argc, char** argv )
|
|||
break;
|
||||
#ifdef XWFEATURE_RELAY
|
||||
case CMD_ROOMNAME:
|
||||
XP_ASSERT( conType == COMMS_CONN_NONE ||
|
||||
conType == COMMS_CONN_RELAY );
|
||||
mainParams.connInfo.relay.invite = optarg;
|
||||
conType = COMMS_CONN_RELAY;
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_RELAY );
|
||||
// isServer = XP_TRUE; /* implicit */
|
||||
break;
|
||||
#endif
|
||||
case CMD_HOSTIP:
|
||||
XP_ASSERT( conType == COMMS_CONN_NONE ||
|
||||
conType == COMMS_CONN_IP_DIRECT );
|
||||
hostName = optarg;
|
||||
conType = COMMS_CONN_IP_DIRECT;
|
||||
mainParams.connInfo.ip.hostName = optarg;
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_IP_DIRECT );
|
||||
break;
|
||||
case CMD_HOSTPORT:
|
||||
mainParams.connInfo.ip.hostPort = atoi(optarg);
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_IP_DIRECT );
|
||||
break;
|
||||
case CMD_MYPORT:
|
||||
mainParams.connInfo.ip.myPort = atoi(optarg);
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_IP_DIRECT );
|
||||
break;
|
||||
case CMD_DICT:
|
||||
trimDictPath( optarg, dictbuf, VSIZE(dictbuf), &path, &dict );
|
||||
|
@ -2151,9 +2224,8 @@ main( int argc, char** argv )
|
|||
break;
|
||||
#ifdef XWFEATURE_SMS
|
||||
case CMD_SMSNUMBER: /* SMS phone number */
|
||||
XP_ASSERT( COMMS_CONN_NONE == conType );
|
||||
phone = optarg;
|
||||
conType = COMMS_CONN_SMS;
|
||||
mainParams.connInfo.sms.phone = optarg;
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_SMS );
|
||||
break;
|
||||
#endif
|
||||
case CMD_DUPPACKETS:
|
||||
|
@ -2181,9 +2253,9 @@ main( int argc, char** argv )
|
|||
mainParams.pgi.players[index].isLocal = XP_FALSE;
|
||||
++mainParams.info.serverInfo.nRemotePlayers;
|
||||
break;
|
||||
case CMD_PORT:
|
||||
/* could be RELAY or IP_DIRECT or SMS */
|
||||
portNum = optarg;
|
||||
case CMD_RELAY_PORT:
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_RELAY );
|
||||
mainParams.connInfo.relay.defaultSendPort = atoi( optarg );
|
||||
break;
|
||||
case CMD_ROBOTNAME:
|
||||
++robotCount;
|
||||
|
@ -2216,10 +2288,8 @@ main( int argc, char** argv )
|
|||
break;
|
||||
case CMD_HOSTNAME:
|
||||
/* mainParams.info.clientInfo.serverName = */
|
||||
XP_ASSERT( conType == COMMS_CONN_NONE ||
|
||||
conType == COMMS_CONN_RELAY );
|
||||
conType = COMMS_CONN_RELAY;
|
||||
hostName = optarg;
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_RELAY );
|
||||
mainParams.connInfo.relay.relayName = optarg;
|
||||
break;
|
||||
#ifdef XWFEATURE_RELAY
|
||||
case CMD_ADVERTISEROOM:
|
||||
|
@ -2258,9 +2328,7 @@ main( int argc, char** argv )
|
|||
break;
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
case CMD_BTADDR:
|
||||
XP_ASSERT( conType == COMMS_CONN_NONE ||
|
||||
conType == COMMS_CONN_BT );
|
||||
conType = COMMS_CONN_BT;
|
||||
addr_addType( &mainParams.addr, COMMS_CONN_BT );
|
||||
btaddr = optarg;
|
||||
break;
|
||||
#endif
|
||||
|
@ -2442,61 +2510,44 @@ main( int argc, char** argv )
|
|||
exit( 0 );
|
||||
}
|
||||
#endif
|
||||
if ( 0 ) {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
} else if ( conType == COMMS_CONN_RELAY ) {
|
||||
mainParams.connInfo.relay.relayName = hostName;
|
||||
if ( NULL == portNum ) {
|
||||
portNum = "10997";
|
||||
}
|
||||
mainParams.connInfo.relay.defaultSendPort = atoi( portNum );
|
||||
#endif
|
||||
#ifdef XWFEATURE_IP_DIRECT
|
||||
} else if ( conType == COMMS_CONN_IP_DIRECT ) {
|
||||
mainParams.connInfo.ip.hostName = hostName;
|
||||
if ( NULL == portNum ) {
|
||||
portNum = "10999";
|
||||
}
|
||||
mainParams.connInfo.ip.port = atoi( portNum );
|
||||
#endif
|
||||
#ifdef XWFEATURE_SMS
|
||||
} else if ( conType == COMMS_CONN_SMS ) {
|
||||
mainParams.connInfo.sms.phone = phone;
|
||||
if ( !portNum ) {
|
||||
portNum = "1";
|
||||
}
|
||||
mainParams.connInfo.sms.port = atoi(portNum);
|
||||
#endif
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( &mainParams.addr, &typ, &st ); ) {
|
||||
switch ( typ ) {
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
} else if ( conType == COMMS_CONN_BT ) {
|
||||
bdaddr_t ba;
|
||||
XP_Bool success;
|
||||
XP_ASSERT( btaddr );
|
||||
if ( isServer ) {
|
||||
success = XP_TRUE;
|
||||
/* any format is ok */
|
||||
} else if ( btaddr[1] == ':' ) {
|
||||
success = XP_FALSE;
|
||||
if ( btaddr[0] == 'n' ) {
|
||||
if ( !nameToBtAddr( btaddr+2, &ba ) ) {
|
||||
fprintf( stderr, "fatal error: unable to find device %s\n",
|
||||
btaddr + 2 );
|
||||
exit(0);
|
||||
}
|
||||
case COMMS_CONN_BT: {
|
||||
bdaddr_t ba;
|
||||
XP_Bool success;
|
||||
XP_ASSERT( btaddr );
|
||||
if ( isServer ) {
|
||||
success = XP_TRUE;
|
||||
} else if ( btaddr[0] == 'a' ) {
|
||||
success = 0 == str2ba( &btaddr[2], &ba );
|
||||
XP_ASSERT( success );
|
||||
/* any format is ok */
|
||||
} else if ( btaddr[1] == ':' ) {
|
||||
success = XP_FALSE;
|
||||
if ( btaddr[0] == 'n' ) {
|
||||
if ( !nameToBtAddr( btaddr+2, &ba ) ) {
|
||||
fprintf( stderr, "fatal error: unable to find device %s\n",
|
||||
btaddr + 2 );
|
||||
exit(0);
|
||||
}
|
||||
success = XP_TRUE;
|
||||
} else if ( btaddr[0] == 'a' ) {
|
||||
success = 0 == str2ba( &btaddr[2], &ba );
|
||||
XP_ASSERT( success );
|
||||
}
|
||||
}
|
||||
if ( !success ) {
|
||||
usage( argv[0], "bad format for -B param" );
|
||||
}
|
||||
XP_MEMCPY( &mainParams.connInfo.bt.hostAddr, &ba,
|
||||
sizeof(mainParams.connInfo.bt.hostAddr) );
|
||||
}
|
||||
if ( !success ) {
|
||||
usage( argv[0], "bad format for -B param" );
|
||||
}
|
||||
XP_MEMCPY( &mainParams.connInfo.bt.hostAddr, &ba,
|
||||
sizeof(mainParams.connInfo.bt.hostAddr) );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
mainParams.conType = conType;
|
||||
// addr_setType( &mainParams.addr, conType );
|
||||
|
||||
/* mainParams.pipe = linuxCommPipeCtxtMake( isServer ); */
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ typedef struct LinuxBMStruct {
|
|||
|
||||
int initListenerSocket( int port );
|
||||
XP_S16 linux_send( const XP_U8* buf, XP_U16 buflen,
|
||||
const CommsAddrRec* addrRec,
|
||||
const CommsAddrRec* addrRec, CommsConnType conType,
|
||||
XP_U32 gameID, void* closure );
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
# define LINUX_SEND linux_send
|
||||
|
|
|
@ -121,7 +121,7 @@ typedef struct LaunchParams {
|
|||
|
||||
DeviceRole serverRole;
|
||||
|
||||
CommsConnType conType;
|
||||
CommsAddrRec addr;
|
||||
struct {
|
||||
#ifdef XWFEATURE_RELAY
|
||||
struct {
|
||||
|
@ -140,7 +140,8 @@ typedef struct LaunchParams {
|
|||
#if defined XWFEATURE_IP_DIRECT || defined XWFEATURE_DIRECTIP
|
||||
struct {
|
||||
const char* hostName;
|
||||
int port;
|
||||
int hostPort;
|
||||
int myPort;
|
||||
} ip;
|
||||
#endif
|
||||
#ifdef XWFEATURE_SMS
|
||||
|
@ -161,7 +162,7 @@ typedef struct LaunchParams {
|
|||
typedef struct CommonGlobals CommonGlobals;
|
||||
|
||||
typedef void (*SocketChangedFunc)(void* closure, int oldsock, int newsock,
|
||||
void** storage );
|
||||
GIOFunc func, void** storage );
|
||||
typedef XP_Bool (*Acceptor)( int sock, void* ctxt );
|
||||
typedef void (*AddAcceptorFunc)(int listener, Acceptor func,
|
||||
CommonGlobals* globals, void** storage );
|
||||
|
|
Loading…
Reference in a new issue