new dbmgr API returns number of players in game; use that rather than

currently connected devices to populate [RE]CONNECT message
This commit is contained in:
Andy2 2010-10-22 22:34:43 -07:00
parent 593dac9d99
commit 7cf4535b4c
3 changed files with 22 additions and 2 deletions

View file

@ -911,8 +911,10 @@ CookieRef::sendResponse( const CRefEvent* evt, bool initial )
*bufp++ = evt->u.con.srcID;
putNetShort( &bufp, GetCookieID() );
putNetShort( &bufp, GetHeartbeat() );
*bufp++ = GetPlayersSought();
*bufp++ = GetPlayersHere();
int nTotal, nHere;
DBMgr::Get()->GetPlayerCounts( ConnName(), &nTotal, &nHere );
*bufp++ = nTotal;
*bufp++ = nHere;
const char* connName = ConnName();
assert( !!connName && connName[0] );

View file

@ -224,6 +224,22 @@ DBMgr::RecordSent( const char* const connName, int nBytes )
execSql( query );
}
void
DBMgr::GetPlayerCounts( const char* const connName, int* nTotal, int* nHere )
{
const char* fmt = "SELECT ntotal, sum_array(nperdevice) FROM " GAMES_TABLE
" WHERE connName = '%s'";
char query[256];
snprintf( query, sizeof(query), fmt, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
PGresult* result = PQexec( getThreadConn(), query );
assert( 1 == PQntuples( result ) );
*nTotal = atoi( PQgetvalue( result, 0, 0 ) );
*nHere = atoi( PQgetvalue( result, 0, 1 ) );
PQclear( result );
}
void
DBMgr::ClearCIDs( void )
{

View file

@ -52,6 +52,8 @@ class DBMgr {
void AddCID( const char* connName, CookieID cid );
void ClearCID( const char* connName );
void RecordSent( const char* const connName, int nBytes );
void GetPlayerCounts( const char* const connName, int* nTotal,
int* nHere );
/* Return list of roomName/playersStillWanted/age for open public games
matching this language and total game size. Will probably want to cache