mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
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:
parent
593dac9d99
commit
7cf4535b4c
3 changed files with 22 additions and 2 deletions
|
@ -911,8 +911,10 @@ CookieRef::sendResponse( const CRefEvent* evt, bool initial )
|
||||||
*bufp++ = evt->u.con.srcID;
|
*bufp++ = evt->u.con.srcID;
|
||||||
putNetShort( &bufp, GetCookieID() );
|
putNetShort( &bufp, GetCookieID() );
|
||||||
putNetShort( &bufp, GetHeartbeat() );
|
putNetShort( &bufp, GetHeartbeat() );
|
||||||
*bufp++ = GetPlayersSought();
|
int nTotal, nHere;
|
||||||
*bufp++ = GetPlayersHere();
|
DBMgr::Get()->GetPlayerCounts( ConnName(), &nTotal, &nHere );
|
||||||
|
*bufp++ = nTotal;
|
||||||
|
*bufp++ = nHere;
|
||||||
|
|
||||||
const char* connName = ConnName();
|
const char* connName = ConnName();
|
||||||
assert( !!connName && connName[0] );
|
assert( !!connName && connName[0] );
|
||||||
|
|
|
@ -224,6 +224,22 @@ DBMgr::RecordSent( const char* const connName, int nBytes )
|
||||||
execSql( query );
|
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
|
void
|
||||||
DBMgr::ClearCIDs( void )
|
DBMgr::ClearCIDs( void )
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,8 @@ class DBMgr {
|
||||||
void AddCID( const char* connName, CookieID cid );
|
void AddCID( const char* connName, CookieID cid );
|
||||||
void ClearCID( const char* connName );
|
void ClearCID( const char* connName );
|
||||||
void RecordSent( const char* const connName, int nBytes );
|
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
|
/* Return list of roomName/playersStillWanted/age for open public games
|
||||||
matching this language and total game size. Will probably want to cache
|
matching this language and total game size. Will probably want to cache
|
||||||
|
|
Loading…
Reference in a new issue