mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
track device seeds in db.
This commit is contained in:
parent
a6f5ea5f4a
commit
bc65377cfd
4 changed files with 33 additions and 45 deletions
|
@ -791,7 +791,7 @@ CookieRef::increasePlayerCounts( CRefEvent* evt, bool reconn )
|
||||||
if ( !reconn ) {
|
if ( !reconn ) {
|
||||||
m_nPlayersHere += nPlayersH;
|
m_nPlayersHere += nPlayersH;
|
||||||
assert( m_nPlayersHere <= m_nPlayersSought );
|
assert( m_nPlayersHere <= m_nPlayersSought );
|
||||||
evt->u.con.srcID = DBMgr::Get()->AddDevice( ConnName(), nPlayersH );
|
evt->u.con.srcID = DBMgr::Get()->AddDevice( ConnName(), nPlayersH, seed );
|
||||||
}
|
}
|
||||||
HostID hostid = evt->u.con.srcID;
|
HostID hostid = evt->u.con.srcID;
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ DBMgr::FindOpen( const char* cookie, int lang, int nPlayersT, int nPlayersH,
|
||||||
} /* FindOpen */
|
} /* FindOpen */
|
||||||
|
|
||||||
HostID
|
HostID
|
||||||
DBMgr::AddDevice( const char* connName, int nToAdd )
|
DBMgr::AddDevice( const char* connName, int nToAdd, unsigned short seed )
|
||||||
{
|
{
|
||||||
HostID newID = HOST_ID_NONE;
|
HostID newID = HOST_ID_NONE;
|
||||||
int arr[4];
|
int arr[4];
|
||||||
|
@ -177,10 +177,10 @@ DBMgr::AddDevice( const char* connName, int nToAdd )
|
||||||
}
|
}
|
||||||
assert( newID <= 4 );
|
assert( newID <= 4 );
|
||||||
|
|
||||||
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d "
|
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d,"
|
||||||
"WHERE connName = '%s'";
|
" seeds[%d] = %d WHERE connName = '%s'";
|
||||||
char query[256];
|
char query[256];
|
||||||
snprintf( query, sizeof(query), fmt, newID, nToAdd, connName );
|
snprintf( query, sizeof(query), fmt, newID, nToAdd, newID, seed, connName );
|
||||||
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
|
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
|
||||||
|
|
||||||
execSql_locked( query );
|
execSql_locked( query );
|
||||||
|
@ -191,10 +191,10 @@ DBMgr::AddDevice( const char* connName, int nToAdd )
|
||||||
void
|
void
|
||||||
DBMgr::RmDevice( const char* connName, HostID hid )
|
DBMgr::RmDevice( const char* connName, HostID hid )
|
||||||
{
|
{
|
||||||
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = 0 "
|
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = 0, "
|
||||||
"WHERE connName = '%s'";
|
"seeds[%d] = 0 WHERE connName = '%s'";
|
||||||
char query[256];
|
char query[256];
|
||||||
snprintf( query, sizeof(query), fmt, hid, connName );
|
snprintf( query, sizeof(query), fmt, hid, hid, connName );
|
||||||
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
|
logf( XW_LOGINFO, "%s: query: %s", __func__, query );
|
||||||
|
|
||||||
execSql( query );
|
execSql( query );
|
||||||
|
@ -233,11 +233,11 @@ DBMgr::ClearCIDs( void )
|
||||||
void
|
void
|
||||||
DBMgr::PublicRooms( int lang, int nPlayers, int* nNames, string& names )
|
DBMgr::PublicRooms( int lang, int nPlayers, int* nNames, string& names )
|
||||||
{
|
{
|
||||||
int ii;
|
|
||||||
int nTuples;
|
|
||||||
|
|
||||||
const char* fmt = "SELECT room, nTotal-" ARRAYSUM " FROM " GAMES_TABLE
|
const char* fmt = "SELECT room, nTotal-" ARRAYSUM " FROM " GAMES_TABLE
|
||||||
" WHERE pub = TRUE AND lang = %d AND ntotal =% d";
|
" WHERE pub = TRUE"
|
||||||
|
" AND lang = %d"
|
||||||
|
" AND nTotal>" ARRAYSUM
|
||||||
|
" AND nTotal = %d";
|
||||||
|
|
||||||
char query[256];
|
char query[256];
|
||||||
snprintf( query, sizeof(query), fmt, lang, nPlayers );
|
snprintf( query, sizeof(query), fmt, lang, nPlayers );
|
||||||
|
@ -246,20 +246,15 @@ DBMgr::PublicRooms( int lang, int nPlayers, int* nNames, string& names )
|
||||||
MutexLock ml( &m_dbMutex );
|
MutexLock ml( &m_dbMutex );
|
||||||
|
|
||||||
PGresult* result = PQexec( m_pgconn, query );
|
PGresult* result = PQexec( m_pgconn, query );
|
||||||
nTuples = PQntuples( result );
|
int nTuples = PQntuples( result );
|
||||||
int goodCount = 0;
|
for ( int ii = 0; ii < nTuples; ++ii ) {
|
||||||
for ( ii = 0; ii < nTuples; ++ii ) {
|
names.append( PQgetvalue( result, ii, 0 ) );
|
||||||
int nOpen = atoi( PQgetvalue( result, ii, 1 ) );
|
names.append( "/" );
|
||||||
if ( nOpen > 0 ) {
|
names.append( PQgetvalue( result, ii, 1 ) );
|
||||||
names.append( PQgetvalue( result, ii, 0 ) );
|
names.append( "\n" );
|
||||||
names.append( "/" );
|
|
||||||
names.append( PQgetvalue( result, ii, 1 ) );
|
|
||||||
names.append( "\n" );
|
|
||||||
++goodCount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
PQclear( result );
|
PQclear( result );
|
||||||
*nNames = goodCount;
|
*nNames = nTuples;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -428,23 +423,3 @@ DBMgr::RemoveStoredMessage( int msgID )
|
||||||
|
|
||||||
execSql( query );
|
execSql( query );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Schema:
|
|
||||||
CREATE TABLE games (
|
|
||||||
cid integer,
|
|
||||||
room VARCHAR(32),
|
|
||||||
connName VARCHAR(64) UNIQUE PRIMARY KEY,
|
|
||||||
nTotal INTEGER,
|
|
||||||
nPerDevice INTEGER[],
|
|
||||||
lang INTEGER,
|
|
||||||
ctime TIMESTAMP,
|
|
||||||
mtime TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
May also want
|
|
||||||
seeds INTEGER ARRAY,
|
|
||||||
ipAddresses INTEGER ARRAY,
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class DBMgr {
|
||||||
int nPlayersH, bool wantsPublic,
|
int nPlayersH, bool wantsPublic,
|
||||||
char* connNameBuf, int bufLen, int* nPlayersHP );
|
char* connNameBuf, int bufLen, int* nPlayersHP );
|
||||||
|
|
||||||
HostID AddDevice( const char* const connName, int nToAdd );
|
HostID AddDevice( const char* const connName, int nToAdd, unsigned short seed );
|
||||||
void RmDevice( const char* const connName, HostID id );
|
void RmDevice( const char* const connName, HostID id );
|
||||||
void AddCID( const char* connName, CookieID cid );
|
void AddCID( const char* connName, CookieID cid );
|
||||||
void ClearCID( const char* connName );
|
void ClearCID( const char* connName );
|
||||||
|
|
|
@ -18,6 +18,18 @@ usage() {
|
||||||
|
|
||||||
make_db() {
|
make_db() {
|
||||||
createdb xwgames
|
createdb xwgames
|
||||||
|
cat | psql xwgames --file - <<EOF
|
||||||
|
create or replace function sum_array( DECIMAL [] )
|
||||||
|
returns decimal
|
||||||
|
as \$\$
|
||||||
|
select sum(\$1[i])
|
||||||
|
from generate_series(
|
||||||
|
array_lower(\$1,1),
|
||||||
|
array_upper(\$1,1)
|
||||||
|
) g(i);
|
||||||
|
\$\$ language sql immutable;
|
||||||
|
EOF
|
||||||
|
|
||||||
cat | psql xwgames --file - <<EOF
|
cat | psql xwgames --file - <<EOF
|
||||||
CREATE TABLE games (
|
CREATE TABLE games (
|
||||||
cid integer,
|
cid integer,
|
||||||
|
@ -27,6 +39,7 @@ pub BOOLEAN,
|
||||||
connName VARCHAR(64) UNIQUE PRIMARY KEY,
|
connName VARCHAR(64) UNIQUE PRIMARY KEY,
|
||||||
nTotal INTEGER,
|
nTotal INTEGER,
|
||||||
nPerDevice INTEGER[],
|
nPerDevice INTEGER[],
|
||||||
|
seeds INTEGER[],
|
||||||
ctime TIMESTAMP,
|
ctime TIMESTAMP,
|
||||||
mtime TIMESTAMP
|
mtime TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue