mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-15 08:47:56 +01:00
use dutil_phoneNumbersSame() instead of strcmp()
This commit is contained in:
parent
4e50024359
commit
2a8a9b442a
7 changed files with 52 additions and 39 deletions
|
@ -1321,7 +1321,8 @@ comms_getChannelAddr( const CommsCtxt* comms, XP_PlayerAddr channelNo,
|
|||
}
|
||||
|
||||
XP_Bool
|
||||
addrsAreSame( const CommsAddrRec* addr1, const CommsAddrRec* addr2 )
|
||||
addrsAreSame( XW_DUtilCtxt* dutil, XWEnv xwe, const CommsAddrRec* addr1,
|
||||
const CommsAddrRec* addr2 )
|
||||
{
|
||||
/* Empty addresses are the same only if both are empty */
|
||||
XP_Bool same = addr1->_conTypes == 0 && addr2->_conTypes == 0;
|
||||
|
@ -1335,7 +1336,7 @@ addrsAreSame( const CommsAddrRec* addr1, const CommsAddrRec* addr2 )
|
|||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
same = addr1->u.sms.port == addr2->u.sms.port
|
||||
&& 0 == XP_STRCMP(addr1->u.sms.phone, addr2->u.sms.phone );
|
||||
&& dutil_phoneNumbersSame( dutil, xwe, addr1->u.sms.phone, addr2->u.sms.phone );
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
same = 0 == XP_STRCMP( addr1->u.bt.hostName, addr2->u.bt.hostName );
|
||||
|
@ -1657,7 +1658,7 @@ getInviteChannels( MsgQueueElem* elem, void* closure )
|
|||
|
||||
/* Choose a channel IFF nli doesn't already specify one. */
|
||||
static XP_PlayerAddr
|
||||
pickChannel( const CommsCtxt* comms, const NetLaunchInfo* nli,
|
||||
pickChannel( const CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
|
||||
const CommsAddrRec* destAddr )
|
||||
{
|
||||
XP_PlayerAddr result = nli->forceChannel;
|
||||
|
@ -1665,7 +1666,7 @@ pickChannel( const CommsCtxt* comms, const NetLaunchInfo* nli,
|
|||
if ( 0 == result ) {
|
||||
/* First, do we already have an invitation for this address */
|
||||
for ( AddressRecord* rec = comms->recs; !!rec; rec = rec->next ) {
|
||||
if ( addrsAreSame( destAddr, &rec->addr ) ) {
|
||||
if ( addrsAreSame( comms->dutil, xwe, destAddr, &rec->addr ) ) {
|
||||
result = rec->channelNo & CHANNEL_MASK;
|
||||
XP_LOGFF( "addrs match; reusing channel %d", result );
|
||||
break;
|
||||
|
@ -1714,7 +1715,7 @@ comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
|
|||
COMMS_LOGFF("(sendNow=%s)", boolToStr(sendNow));
|
||||
LOGNLI(nli);
|
||||
WITH_MUTEX(&comms->mutex);
|
||||
XP_PlayerAddr forceChannel = pickChannel( comms, nli, destAddr );
|
||||
XP_PlayerAddr forceChannel = pickChannel( comms, xwe, nli, destAddr );
|
||||
XP_LOGFF( "forceChannel: %d", forceChannel );
|
||||
XP_ASSERT( 0 < forceChannel );
|
||||
if ( 0 < forceChannel ) {
|
||||
|
@ -2766,13 +2767,13 @@ preProcess(
|
|||
the channel set up. Be sure to use it or we may wind up nuking undelievered
|
||||
invitations */
|
||||
static XP_Bool
|
||||
getChannelFromInvite( const CommsCtxt* comms, const CommsAddrRec* retAddr,
|
||||
XP_PlayerAddr* channelNoP )
|
||||
getChannelFromInvite( const CommsCtxt* comms, XWEnv xwe,
|
||||
const CommsAddrRec* retAddr, XP_PlayerAddr* channelNoP )
|
||||
{
|
||||
XP_Bool found = XP_FALSE;
|
||||
for ( const AddressRecord* rec = comms->recs; !!rec && !found;
|
||||
rec = rec->next ) {
|
||||
found = addrsAreSame( retAddr, &rec->addr );
|
||||
found = addrsAreSame( comms->dutil, xwe, retAddr, &rec->addr );
|
||||
if ( found ) {
|
||||
COMMS_LOGFF( "channelNo before: %x", *channelNoP );
|
||||
*channelNoP |= rec->channelNo;
|
||||
|
@ -2849,13 +2850,14 @@ getNextChannelNo( CommsCtxt* comms )
|
|||
}
|
||||
|
||||
static XP_Bool
|
||||
checkChannelNo( CommsCtxt* comms, const CommsAddrRec* retAddr, XP_PlayerAddr* channelNoP )
|
||||
checkChannelNo( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* retAddr,
|
||||
XP_PlayerAddr* channelNoP )
|
||||
{
|
||||
XP_Bool success = XP_TRUE;
|
||||
XP_PlayerAddr channelNo = *channelNoP;
|
||||
if ( 0 == (channelNo & CHANNEL_MASK) ) {
|
||||
XP_ASSERT( comms->isServer );
|
||||
if ( getChannelFromInvite( comms, retAddr, &channelNo ) ) {
|
||||
if ( getChannelFromInvite( comms, xwe, retAddr, &channelNo ) ) {
|
||||
success = XP_TRUE;
|
||||
} else {
|
||||
success = comms->nextChannelNo < CHANNEL_MASK;
|
||||
|
@ -2894,7 +2896,8 @@ checkChannelNo( CommsCtxt* comms, const CommsAddrRec* retAddr, XP_PlayerAddr* ch
|
|||
* it invalid
|
||||
*/
|
||||
static AddressRecord*
|
||||
validateInitialMessage( CommsCtxt* comms, XP_Bool XP_UNUSED_HEARTBEAT(hasPayload),
|
||||
validateInitialMessage( CommsCtxt* comms, XWEnv xwe,
|
||||
XP_Bool XP_UNUSED_HEARTBEAT(hasPayload),
|
||||
const CommsAddrRec* retAddr, XWHostID senderID,
|
||||
XP_PlayerAddr* channelNoP, XP_U16 flags, MsgID msgID )
|
||||
{
|
||||
|
@ -2916,7 +2919,7 @@ validateInitialMessage( CommsCtxt* comms, XP_Bool XP_UNUSED_HEARTBEAT(hasPayload
|
|||
}
|
||||
} else {
|
||||
if ( comms->isServer ) {
|
||||
if ( checkChannelNo( comms, retAddr, channelNoP ) ) {
|
||||
if ( checkChannelNo( comms, xwe, retAddr, channelNoP ) ) {
|
||||
CNO_FMT( cbuf, *channelNoP );
|
||||
COMMS_LOGFF( TAGFMT() "augmented channel: %s", TAGPRMS, cbuf );
|
||||
} else {
|
||||
|
@ -3175,7 +3178,7 @@ comms_checkIncomingStream( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream,
|
|||
if ( messageValid ) {
|
||||
if ( stuff.connID == CONN_ID_NONE ) {
|
||||
/* special case: initial message from client or server */
|
||||
rec = validateInitialMessage( comms, streamSize > 0, retAddr,
|
||||
rec = validateInitialMessage( comms, xwe, streamSize > 0, retAddr,
|
||||
senderID, &stuff.channelNo,
|
||||
stuff.flags, stuff.msgID );
|
||||
state->rec = rec;
|
||||
|
|
|
@ -218,7 +218,8 @@ XP_S16 comms_resendAll( CommsCtxt* comms, XWEnv xwe, CommsConnType filter,
|
|||
XP_U16 comms_getChannelSeed( CommsCtxt* comms );
|
||||
void comms_getChannelAddr( const CommsCtxt* comms, XP_PlayerAddr channelNo,
|
||||
CommsAddrRec* addr );
|
||||
XP_Bool addrsAreSame( const CommsAddrRec* addr1, const CommsAddrRec* addr2 );
|
||||
XP_Bool addrsAreSame( XW_DUtilCtxt* dutil, XWEnv xwe, const CommsAddrRec* addr1,
|
||||
const CommsAddrRec* addr2 );
|
||||
|
||||
#ifdef XWFEATURE_COMMSACK
|
||||
void comms_ackAny( CommsCtxt* comms, XWEnv xwe );
|
||||
|
|
|
@ -94,6 +94,9 @@ clearDS( DragState* ds )
|
|||
static XP_Bool
|
||||
ddStartBoard( BoardCtxt* board, XWEnv xwe, XP_U16 xx, XP_U16 yy )
|
||||
{
|
||||
#ifndef XWFEATURE_SEARCHLIMIT
|
||||
XP_USE(xwe);
|
||||
#endif
|
||||
DragState* ds = &board->dragState;
|
||||
XP_Bool trayVisible;
|
||||
XP_U16 col, row;
|
||||
|
|
|
@ -242,7 +242,7 @@ game_makeRematch( const XWGame* oldGame, XWEnv xwe, XW_UtilCtxt* newUtil,
|
|||
XP_Bool success = XP_FALSE;
|
||||
|
||||
RematchInfo* rip;
|
||||
if ( server_getRematchInfo( oldGame->server, newUtil,
|
||||
if ( server_getRematchInfo( oldGame->server, xwe, newUtil,
|
||||
game_makeGameID( 0 ), nop, &rip ) ) {
|
||||
CommsAddrRec* selfAddrP = NULL;
|
||||
CommsAddrRec selfAddr;
|
||||
|
|
|
@ -384,6 +384,8 @@ kplr_nameForMqttDev( XW_DUtilCtxt* dutil, XWEnv xwe,
|
|||
}
|
||||
|
||||
typedef struct _MDevState {
|
||||
XW_DUtilCtxt* dutil;
|
||||
XWEnv xwe;
|
||||
const CommsAddrRec* addr;
|
||||
const XP_UCHAR* name;
|
||||
} MDevState;
|
||||
|
@ -395,7 +397,7 @@ addrProc( const DLHead* dl, void* closure )
|
|||
const KnownPlayer* kp = (KnownPlayer*)dl;
|
||||
MDevState* msp = (MDevState*)closure;
|
||||
|
||||
if ( addrsAreSame( &kp->addr, msp->addr ) ) {
|
||||
if ( addrsAreSame( msp->dutil, msp->xwe, &kp->addr, msp->addr ) ) {
|
||||
msp->name = kp->name;
|
||||
result = FEA_EXIT;
|
||||
}
|
||||
|
@ -406,7 +408,8 @@ const XP_UCHAR*
|
|||
kplr_nameForAddress( XW_DUtilCtxt* dutil, XWEnv xwe,
|
||||
const CommsAddrRec* addr )
|
||||
{
|
||||
MDevState ms = {.addr = addr};
|
||||
MDevState ms = {.addr = addr, .dutil = dutil, .xwe = xwe, };
|
||||
|
||||
WITH_MUTEX( &dutil->kpMutex );
|
||||
KPState* state = loadStateLocked( dutil, xwe );
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -291,7 +291,7 @@ static void writeProto( const ServerCtxt* server, XWStreamCtxt* stream,
|
|||
XW_Proto proto );
|
||||
static void readGuestAddrs( ServerCtxt* server, XWStreamCtxt* stream,
|
||||
XP_U8 streamVersion );
|
||||
static XP_Bool getRematchInfoImpl( const ServerCtxt* server,
|
||||
static XP_Bool getRematchInfoImpl( const ServerCtxt* server, XWEnv xwe,
|
||||
CurGameInfo* newGI, const NewOrder* nop,
|
||||
RematchInfo** ripp );
|
||||
|
||||
|
@ -299,8 +299,8 @@ static void ri_fromStream( RematchInfo* rip, XWStreamCtxt* stream,
|
|||
const ServerCtxt* server );
|
||||
static void ri_toStream( XWStreamCtxt* stream, const RematchInfo* rip,
|
||||
const ServerCtxt* server );
|
||||
static void ri_addAddrAt( RematchInfo* rip, const CommsAddrRec* addr,
|
||||
XP_U16 playerIndex );
|
||||
static void ri_addAddrAt( XW_DUtilCtxt* dutil, XWEnv xwe, RematchInfo* rip,
|
||||
const CommsAddrRec* addr, XP_U16 playerIndex );
|
||||
static void ri_addHostAddrs( RematchInfo* rip, const ServerCtxt* server );
|
||||
static void ri_addLocal( RematchInfo* rip );
|
||||
|
||||
|
@ -888,7 +888,7 @@ readMQTTDevID( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
address, which the guest knows already, add an empty address as a
|
||||
placeholder. Guest will replace it if needed. */
|
||||
static void
|
||||
buildGuestRI( const ServerCtxt* server, XP_U16 guestIndex, RematchInfo* rip )
|
||||
buildGuestRI( const ServerCtxt* server, XWEnv xwe, XP_U16 guestIndex, RematchInfo* rip )
|
||||
{
|
||||
XP_MEMSET( rip, 0, sizeof(*rip) );
|
||||
|
||||
|
@ -897,7 +897,7 @@ buildGuestRI( const ServerCtxt* server, XP_U16 guestIndex, RematchInfo* rip )
|
|||
const LocalPlayer* lp = &gi->players[ii];
|
||||
if ( lp->isLocal ) { /* that's me, the host */
|
||||
CommsAddrRec addr = {};
|
||||
ri_addAddrAt( rip, &addr, ii );
|
||||
ri_addAddrAt( server->vol.dutil, xwe, rip, &addr, ii );
|
||||
} else {
|
||||
XP_S8 deviceIndex = server->srvPlyrs[ii].deviceIndex;
|
||||
if ( guestIndex == deviceIndex ) {
|
||||
|
@ -907,7 +907,7 @@ buildGuestRI( const ServerCtxt* server, XP_U16 guestIndex, RematchInfo* rip )
|
|||
= server->nv.addresses[deviceIndex].channelNo;
|
||||
CommsAddrRec addr;
|
||||
comms_getChannelAddr( server->vol.comms, channelNo, &addr );
|
||||
ri_addAddrAt( rip, &addr, ii );
|
||||
ri_addAddrAt( server->vol.dutil, xwe, rip, &addr, ii );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -933,7 +933,8 @@ loadRemoteRI( const ServerCtxt* server, const CurGameInfo* XP_UNUSED_DBG(gi),
|
|||
}
|
||||
|
||||
static void
|
||||
addGuestAddrsIf( const ServerCtxt* server, XP_U16 sendee, XWStreamCtxt* stream )
|
||||
addGuestAddrsIf( const ServerCtxt* server, XWEnv xwe, XP_U16 sendee,
|
||||
XWStreamCtxt* stream )
|
||||
{
|
||||
SRVR_LOGFF("(sendee: %d)", sendee );
|
||||
XP_ASSERT( amHost( server ) );
|
||||
|
@ -947,7 +948,7 @@ addGuestAddrsIf( const ServerCtxt* server, XP_U16 sendee, XWStreamCtxt* stream )
|
|||
|
||||
if ( STREAM_VERS_REMATCHORDER <= version ) {
|
||||
RematchInfo ri;
|
||||
buildGuestRI( server, sendee, &ri );
|
||||
buildGuestRI( server, xwe, sendee, &ri );
|
||||
ri_toStream( tmpStream, &ri, server );
|
||||
|
||||
/* Old verion requires no two-player devices */
|
||||
|
@ -1066,7 +1067,7 @@ server_initClientConnection( ServerCtxt* server, XWEnv xwe )
|
|||
#endif
|
||||
stream_destroy( stream );
|
||||
} else {
|
||||
SRVR_LOGFF( "wierd state: %s (expected XWSTATE_NONE); dropping message",
|
||||
SRVR_LOGFF( "wierd state: %s (expected XWSTATE_NONE); doing nothing",
|
||||
getStateStr(server->nv.gameState) );
|
||||
}
|
||||
SRVR_LOGFF( "=> %s", boolToStr(result) );
|
||||
|
@ -2123,7 +2124,7 @@ findFirstPending( ServerCtxt* server, ServerPlayer** spp,
|
|||
} /* findFirstPending */
|
||||
|
||||
static XP_Bool
|
||||
findOrderedSlot( ServerCtxt* server, XWStreamCtxt* stream,
|
||||
findOrderedSlot( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream,
|
||||
ServerPlayer** spp, LocalPlayer** lpp )
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
@ -2148,7 +2149,8 @@ findOrderedSlot( ServerCtxt* server, XWStreamCtxt* stream,
|
|||
SRVR_LOGFFV( "ii: %d; deviceIndex: %d", ii, sp->deviceIndex );
|
||||
if ( UNKNOWN_DEVICE == sp->deviceIndex ) {
|
||||
int addrIndx = rip->addrIndices[ii];
|
||||
if ( addrsAreSame( &guestAddr, &rip->addrs[addrIndx] ) ) {
|
||||
if ( addrsAreSame( server->vol.dutil, xwe, &guestAddr,
|
||||
&rip->addrs[addrIndx] ) ) {
|
||||
*spp = sp;
|
||||
*lpp = &gi->players[ii];
|
||||
XP_ASSERT( !(*lpp)->isLocal );
|
||||
|
@ -2175,7 +2177,7 @@ registerRemotePlayer( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
|
|||
LocalPlayer* lp;
|
||||
XP_Bool success;
|
||||
if ( server_isFromRematch( server ) ) {
|
||||
success = findOrderedSlot( server, stream, &sp, &lp );
|
||||
success = findOrderedSlot( server, xwe, stream, &sp, &lp );
|
||||
} else {
|
||||
success = findFirstPending( server, &sp, &lp );
|
||||
}
|
||||
|
@ -2454,7 +2456,7 @@ sendInitialMessage( ServerCtxt* server, XWEnv xwe )
|
|||
}
|
||||
|
||||
addMQTTDevIDIf( server, xwe, stream );
|
||||
addGuestAddrsIf( server, deviceIndex, stream );
|
||||
addGuestAddrsIf( server, xwe, deviceIndex, stream );
|
||||
|
||||
stream_destroy( stream );
|
||||
}
|
||||
|
@ -4273,7 +4275,7 @@ setPlayerOrder( const ServerCtxt* XP_UNUSED_DBG(server), const NewOrder* nop,
|
|||
} /* setPlayerOrder */
|
||||
|
||||
XP_Bool
|
||||
server_getRematchInfo( const ServerCtxt* server, XW_UtilCtxt* newUtil,
|
||||
server_getRematchInfo( const ServerCtxt* server, XWEnv xwe, XW_UtilCtxt* newUtil,
|
||||
XP_U32 gameID, const NewOrder* nop, RematchInfo** ripp )
|
||||
{
|
||||
XP_Bool success = server_canRematch( server, NULL );
|
||||
|
@ -4289,13 +4291,13 @@ server_getRematchInfo( const ServerCtxt* server, XW_UtilCtxt* newUtil,
|
|||
}
|
||||
LOGGI( newUtil->gameInfo, "ready to invite" );
|
||||
|
||||
success = getRematchInfoImpl( server, newGI, nop, ripp );
|
||||
success = getRematchInfoImpl( server, xwe, newGI, nop, ripp );
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
static XP_Bool
|
||||
getRematchInfoImpl( const ServerCtxt* server, CurGameInfo* newGI,
|
||||
getRematchInfoImpl( const ServerCtxt* server, XWEnv xwe, CurGameInfo* newGI,
|
||||
const NewOrder* nop, RematchInfo** ripp )
|
||||
{
|
||||
XP_Bool success = XP_TRUE;
|
||||
|
@ -4323,7 +4325,7 @@ getRematchInfoImpl( const ServerCtxt* server, CurGameInfo* newGI,
|
|||
} else {
|
||||
comms_getHostAddr( comms, &addr );
|
||||
}
|
||||
ri_addAddrAt( &ri, &addr, ii );
|
||||
ri_addAddrAt( server->vol.dutil, xwe, &ri, &addr, ii );
|
||||
}
|
||||
}
|
||||
} else if ( !!server->nv.rematch.addrs ) {
|
||||
|
@ -4361,7 +4363,7 @@ getRematchInfoImpl( const ServerCtxt* server, CurGameInfo* newGI,
|
|||
if ( newGI->players[ii].isLocal ) {
|
||||
ri_addLocal( &ri );
|
||||
} else if ( nextRemote < nAddrs ) {
|
||||
ri_addAddrAt( &ri, &addrs[nextRemote++], ii );
|
||||
ri_addAddrAt( server->vol.dutil, xwe, &ri, &addrs[nextRemote++], ii );
|
||||
} else {
|
||||
SRVR_LOGFF( "ERROR: not enough addresses for all"
|
||||
" remote players" );
|
||||
|
@ -4499,7 +4501,7 @@ server_gatherPlayers( ServerCtxt* server, XWEnv xwe, XP_U32 created )
|
|||
|
||||
CurGameInfo tmpGi = *gi;
|
||||
RematchInfo* ripp;
|
||||
if ( getRematchInfoImpl( server, &tmpGi, &no, &ripp ) ) {
|
||||
if ( getRematchInfoImpl( server, xwe, &tmpGi, &no, &ripp ) ) {
|
||||
for ( int ii = 0, nRemotes = 0; ii < gi->nPlayers; ++ii ) {
|
||||
const LocalPlayer* lp = &gi->players[ii];
|
||||
/* order unchanged? */
|
||||
|
@ -4601,13 +4603,14 @@ ri_fromStream( RematchInfo* rip, XWStreamCtxt* stream,
|
|||
/* Given an address, insert it if it's new, or point to an existing copy
|
||||
otherwise */
|
||||
static void
|
||||
ri_addAddrAt( RematchInfo* rip, const CommsAddrRec* addr, const XP_U16 player )
|
||||
ri_addAddrAt( XW_DUtilCtxt* dutil, XWEnv xwe, RematchInfo* rip,
|
||||
const CommsAddrRec* addr, const XP_U16 player )
|
||||
{
|
||||
XP_S8 newIndex = RIP_LOCAL_INDX;
|
||||
for ( int ii = 0; ii < player; ++ii ) {
|
||||
int index = rip->addrIndices[ii];
|
||||
if ( index != RIP_LOCAL_INDX &&
|
||||
addrsAreSame( addr, &rip->addrs[index] ) ) {
|
||||
addrsAreSame( dutil, xwe, addr, &rip->addrs[index] ) ) {
|
||||
newIndex = index;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ void server_figureOrder( const ServerCtxt* server, RematchOrder ro,
|
|||
addresses to which invitation should be sent. But: meant to be called
|
||||
only from game.c anyway.
|
||||
*/
|
||||
XP_Bool server_getRematchInfo( const ServerCtxt* server, XW_UtilCtxt* newUtil,
|
||||
XP_Bool server_getRematchInfo( const ServerCtxt* server, XWEnv xwe, XW_UtilCtxt* newUtil,
|
||||
XP_U32 gameID, const NewOrder* nop, RematchInfo** ripp );
|
||||
void server_disposeRematchInfo( ServerCtxt* server, RematchInfo** rip );
|
||||
XP_Bool server_ri_getAddr( const RematchInfo* ri, XP_U16 nth,
|
||||
|
|
Loading…
Add table
Reference in a new issue