mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
Reset all relay-related variable on new game. Fixes bug where devices
couldn't switch roles or join a new game.
This commit is contained in:
parent
61c07ba1a3
commit
213c66b391
2 changed files with 36 additions and 20 deletions
|
@ -119,8 +119,9 @@ struct CommsCtxt {
|
||||||
|
|
||||||
/* Stuff for relays */
|
/* Stuff for relays */
|
||||||
struct {
|
struct {
|
||||||
XWHostID myHostID; /* 0 if unset, 1 if acting as server,
|
XWHostID myHostID; /* 0 if unset, 1 if acting as server.
|
||||||
random for client */
|
Client's 0 replaced by id assigned by
|
||||||
|
relay. Relay calls this "srcID". */
|
||||||
CommsRelayState relayState; /* not saved: starts at UNCONNECTED */
|
CommsRelayState relayState; /* not saved: starts at UNCONNECTED */
|
||||||
CookieID cookieID; /* not saved; temp standin for cookie; set
|
CookieID cookieID; /* not saved; temp standin for cookie; set
|
||||||
by relay */
|
by relay */
|
||||||
|
@ -168,7 +169,7 @@ static AddressRecord* getRecordFor( CommsCtxt* comms, const CommsAddrRec* addr,
|
||||||
static XP_S16 sendMsg( CommsCtxt* comms, MsgQueueElem* elem );
|
static XP_S16 sendMsg( CommsCtxt* comms, MsgQueueElem* elem );
|
||||||
static void addToQueue( CommsCtxt* comms, MsgQueueElem* newMsgElem );
|
static void addToQueue( CommsCtxt* comms, MsgQueueElem* newMsgElem );
|
||||||
static XP_U16 countAddrRecs( const CommsCtxt* comms );
|
static XP_U16 countAddrRecs( const CommsCtxt* comms );
|
||||||
static void sendConnect( CommsCtxt* comms );
|
static void sendConnect( CommsCtxt* comms, XP_Bool breakExisting );
|
||||||
|
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
static XP_Bool relayConnect( CommsCtxt* comms );
|
static XP_Bool relayConnect( CommsCtxt* comms );
|
||||||
|
@ -193,6 +194,20 @@ static XP_S16 send_via_bt_or_ip( CommsCtxt* comms, BTIPMsgType typ,
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* implementation
|
* implementation
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#ifdef XWFEATURE_RELAY
|
||||||
|
static void
|
||||||
|
init_relay( CommsCtxt* comms, XP_U16 nPlayersHere, XP_U16 nPlayersTotal )
|
||||||
|
{
|
||||||
|
comms->r.myHostID = comms->isServer? HOST_ID_SERVER: HOST_ID_NONE;
|
||||||
|
XP_LOGF( "set myHostID to %d", comms->r.myHostID );
|
||||||
|
comms->r.relayState = COMMS_RELAYSTATE_UNCONNECTED;
|
||||||
|
comms->r.nPlayersHere = nPlayersHere;
|
||||||
|
comms->r.nPlayersTotal = nPlayersTotal;
|
||||||
|
comms->r.cookieID = COOKIE_ID_NONE;
|
||||||
|
comms->r.connName[0] = '\0';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
CommsCtxt*
|
CommsCtxt*
|
||||||
comms_make( MPFORMAL XW_UtilCtxt* util, XP_Bool isServer,
|
comms_make( MPFORMAL XW_UtilCtxt* util, XP_Bool isServer,
|
||||||
XP_U16 XP_UNUSED_RELAY(nPlayersHere),
|
XP_U16 XP_UNUSED_RELAY(nPlayersHere),
|
||||||
|
@ -214,12 +229,7 @@ comms_make( MPFORMAL XW_UtilCtxt* util, XP_Bool isServer,
|
||||||
result->util = util;
|
result->util = util;
|
||||||
|
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
result->r.myHostID = isServer? HOST_ID_SERVER: HOST_ID_NONE;
|
init_relay( result, nPlayersHere, nPlayersTotal );
|
||||||
XP_LOGF( "set myHostID to %d", result->r.myHostID );
|
|
||||||
|
|
||||||
result->r.relayState = COMMS_RELAYSTATE_UNCONNECTED;
|
|
||||||
result->r.nPlayersHere = nPlayersHere;
|
|
||||||
result->r.nPlayersTotal = nPlayersTotal;
|
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
} /* comms_make */
|
} /* comms_make */
|
||||||
|
@ -271,10 +281,7 @@ comms_reset( CommsCtxt* comms, XP_Bool isServer,
|
||||||
|
|
||||||
comms->connID = CONN_ID_NONE;
|
comms->connID = CONN_ID_NONE;
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
comms->r.cookieID = COOKIE_ID_NONE;
|
init_relay( comms, nPlayersHere, nPlayersTotal );
|
||||||
comms->r.nPlayersHere = nPlayersHere;
|
|
||||||
comms->r.nPlayersTotal = nPlayersTotal;
|
|
||||||
(void)relayConnect( comms );
|
|
||||||
#endif
|
#endif
|
||||||
LOG_RETURN_VOID();
|
LOG_RETURN_VOID();
|
||||||
} /* comms_reset */
|
} /* comms_reset */
|
||||||
|
@ -503,21 +510,27 @@ setDoHeartbeat( CommsCtxt* comms )
|
||||||
# define setDoHeartbeat(c)
|
# define setDoHeartbeat(c)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Currently this disconnects an open connection. Don't do that.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
comms_start( CommsCtxt* comms )
|
comms_start( CommsCtxt* comms )
|
||||||
{
|
{
|
||||||
setDoHeartbeat( comms );
|
setDoHeartbeat( comms );
|
||||||
sendConnect( comms );
|
sendConnect( comms, XP_FALSE );
|
||||||
} /* comms_start */
|
} /* comms_start */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sendConnect( CommsCtxt* comms )
|
sendConnect( CommsCtxt* comms, XP_Bool breakExisting )
|
||||||
{
|
{
|
||||||
switch( comms->addr.conType ) {
|
switch( comms->addr.conType ) {
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
case COMMS_CONN_RELAY:
|
case COMMS_CONN_RELAY:
|
||||||
comms->r.relayState = COMMS_RELAYSTATE_UNCONNECTED;
|
if ( breakExisting
|
||||||
relayConnect( comms );
|
|| COMMS_RELAYSTATE_UNCONNECTED == comms->r.relayState ) {
|
||||||
|
comms->r.relayState = COMMS_RELAYSTATE_UNCONNECTED;
|
||||||
|
relayConnect( comms );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_IP_DIRECT
|
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_IP_DIRECT
|
||||||
|
@ -571,6 +584,9 @@ addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addrP )
|
||||||
stringToStream( stream, addr.u.sms.phone );
|
stringToStream( stream, addr.u.sms.phone );
|
||||||
stream_putU16( stream, addr.u.sms.port );
|
stream_putU16( stream, addr.u.sms.port );
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
XP_ASSERT(0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} /* addrToStream */
|
} /* addrToStream */
|
||||||
|
|
||||||
|
@ -652,7 +668,7 @@ comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr )
|
||||||
#ifdef COMMS_HEARTBEAT
|
#ifdef COMMS_HEARTBEAT
|
||||||
setDoHeartbeat( comms );
|
setDoHeartbeat( comms );
|
||||||
#endif
|
#endif
|
||||||
sendConnect( comms );
|
sendConnect( comms, XP_TRUE );
|
||||||
|
|
||||||
} /* comms_setAddr */
|
} /* comms_setAddr */
|
||||||
|
|
||||||
|
@ -894,8 +910,6 @@ removeFromQueue( CommsCtxt* comms, XP_PlayerAddr channelNo, MsgID msgID )
|
||||||
|
|
||||||
XP_STATUSF( "%s: queueLen now %d", __func__, comms->queueLen );
|
XP_STATUSF( "%s: queueLen now %d", __func__, comms->queueLen );
|
||||||
|
|
||||||
XP_ASSERT( comms->queueLen > 0 || comms->msgQueueHead == NULL );
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assertQueueOk( comms );
|
assertQueueOk( comms );
|
||||||
printQueue( comms );
|
printQueue( comms );
|
||||||
|
|
|
@ -41,6 +41,8 @@ typedef enum {
|
||||||
,COMMS_CONN_RELAY
|
,COMMS_CONN_RELAY
|
||||||
,COMMS_CONN_BT
|
,COMMS_CONN_BT
|
||||||
,COMMS_CONN_SMS
|
,COMMS_CONN_SMS
|
||||||
|
|
||||||
|
,COMMS_CONN_NTYPES
|
||||||
} CommsConnType;
|
} CommsConnType;
|
||||||
|
|
||||||
/* WHAT SHOULD THIS BE? Copied from Whiteboard.... PENDING */
|
/* WHAT SHOULD THIS BE? Copied from Whiteboard.... PENDING */
|
||||||
|
|
Loading…
Add table
Reference in a new issue