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