mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
pass through to database whether room is public
This commit is contained in:
parent
e3053370d0
commit
54d268b718
6 changed files with 32 additions and 22 deletions
|
@ -132,11 +132,12 @@ CRefMgr::CloseAll()
|
|||
CookieRef*
|
||||
CRefMgr::FindOpenGameFor( const char* cookie, const char* connName,
|
||||
HostID hid, int socket, int nPlayersH, int nPlayersT,
|
||||
int gameSeed, int langCode, bool* alreadyHere )
|
||||
int gameSeed, int langCode, bool wantsPublic,
|
||||
bool* alreadyHere )
|
||||
{
|
||||
#if 1
|
||||
CookieRef* found = NULL;
|
||||
CookieID cid = m_db->FindOpen( cookie, langCode, nPlayersT, nPlayersH );
|
||||
CookieID cid = m_db->FindOpen( cookie, langCode, nPlayersT, nPlayersH, wantsPublic );
|
||||
if ( cid > 0 ) {
|
||||
found = getCookieRef_impl( cid );
|
||||
}
|
||||
|
@ -335,7 +336,8 @@ CRefMgr::getFromFreeList( void )
|
|||
CookieRef*
|
||||
CRefMgr::getMakeCookieRef_locked( const char* cookie, const char* connName,
|
||||
HostID hid, int socket, int nPlayersH,
|
||||
int nPlayersT, int langCode, int gameSeed )
|
||||
int nPlayersT, int langCode, int gameSeed,
|
||||
bool wantsPublic, bool makePublic )
|
||||
{
|
||||
CookieRef* cref;
|
||||
|
||||
|
@ -349,11 +351,11 @@ CRefMgr::getMakeCookieRef_locked( const char* cookie, const char* connName,
|
|||
|
||||
bool alreadyHere;
|
||||
cref = FindOpenGameFor( cookie, connName, hid, socket, nPlayersH, nPlayersT,
|
||||
gameSeed, langCode, &alreadyHere );
|
||||
gameSeed, langCode, wantsPublic, &alreadyHere );
|
||||
if ( cref == NULL && !alreadyHere ) {
|
||||
CookieID cid = nextCID( NULL );
|
||||
cref = AddNew( cookie, connName, cid, langCode, nPlayersT );
|
||||
m_db->AddNew( cookie, cref->ConnName(), cid, langCode, nPlayersT );
|
||||
m_db->AddNew( cookie, cref->ConnName(), cid, langCode, nPlayersT, makePublic );
|
||||
}
|
||||
|
||||
return cref;
|
||||
|
@ -684,7 +686,7 @@ SafeCref::SafeCref( const char* cookie, int socket, int nPlayersH, int nPlayersS
|
|||
|
||||
cref = m_mgr->getMakeCookieRef_locked( cookie, NULL, 0, socket,
|
||||
nPlayersH, nPlayersS, langCode,
|
||||
gameSeed );
|
||||
gameSeed, wantsPublic, makePublic );
|
||||
if ( cref != NULL ) {
|
||||
m_locked = cref->Lock();
|
||||
m_cref = cref;
|
||||
|
@ -703,7 +705,7 @@ SafeCref::SafeCref( const char* connName, HostID hid,
|
|||
CookieRef* cref;
|
||||
|
||||
cref = m_mgr->getMakeCookieRef_locked( NULL, connName, hid, socket, nPlayersH,
|
||||
nPlayersS, langCode, gameSeed );
|
||||
nPlayersS, langCode, gameSeed, false, false );
|
||||
if ( cref != NULL ) {
|
||||
m_locked = cref->Lock();
|
||||
m_cref = cref;
|
||||
|
|
|
@ -138,7 +138,8 @@ class CRefMgr {
|
|||
CookieRef* getMakeCookieRef_locked( const char* cookie,
|
||||
const char* connName,
|
||||
HostID hid, int socket, int nPlayersH,
|
||||
int nPlayersS, int langCode, int seed );
|
||||
int nPlayersS, int langCode, int seed,
|
||||
bool wantsPublic, bool makePublic );
|
||||
CookieRef* getCookieRef( CookieID cookieID );
|
||||
CookieRef* getCookieRef( int socket );
|
||||
bool checkCookieRef_locked( CookieRef* cref );
|
||||
|
@ -148,7 +149,7 @@ class CRefMgr {
|
|||
CookieRef* FindOpenGameFor( const char* cookie, const char* connName,
|
||||
HostID hid, int socket, int nPlayersH,
|
||||
int nPlayersS, int gameSeed, int langCode,
|
||||
bool* alreadyHere );
|
||||
bool wantsPublic, bool* alreadyHere );
|
||||
|
||||
CookieID cookieIDForConnName( const char* connName );
|
||||
CookieID nextCID( const char* connName );
|
||||
|
|
|
@ -45,7 +45,10 @@ DBMgr::DBMgr()
|
|||
logf( XW_LOGINFO, "%s:, m_pgconn: %p", __func__, m_pgconn );
|
||||
|
||||
ConnStatusType status = PQstatus( m_pgconn );
|
||||
assert( status == CONNECTION_OK );
|
||||
if ( CONNECTION_OK != status ) {
|
||||
fprintf( stderr, "%s: unable to open db; does it exist?\n", __func__ );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
/* Now figure out what the largest cid currently is. There must be a way
|
||||
to get postgres to do this for me.... */
|
||||
|
@ -72,18 +75,18 @@ DBMgr::~DBMgr()
|
|||
|
||||
void
|
||||
DBMgr::AddNew( const char* cookie, const char* connName, CookieID cid,
|
||||
int langCode, int nPlayersT )
|
||||
int langCode, int nPlayersT, bool isPublic )
|
||||
{
|
||||
#if 1
|
||||
if ( !cookie ) cookie = "";
|
||||
if ( !connName ) connName = "";
|
||||
|
||||
const char* fmt = "INSERT INTO " DB_NAME
|
||||
" (cid, cookie, connName, nTotal, nHere, lang, ctime) "
|
||||
const char* fmt = "INSERT INTO " TABLE_NAME
|
||||
"(cid, cookie, connName, nTotal, nHere, lang, ispublic, ctime) "
|
||||
"VALUES( %d, '%s', '%s', %d, %d, %d, 'now' )";
|
||||
char buf[256];
|
||||
snprintf( buf, sizeof(buf), fmt, cid/*m_nextCID++*/, cookie, connName,
|
||||
nPlayersT, 0, langCode );
|
||||
nPlayersT, 0, langCode, isPublic?"TRUE":"FALSE" );
|
||||
logf( XW_LOGINFO, "passing %s", buf );
|
||||
execSql( buf );
|
||||
#else
|
||||
|
@ -110,18 +113,19 @@ DBMgr::AddNew( const char* cookie, const char* connName, CookieID cid,
|
|||
}
|
||||
|
||||
CookieID
|
||||
DBMgr::FindOpen( const char* cookie, int lang, int nPlayersT, int nPlayersH )
|
||||
DBMgr::FindOpen( const char* cookie, int lang, int nPlayersT, int nPlayersH, bool wantsPublic )
|
||||
{
|
||||
CookieID cid = 0;
|
||||
|
||||
const char* fmt = "SELECT cid from " DB_NAME " where cookie = '%s' "
|
||||
const char* fmt = "SELECT cid from " TABLE_NAME " where cookie = '%s' "
|
||||
"AND lang = %d "
|
||||
"AND nTotal = %d "
|
||||
"AND %d <= nTotal-nHere "
|
||||
"AND %s = ispublic "
|
||||
"LIMIT 1";
|
||||
char query[256];
|
||||
snprintf( query, sizeof(query), fmt,
|
||||
cookie, lang, nPlayersT, nPlayersH );
|
||||
cookie, lang, nPlayersT, nPlayersH, wantsPublic?"TRUE":"FALSE" );
|
||||
logf( XW_LOGINFO, "query: %s", query );
|
||||
|
||||
PGresult* result = PQexec( m_pgconn, query );
|
||||
|
@ -137,7 +141,7 @@ DBMgr::FindOpen( const char* cookie, int lang, int nPlayersT, int nPlayersH )
|
|||
void
|
||||
DBMgr::AddPlayers( const char* connName, int nToAdd )
|
||||
{
|
||||
const char* fmt = "UPDATE " DB_NAME " SET nHere = nHere+%d "
|
||||
const char* fmt = "UPDATE " TABLE_NAME " SET nHere = nHere+%d "
|
||||
"WHERE connName = '%s'";
|
||||
char query[256];
|
||||
snprintf( query, sizeof(query), fmt, nToAdd, connName );
|
||||
|
|
|
@ -33,10 +33,10 @@ class DBMgr {
|
|||
void ClearCIDs( void );
|
||||
|
||||
void AddNew( const char* cookie, const char* connName, CookieID cid,
|
||||
int langCode, int nPlayersT );
|
||||
int langCode, int nPlayersT, bool isPublic );
|
||||
|
||||
CookieID FindOpen( const char* cookie, int lang, int nPlayersT,
|
||||
int nPlayersH );
|
||||
int nPlayersH, bool wantsPublic );
|
||||
|
||||
void AddPlayers( const char* connName, int nToAdd );
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ HEARTBEAT=60
|
|||
# How many worker threads in the thread pool? Default is five.
|
||||
NTHREADS=3
|
||||
|
||||
# How many seconds to wait for device to ack new connName
|
||||
DEVACK=3
|
||||
|
||||
# What ports do we listen on for per-game incoming connections?
|
||||
GAME_PORTS=10999
|
||||
#PORTS=10997,10998,10999
|
||||
|
|
|
@ -322,7 +322,7 @@ processConnect( unsigned char* bufp, int bufLen, int socket )
|
|||
&& getNetByte( &bufp, end, &nPlayersT )
|
||||
&& getNetShort( &bufp, end, &gameSeed )
|
||||
&& getNetByte( &bufp, end, &langCode ) ) {
|
||||
logf( XW_LOGINFO, "%s(): langCode=%d", __func__, langCode );
|
||||
logf( XW_LOGINFO, "%s(): langCode=%d; wantsPublic=%d", __func__, langCode, wantsPublic );
|
||||
|
||||
/* Make sure second thread can't create new cref for same cookie
|
||||
this one just handled.*/
|
||||
|
@ -518,7 +518,7 @@ processMessage( unsigned char* buf, int bufLen, int socket )
|
|||
killSocket( socket, "failure" );
|
||||
}
|
||||
|
||||
return success; /* caller defines non-0 as failure */
|
||||
return success;
|
||||
} /* processMessage */
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue