finish first pass at sending open public room names -- but with actual

list harvesting stubbed out.
This commit is contained in:
Andy2 2010-09-21 06:27:31 -07:00
parent 2ec67c8ed1
commit e7b5923883
3 changed files with 38 additions and 5 deletions

View file

@ -225,6 +225,14 @@ DBMgr::ClearCIDs( void )
execSql( "UPDATE " TABLE_NAME " set cid = null" );
}
void
DBMgr::PublicRooms( int lang, int nPlayers, int* nNames, string& names )
{
*nNames = 2;
names.append( "hello world/2\n" );
names.append( "Room 222/1\n" );
}
void
DBMgr::execSql( const char* query )
{

View file

@ -21,9 +21,13 @@
#ifndef _DBMGR_H_
#define _DBMGR_H_
#include <string>
#include "xwrelay.h"
#include <libpq-fe.h>
using namespace std;
class DBMgr {
public:
static DBMgr* Get();
@ -46,6 +50,12 @@ class DBMgr {
void AddCID( const char* connName, CookieID cid );
void ClearCID( const char* connName );
/* Return list of roomName/playersStillWanted for open public games
matching this language and total game size. Will probably want to cache
lists locally and only update them every few seconds to avoid to many
queries.*/
void PublicRooms( int lang, int nPlayers, int* nNames, string& names );
private:
DBMgr();
void execSql( const char* query ); /* no-results query */

View file

@ -74,6 +74,7 @@
#include "timermgr.h"
#include "permid.h"
#include "lstnrmgr.h"
#include "dbmgr.h"
static int s_nSpawns = 0;
#define MAX_PROXY_LEN 64
@ -645,18 +646,20 @@ handlePipe( int sig )
logf( XW_LOGINFO, "%s", __func__ );
}
bool
int
read_packet( int sock, unsigned char* buf, int buflen )
{
bool result = false;
int result = -1;
ssize_t nread;
unsigned short msgLen;
nread = recv( sock, &msgLen, sizeof(msgLen), MSG_WAITALL );
if ( nread == sizeof(msgLen) ) {
msgLen = ntohs( msgLen );
if ( msgLen >= buflen ) {
if ( msgLen <= buflen ) {
nread = recv( sock, buf, msgLen, MSG_WAITALL );
result = nread == msgLen;
if ( nread == msgLen ) {
result = nread;
}
}
}
return result;
@ -677,7 +680,19 @@ handle_proxy_tproc( void* closure )
case PRX_NONE:
break;
case PRX_PUBROOMS:
logf( XW_LOGINFO, "%s: PRX_PUBROOMS", __func__ );
if ( len >= 4 ) {
int lang = *bufp++;
int nPlayers = *bufp++;
string names;
int nNames;
DBMgr::Get()->PublicRooms( lang, nPlayers, &nNames, names );
unsigned short netshort = htons( names.size()
+ sizeof(unsigned short) );
write( sock, &netshort, sizeof(netshort) );
netshort = htons( (unsigned short)nNames );
write( sock, &netshort, sizeof(netshort) );
write( sock, names.c_str(), names.size() );
}
break;
}
}