add GameFull -- database, not in-memory state, knows if game is full.

This commit is contained in:
Andy2 2010-11-15 06:48:36 -08:00
parent 14579c6e30
commit feca7345dc
2 changed files with 18 additions and 0 deletions

View file

@ -173,6 +173,23 @@ DBMgr::FindOpen( const char* cookie, int lang, int nPlayersT, int nPlayersH,
return cid;
} /* FindOpen */
bool
DBMgr::GameFull( const char* const connName )
{
const char* cmd = "SELECT ntotal=sum_array(nperdevice) from " GAMES_TABLE
" WHERE connName='%s'";
char query[256];
snprintf( query, sizeof(query), cmd, connName );
logf( XW_LOGINFO, "query: %s", query );
PGresult* result = PQexec( getThreadConn(), query );
int nTuples = PQntuples( result );
assert( nTuples <= 1 );
bool full = 't' == PQgetvalue( result, 0, 0 )[0];
PQclear( result );
return full;
}
HostID
DBMgr::AddDevice( const char* connName, HostID curID, int nToAdd,
unsigned short seed )

View file

@ -46,6 +46,7 @@ class DBMgr {
CookieID FindOpen( const char* cookie, int lang, int nPlayersT,
int nPlayersH, bool wantsPublic,
char* connNameBuf, int bufLen, int* nPlayersHP );
bool GameFull( const char* const connName );
HostID AddDevice( const char* const connName, HostID curID,
int nToAdd, unsigned short seed );