From feca7345dcf8f1f6f82070c0f7f5a3837e99d561 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 15 Nov 2010 06:48:36 -0800 Subject: [PATCH] add GameFull -- database, not in-memory state, knows if game is full. --- xwords4/relay/dbmgr.cpp | 17 +++++++++++++++++ xwords4/relay/dbmgr.h | 1 + 2 files changed, 18 insertions(+) diff --git a/xwords4/relay/dbmgr.cpp b/xwords4/relay/dbmgr.cpp index eb3981804..4b0f69efd 100644 --- a/xwords4/relay/dbmgr.cpp +++ b/xwords4/relay/dbmgr.cpp @@ -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 ) diff --git a/xwords4/relay/dbmgr.h b/xwords4/relay/dbmgr.h index 6a354cdd2..7d778a46e 100644 --- a/xwords4/relay/dbmgr.h +++ b/xwords4/relay/dbmgr.h @@ -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 );