mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-17 18:12:01 +01:00
make location of file storing next ID configurable.
This commit is contained in:
parent
deb0a2d265
commit
b135f317b4
6 changed files with 38 additions and 5 deletions
|
@ -105,6 +105,8 @@ RelayConfigs::parse( const char* fname )
|
|||
m_nWorkerThreads = atoi( value );
|
||||
} else if ( 0 == strcmp( line, "SERVERNAME" ) ) {
|
||||
m_serverName = value;
|
||||
} else if ( 0 == strcmp( line, "IDFILE" ) ) {
|
||||
m_idFileName = value;
|
||||
} else {
|
||||
logf( XW_LOGERROR, "unknown key %s with value %s\n",
|
||||
line, value );
|
||||
|
|
|
@ -38,7 +38,7 @@ class RelayConfigs {
|
|||
time_t GetAllConnectedInterval() { return m_allConnInterval; }
|
||||
time_t GetHeartbeatInterval() { return m_heartbeatInterval; }
|
||||
const char* GetServerName() { return m_serverName.c_str(); }
|
||||
|
||||
const char* GetIdFileName() { return m_idFileName.c_str(); }
|
||||
|
||||
private:
|
||||
RelayConfigs( const char* cfile );
|
||||
|
@ -50,6 +50,7 @@ class RelayConfigs {
|
|||
int m_port;
|
||||
int m_nWorkerThreads;
|
||||
std::string m_serverName;
|
||||
std::string m_idFileName;
|
||||
|
||||
static RelayConfigs* instance;
|
||||
};
|
||||
|
|
|
@ -27,10 +27,12 @@ using namespace std;
|
|||
|
||||
pthread_mutex_t PermID::s_guard = PTHREAD_MUTEX_INITIALIZER;
|
||||
string PermID::s_serverName;
|
||||
string PermID::s_idFileName;
|
||||
|
||||
string
|
||||
PermID::GetNextUniqueID()
|
||||
{
|
||||
const char* fileName = s_idFileName.c_str();
|
||||
MutexLock ml( &s_guard );
|
||||
|
||||
string s = s_serverName;
|
||||
|
@ -39,12 +41,12 @@ PermID::GetNextUniqueID()
|
|||
|
||||
char buf[32]; /* should last for a while :-) */
|
||||
|
||||
FILE* f = fopen( "/etc/xwrelay/xwrelay_id.txt", "r+" );
|
||||
FILE* f = fopen( fileName, "r+" );
|
||||
if ( f ) {
|
||||
fscanf( f, "%s\n", buf );
|
||||
rewind( f );
|
||||
} else {
|
||||
f = fopen( "/etc/xwrelay/xwrelay_id.txt", "w" );
|
||||
f = fopen( fileName, "w" );
|
||||
assert ( f != NULL );
|
||||
buf[0] = '0';
|
||||
buf[1] = '\0';
|
||||
|
@ -66,3 +68,9 @@ PermID::SetServerName( const char* name )
|
|||
{
|
||||
s_serverName = name;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
PermID::SetIDFileName( const char* name )
|
||||
{
|
||||
s_idFileName = name;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
class PermID {
|
||||
public:
|
||||
static void SetServerName( const char* name );
|
||||
static void SetIDFileName( const char* name );
|
||||
static std::string GetNextUniqueID();
|
||||
|
||||
private:
|
||||
|
@ -42,5 +43,7 @@ class PermID {
|
|||
this, which is supposed to be
|
||||
unique to this relay
|
||||
instance. */
|
||||
static std::string s_idFileName; /* The incremented part of the
|
||||
name is stored where? */
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -22,4 +22,8 @@ CTLPORT=11000
|
|||
|
||||
# Need a unique name for every instance of the relay so they can
|
||||
# create game ids guaranteed to be unique
|
||||
#SERVERNAME=eehouse.org
|
||||
SERVERNAME=eehouse.org
|
||||
|
||||
# Where will the file live that stores the last ID used for a new
|
||||
# connName.
|
||||
#IDFILE=/home/ehouse/xwrelay_id.txt
|
||||
|
|
|
@ -394,6 +394,7 @@ enum { FLAG_HELP
|
|||
,FLAG_CPORT
|
||||
,FLAG_NTHREADS
|
||||
,FLAG_NAME
|
||||
,FLAG_IDNAME
|
||||
};
|
||||
|
||||
struct option longopts[] = {
|
||||
|
@ -421,6 +422,12 @@ struct option longopts[] = {
|
|||
NULL,
|
||||
FLAG_NAME
|
||||
}
|
||||
,{
|
||||
"idFile",
|
||||
1,
|
||||
NULL,
|
||||
FLAG_IDNAME
|
||||
}
|
||||
,{
|
||||
"ctrlport",
|
||||
1,
|
||||
|
@ -493,6 +500,7 @@ int main( int argc, char** argv )
|
|||
int nWorkerThreads = 0;
|
||||
char* conffile = NULL;
|
||||
const char* serverName = NULL;
|
||||
const char* idFileName = NULL;
|
||||
|
||||
/* Verify sizes here... */
|
||||
assert( sizeof(CookieID) == 2 );
|
||||
|
@ -503,7 +511,7 @@ int main( int argc, char** argv )
|
|||
first. */
|
||||
|
||||
for ( ; ; ) {
|
||||
int opt = getopt_long(argc, argv, "hc:p:l:n:",longopts, NULL);
|
||||
int opt = getopt_long(argc, argv, "hc:p:l:n:i:", longopts, NULL);
|
||||
|
||||
if ( opt == -1 ) {
|
||||
break;
|
||||
|
@ -522,6 +530,9 @@ int main( int argc, char** argv )
|
|||
case FLAG_NAME:
|
||||
serverName = optarg;
|
||||
break;
|
||||
case FLAG_IDNAME:
|
||||
idFileName = optarg;
|
||||
break;
|
||||
case FLAG_CPORT:
|
||||
ctrlport = atoi( optarg );
|
||||
break;
|
||||
|
@ -549,8 +560,12 @@ int main( int argc, char** argv )
|
|||
if ( serverName == NULL ) {
|
||||
serverName = cfg->GetServerName();
|
||||
}
|
||||
if ( idFileName == NULL ) {
|
||||
idFileName = cfg->GetIdFileName();
|
||||
}
|
||||
|
||||
PermID::SetServerName( serverName );
|
||||
PermID::SetIDFileName( idFileName );
|
||||
|
||||
g_listener = make_socket( INADDR_ANY, port );
|
||||
if ( g_listener == -1 ) {
|
||||
|
|
Loading…
Reference in a new issue