diff --git a/xwords4/relay/configs.cpp b/xwords4/relay/configs.cpp index 50374e052..681a1f0ab 100644 --- a/xwords4/relay/configs.cpp +++ b/xwords4/relay/configs.cpp @@ -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 ); diff --git a/xwords4/relay/configs.h b/xwords4/relay/configs.h index 34703f06e..66eda2175 100644 --- a/xwords4/relay/configs.h +++ b/xwords4/relay/configs.h @@ -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; }; diff --git a/xwords4/relay/permid.cpp b/xwords4/relay/permid.cpp index 0d8b5e2bf..d9a68cea8 100644 --- a/xwords4/relay/permid.cpp +++ b/xwords4/relay/permid.cpp @@ -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; +} diff --git a/xwords4/relay/permid.h b/xwords4/relay/permid.h index a7c2b5e1c..438e01494 100644 --- a/xwords4/relay/permid.h +++ b/xwords4/relay/permid.h @@ -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 diff --git a/xwords4/relay/xwrelay.conf b/xwords4/relay/xwrelay.conf index 1ca10dd0d..812c81a8f 100644 --- a/xwords4/relay/xwrelay.conf +++ b/xwords4/relay/xwrelay.conf @@ -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 diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index efd4844bb..a11889d19 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -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 ) {