mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
pass hid in to db function getting per-dev info
Somehow I've been failing to treat this column as an array for some time. I don't have any test cases that failed but it was clearly wrong. Test cases still pass....
This commit is contained in:
parent
051b6a7220
commit
3645331061
5 changed files with 15 additions and 15 deletions
|
@ -337,7 +337,7 @@ CRefMgr::getMakeCookieRef( const char* connName, const char* cookie,
|
|||
} /* getMakeCookieRef */
|
||||
|
||||
CidInfo*
|
||||
CRefMgr::getMakeCookieRef( const char* const connName, bool* isDead )
|
||||
CRefMgr::getMakeCookieRef( const char* const connName, HostID hid, bool* isDead )
|
||||
{
|
||||
CookieRef* cref = NULL;
|
||||
CidInfo* cinfo = NULL;
|
||||
|
@ -347,7 +347,7 @@ CRefMgr::getMakeCookieRef( const char* const connName, bool* isDead )
|
|||
int nAlreadyHere = 0;
|
||||
|
||||
for ( ; ; ) { /* for: see comment above */
|
||||
CookieID cid = m_db->FindGame( connName, curCookie, sizeof(curCookie),
|
||||
CookieID cid = m_db->FindGame( connName, hid, curCookie, sizeof(curCookie),
|
||||
&curLangCode, &nPlayersT, &nAlreadyHere,
|
||||
isDead );
|
||||
if ( 0 != cid ) { /* already open */
|
||||
|
@ -672,13 +672,13 @@ SafeCref::SafeCref( const char* connName, const char* cookie, HostID hid,
|
|||
}
|
||||
|
||||
/* ConnName case -- must exist (unless DB record's been removed */
|
||||
SafeCref::SafeCref( const char* const connName )
|
||||
SafeCref::SafeCref( const char* const connName, HostID hid )
|
||||
: m_cinfo( NULL )
|
||||
, m_mgr( CRefMgr::Get() )
|
||||
, m_isValid( false )
|
||||
{
|
||||
bool isDead = false;
|
||||
CidInfo* cinfo = m_mgr->getMakeCookieRef( connName, &isDead );
|
||||
CidInfo* cinfo = m_mgr->getMakeCookieRef( connName, hid, &isDead );
|
||||
if ( NULL != cinfo && NULL != cinfo->GetRef() ) {
|
||||
assert( cinfo->GetCid() == cinfo->GetRef()->GetCid() );
|
||||
m_locked = cinfo->GetRef()->Lock();
|
||||
|
|
|
@ -128,7 +128,7 @@ class CRefMgr {
|
|||
int nPlayersS, int seed, int langCode,
|
||||
bool isPublic, bool* isDead );
|
||||
|
||||
CidInfo* getMakeCookieRef( const char* const connName, bool* isDead );
|
||||
CidInfo* getMakeCookieRef( const char* const connName, HostID hid, bool* isDead );
|
||||
|
||||
CidInfo* getCookieRef( CookieID cid, bool failOk = false );
|
||||
CidInfo* getCookieRef( const AddrInfo* addr );
|
||||
|
@ -179,7 +179,7 @@ class SafeCref {
|
|||
const AddrInfo* addr, int clientVersion, DevID* devID,
|
||||
int nPlayersH, int nPlayersS, unsigned short gameSeed,
|
||||
int clientIndx, int langCode, bool wantsPublic, bool makePublic );
|
||||
SafeCref( const char* const connName );
|
||||
SafeCref( const char* const connName, HostID hid );
|
||||
SafeCref( CookieID cid, bool failOk = false );
|
||||
SafeCref( const AddrInfo* addr );
|
||||
/* SafeCref( CookieRef* cref ); */
|
||||
|
|
|
@ -153,19 +153,19 @@ DBMgr::FindGameFor( const char* connName, char* cookieBuf, int bufLen,
|
|||
} /* FindGameFor */
|
||||
|
||||
CookieID
|
||||
DBMgr::FindGame( const char* connName, char* cookieBuf, int bufLen,
|
||||
DBMgr::FindGame( const char* connName, HostID hid, char* roomBuf, int roomBufLen,
|
||||
int* langP, int* nPlayersTP, int* nPlayersHP, bool* isDead )
|
||||
{
|
||||
MutexLock ml( &m_cidsMutex );
|
||||
|
||||
CookieID cid = 0;
|
||||
|
||||
const char* fmt = "SELECT room, lang, nTotal, nPerDevice, dead FROM "
|
||||
const char* fmt = "SELECT room, lang, nTotal, nPerDevice[%d], dead FROM "
|
||||
GAMES_TABLE " WHERE connName = '%s'"
|
||||
// " LIMIT 1"
|
||||
;
|
||||
StrWPF query;
|
||||
query.catf( fmt, connName );
|
||||
query.catf( fmt, hid, connName );
|
||||
logf( XW_LOGINFO, "query: %s", query.c_str() );
|
||||
|
||||
PGresult* result = PQexec( getThreadConn(), query.c_str() );
|
||||
|
@ -173,7 +173,7 @@ DBMgr::FindGame( const char* connName, char* cookieBuf, int bufLen,
|
|||
if ( 1 == PQntuples( result ) ) {
|
||||
int col = 0;
|
||||
cid = m_cidsMap[connName];
|
||||
snprintf( cookieBuf, bufLen, "%s", PQgetvalue( result, 0, col++ ) );
|
||||
snprintf( roomBuf, roomBufLen, "%s", PQgetvalue( result, 0, col++ ) );
|
||||
*langP = atoi( PQgetvalue( result, 0, col++ ) );
|
||||
*nPlayersTP = atoi( PQgetvalue( result, 0, col++ ) );
|
||||
*nPlayersHP = atoi( PQgetvalue( result, 0, col++ ) );
|
||||
|
|
|
@ -75,7 +75,7 @@ class DBMgr {
|
|||
bool FindRelayIDFor( const char* connName, HostID hid, unsigned short seed,
|
||||
const DevID* host, DevIDRelay* devID );
|
||||
|
||||
CookieID FindGame( const char* connName, char* cookieBuf, int bufLen,
|
||||
CookieID FindGame( const char* connName, HostID hid, char* cookieBuf, int bufLen,
|
||||
int* langP, int* nPlayersTP, int* nPlayersHP,
|
||||
bool* isDead );
|
||||
|
||||
|
|
|
@ -1446,7 +1446,7 @@ handleProxyMsgs( int sock, const AddrInfo* addr, const uint8_t* bufp,
|
|||
}
|
||||
unsigned short nMsgs;
|
||||
if ( getNetShort( &bufp, end, &nMsgs ) ) {
|
||||
SafeCref scr( connName );
|
||||
SafeCref scr( connName, hid );
|
||||
while ( scr.IsValid() && nMsgs-- > 0 ) {
|
||||
unsigned short len;
|
||||
if ( getNetShort( &bufp, end, &len ) ) {
|
||||
|
@ -1536,7 +1536,7 @@ proxy_thread_proc( UdpThreadClosure* utc )
|
|||
sizeof( connName ), &hid ) ) {
|
||||
break;
|
||||
}
|
||||
SafeCref scr( connName );
|
||||
SafeCref scr( connName, hid );
|
||||
scr.DeviceGone( hid, seed );
|
||||
}
|
||||
}
|
||||
|
@ -1774,7 +1774,7 @@ handle_udp_packet( UdpThreadClosure* utc )
|
|||
logf( XW_LOGERROR, "parse failed!!!" );
|
||||
break;
|
||||
}
|
||||
SafeCref scr( connName );
|
||||
SafeCref scr( connName, hid );
|
||||
if ( scr.IsValid() ) {
|
||||
AddrInfo addr( g_udpsock, clientToken, utc->saddr() );
|
||||
handlePutMessage( scr, hid, &addr, end - ptr, &ptr, end );
|
||||
|
@ -1841,7 +1841,7 @@ handle_udp_packet( UdpThreadClosure* utc )
|
|||
string connName;
|
||||
if ( DBMgr::Get()->FindPlayer( devID.asRelayID(), clientToken,
|
||||
connName, &hid, &seed ) ) {
|
||||
SafeCref scr( connName.c_str() );
|
||||
SafeCref scr( connName.c_str(), hid );
|
||||
scr.DeviceGone( hid, seed );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue