From aada1a912fbe4a2097964e4d1b184153f219eac7 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 14 Jul 2012 16:18:09 +0000 Subject: [PATCH] introduce command line argument for enabling the ping of the slave servers in the list to keep the NAT port open (central server functionality only) --- src/main.cpp | 78 ++++++++++++++++++++++++++++------------------ src/server.cpp | 4 ++- src/server.h | 3 +- src/serverlist.cpp | 17 +++++++--- src/serverlist.h | 2 ++ 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 083e1d47..f5fe0091 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,21 +53,22 @@ int main ( int argc, char** argv ) // initialize all flags and string which might be changed by command line // arguments - bool bIsClient = true; - bool bUseGUI = true; - bool bStartMinimized = false; - bool bConnectOnStartup = false; - bool bDisalbeLEDs = false; - bool bShowComplRegConnList = false; - int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; - quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; - QString strIniFileName = ""; - QString strHTMLStatusFileName = ""; - QString strServerName = ""; - QString strLoggingFileName = ""; - QString strHistoryFileName = ""; - QString strCentralServer = ""; - QString strServerInfo = ""; + bool bIsClient = true; + bool bUseGUI = true; + bool bStartMinimized = false; + bool bConnectOnStartup = false; + bool bDisalbeLEDs = false; + bool bShowComplRegConnList = false; + bool bCentServPingServerInList = false; + int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; + quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; + QString strIniFileName = ""; + QString strHTMLStatusFileName = ""; + QString strServerName = ""; + QString strLoggingFileName = ""; + QString strHistoryFileName = ""; + QString strCentralServer = ""; + QString strServerInfo = ""; // QT docu: argv()[0] is the program name, argv()[1] is the first // argument and argv()[argc()-1] is the last argument. @@ -143,6 +144,18 @@ int main ( int argc, char** argv ) } + // Ping servers in list for central server ----------------------------- + if ( GetFlagArgument ( argv, + i, + "-g", + "--pingservers" ) ) + { + bCentServPingServerInList = true; + tsConsole << "- ping servers in slave server list" << endl; + continue; + } + + // Show all registered servers in the server list ---------------------- // Undocumented debugging command line argument: Show all registered // servers in the server list regardless if a ping to the server is @@ -391,7 +404,8 @@ int main ( int argc, char** argv ) strHistoryFileName, strServerName, strCentralServer, - strServerInfo ); + strServerInfo, + bCentServPingServerInList ); if ( bUseGUI ) { @@ -469,30 +483,32 @@ QString UsageArguments ( char **argv ) return "Usage: " + QString ( argv[0] ) + " [option] [argument]\n" "\nRecognized options:\n" - " -s, --server start server\n" - " -n, --nogui disable GUI (server only)\n" - " -u, --numchannels maximum number of channels (server only)\n" - " -z, --startminimized start minimizied (server only)\n" - " -l, --log enable logging, set file name\n" - " -i, --inifile initialization file name (client only)\n" - " -p, --port local port number (server only)\n" - " -m, --htmlstatus enable HTML status file, set file name (server\n" - " only)\n" " -a, --servername server name, required for HTML status (server\n" " only)\n" - " -y, --history enable connection history and set file\n" - " name (server only)\n" + " -c, --connect connect to last server on startup (client\n" + " only)\n" + " -d, --disableleds disable LEDs in main window (client only)\n" " -e, --centralserver address of the central server (server only)\n" + " -g, --pingservers ping servers in list to keep NAT port open\n" + " (central server only)\n" + " -h, -?, --help this help text\n" + " -i, --inifile initialization file name (client only)\n" + " -l, --log enable logging, set file name\n" + " -m, --htmlstatus enable HTML status file, set file name (server\n" + " only)\n" + " -n, --nogui disable GUI (server only)\n" " -o, --serverinfo infos of the server(s) in the format:\n" " [name];[city];[country as QLocale ID]; ...\n" " [server1 address];[server1 name]; ...\n" " [server1 city]; ...\n" " [server1 country as QLocale ID]; ...\n" " [server2 address]; ... (server only)\n" - " -c, --connect connect to last server on startup (client\n" - " only)\n" - " -d, --disableleds disable LEDs in main window (client only)\n" - " -h, -?, --help this help text\n" + " -p, --port local port number (server only)\n" + " -s, --server start server\n" + " -u, --numchannels maximum number of channels (server only)\n" + " -y, --history enable connection history and set file\n" + " name (server only)\n" + " -z, --startminimized start minimizied (server only)\n" "\nExample: " + QString ( argv[0] ) + " -l -inifile myinifile.ini\n"; } diff --git a/src/server.cpp b/src/server.cpp index 92e782a8..8e699634 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -171,7 +171,8 @@ CServer::CServer ( const int iNewNumChan, const QString& strHistoryFileName, const QString& strServerNameForHTMLStatusFile, const QString& strCentralServer, - const QString& strServerInfo ) : + const QString& strServerInfo, + const bool bNCentServPingServerInList ) : iNumChannels ( iNewNumChan ), Socket ( this, iPortNumber ), bWriteStatusHTMLFile ( false ), @@ -179,6 +180,7 @@ CServer::CServer ( const int iNewNumChan, strCentralServer, strServerInfo, iNewNumChan, + bNCentServPingServerInList, &ConnLessProtocol ), bAutoRunMinimized ( false ) { diff --git a/src/server.h b/src/server.h index d7ef0298..0c29f0c3 100755 --- a/src/server.h +++ b/src/server.h @@ -110,7 +110,8 @@ public: const QString& strHistoryFileName, const QString& strServerNameForHTMLStatusFile, const QString& strCentralServer, - const QString& strServerInfo ); + const QString& strServerInfo, + const bool bNCentServPingServerInList ); void Start(); void Stop(); diff --git a/src/serverlist.cpp b/src/serverlist.cpp index b402627e..ce1950c8 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -30,11 +30,13 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum, const QString& sNCentServAddr, const QString& strServerInfo, const int iNumChannels, + const bool bNCentServPingServerInList, CProtocol* pNConLProt ) : iPortNumber ( iNPortNum ), iNumPredefinedServers ( 0 ), bUseDefaultCentralServerAddress ( false ), - pConnLessProtocol ( pNConLProt ) + pConnLessProtocol ( pNConLProt ), + bCentServPingServerInList ( bNCentServPingServerInList ) { // set the central server address SetCentralServerAddress ( sNCentServAddr ); @@ -200,8 +202,11 @@ void CServerListManager::Update() // 1 minute = 60 * 1000 ms TimerPollList.start ( SERVLIST_POLL_TIME_MINUTES * 60000 ); - // start timer for sending ping messages to servers in the list - TimerPingServerInList.start ( SERVLIST_UPDATE_PING_SERVERS_MS ); + if ( bCentServPingServerInList ) + { + // start timer for sending ping messages to servers in the list + TimerPingServerInList.start ( SERVLIST_UPDATE_PING_SERVERS_MS ); + } } else { @@ -235,7 +240,11 @@ void CServerListManager::Update() if ( bIsCentralServer ) { TimerPollList.stop(); - TimerPingServerInList.stop(); + + if ( bCentServPingServerInList ) + { + TimerPingServerInList.stop(); + } } else { diff --git a/src/serverlist.h b/src/serverlist.h index 599283f8..29ac78e8 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -129,6 +129,7 @@ public: const QString& sNCentServAddr, const QString& strServerInfo, const int iNumChannels, + const bool bNCentServPingServerInList, CProtocol* pNConLProt ); // the update has to be called if any change to the server list @@ -194,6 +195,7 @@ protected: bool bEnabled; bool bIsCentralServer; bool bUseDefaultCentralServerAddress; + bool bCentServPingServerInList; CHostAddress SlaveCurCentServerHostAddress;