pass remaining reconnect params in case connName's missing from db.

Should only matter if the relay's db's been deleted.
This commit is contained in:
Andy2 2010-10-04 18:39:26 -07:00
parent b3c7cb3711
commit 89f967a016
6 changed files with 56 additions and 28 deletions

View file

@ -797,8 +797,11 @@ CookieRef::increasePlayerCounts( CRefEvent* evt, bool reconn )
if ( !reconn ) {
m_nPlayersHere += nPlayersH;
assert( m_nPlayersHere <= m_nPlayersSought );
evt->u.con.srcID = DBMgr::Get()->AddDevice( ConnName(), nPlayersH, seed );
}
evt->u.con.srcID = DBMgr::Get()->AddDevice( ConnName(), evt->u.con.srcID,
nPlayersH, seed );
HostID hostid = evt->u.con.srcID;
/* first add the rec here, whether it'll get ack'd or not */

View file

@ -269,28 +269,42 @@ CRefMgr::getMakeCookieRef( const char* cookie, HostID hid, int socket,
/* reconnect case */
CookieRef*
CRefMgr::getMakeCookieRef( const char* connName, HostID hid, int socket,
int nPlayersH, int seed )
CRefMgr::getMakeCookieRef( const char* connName, const char* cookie,
HostID hid, int socket, int nPlayersH,
int nPlayersS, int seed, int langCode,
bool isPublic )
{
CookieRef* cref = NULL;
/* fetch these from DB */
char cookie[MAX_INVITE_LEN+1];
int langCode;
char curCookie[MAX_INVITE_LEN+1];
int curLangCode;
int nPlayersT = 0;
int nAlreadyHere = 0;
CookieID cid = m_db->FindGame( connName, cookie, sizeof(cookie),
&langCode, &nPlayersT, &nAlreadyHere );
CookieID cid = m_db->FindGame( connName, curCookie, sizeof(curCookie),
&curLangCode, &nPlayersT, &nAlreadyHere );
if ( 0 != cid ) { /* already open */
cref = getCookieRef_impl( cid );
} else {
/* The entry may not even be in the DB, e.g. if it got deleted.
Deal with that possibility by taking the caller's word for it. */
CookieID cid = nextCID( NULL );
cref = AddNew( cookie, connName, cid, langCode, nPlayersT, nAlreadyHere );
if ( nPlayersT == 0 ) { /* wasn't in the DB */
m_db->AddNew( cookie, connName, cid, langCode, nPlayersS, isPublic );
curLangCode = langCode;
nPlayersT = nPlayersS;
} else {
cookie = curCookie;
}
cref = AddNew( cookie, connName, cid, curLangCode, nPlayersT,
nAlreadyHere );
m_db->AddCID( connName, cid );
}
return cref;
}
} /* getMakeCookieRef */
bool
CRefMgr::Associate( int socket, CookieRef* cref )
@ -619,8 +633,8 @@ SafeCref::SafeCref( const char* cookie, int socket, int nPlayersH, int nPlayersS
CookieRef* cref;
cref = m_mgr->getMakeCookieRef( cookie, 0, socket,
nPlayersH, nPlayersS, langCode,
gameSeed, wantsPublic, makePublic );
nPlayersH, nPlayersS, langCode,
gameSeed, wantsPublic, makePublic );
if ( cref != NULL ) {
m_locked = cref->Lock();
m_cref = cref;
@ -629,9 +643,10 @@ SafeCref::SafeCref( const char* cookie, int socket, int nPlayersH, int nPlayersS
}
/* REconnect case */
SafeCref::SafeCref( const char* connName, HostID hid,
SafeCref::SafeCref( const char* connName, const char* cookie, HostID hid,
int socket, int nPlayersH, int nPlayersS,
unsigned short gameSeed, int langCode )
unsigned short gameSeed, int langCode,
bool wantsPublic, bool makePublic )
: m_cref( NULL )
, m_mgr( CRefMgr::Get() )
, m_isValid( false )
@ -639,7 +654,9 @@ SafeCref::SafeCref( const char* connName, HostID hid,
CookieRef* cref;
assert( hid <= 4 ); /* no more than 4 hosts */
cref = m_mgr->getMakeCookieRef( connName, hid, socket, nPlayersH, gameSeed );
cref = m_mgr->getMakeCookieRef( connName, cookie, hid, socket, nPlayersH,
nPlayersS, gameSeed, langCode,
wantsPublic || makePublic );
if ( cref != NULL ) {
m_locked = cref->Lock();
m_cref = cref;

View file

@ -142,8 +142,10 @@ class CRefMgr {
bool wantsPublic, bool makePublic );
/* reconnect case; just the stuff we don't have in db */
CookieRef* getMakeCookieRef( const char* connName, HostID hid, int socket,
int nPlayersH, int seed );
CookieRef* getMakeCookieRef( const char* connName, const char* cookie,
HostID hid, int socket, int nPlayersH,
int nPlayersS, int seed, int langCode,
bool isPublic );
CookieRef* getCookieRef( CookieID cookieID );
CookieRef* getCookieRef( int socket );
@ -194,9 +196,10 @@ class SafeCref {
unsigned short gameSeed, int langCode, bool wantsPublic,
bool makePublic );
/* for reconnect */
SafeCref( const char* connName, HostID hid,
SafeCref( const char* connName, const char* cookie, HostID hid,
int socket, int nPlayersH, int nPlayersS,
unsigned short gameSeed, int langCode );
unsigned short gameSeed, int langCode,
bool wantsPublic, bool makePublic );
SafeCref( CookieID cid, bool failOk = false );
SafeCref( int socket );
SafeCref( CookieRef* cref );

View file

@ -162,17 +162,20 @@ DBMgr::FindOpen( const char* cookie, int lang, int nPlayersT, int nPlayersH,
} /* FindOpen */
HostID
DBMgr::AddDevice( const char* connName, int nToAdd, unsigned short seed )
DBMgr::AddDevice( const char* connName, HostID curID, int nToAdd,
unsigned short seed )
{
HostID newID = HOST_ID_NONE;
int arr[4];
HostID newID = curID;
MutexLock ml( &m_dbMutex );
readArray_locked( connName, arr );
for ( newID = HOST_ID_SERVER; newID <= 4; ++newID ) {
if ( arr[newID-1] == 0 ) {
break;
if ( newID == HOST_ID_NONE ) {
int arr[4];
readArray_locked( connName, arr );
for ( newID = HOST_ID_SERVER; newID <= 4; ++newID ) {
if ( arr[newID-1] == 0 ) {
break;
}
}
}
assert( newID <= 4 );

View file

@ -46,7 +46,8 @@ class DBMgr {
int nPlayersH, bool wantsPublic,
char* connNameBuf, int bufLen, int* nPlayersHP );
HostID AddDevice( const char* const connName, int nToAdd, unsigned short seed );
HostID AddDevice( const char* const connName, HostID curID,
int nToAdd, unsigned short seed );
void RmDevice( const char* const connName, HostID id );
void AddCID( const char* connName, CookieID cid );
void ClearCID( const char* connName );

View file

@ -376,8 +376,9 @@ processReconnect( unsigned char* bufp, int bufLen, int socket )
&& readStr( &bufp, end, connName, sizeof(connName) ) ) {
SafeCref scr( connName[0]? connName : NULL,
srcID, socket, nPlayersH,
nPlayersT, gameSeed, langCode );
cookie, srcID, socket, nPlayersH,
nPlayersT, gameSeed, langCode,
wantsPublic, makePublic );
success = scr.Reconnect( socket, srcID, nPlayersH, nPlayersT,
gameSeed );
}