support for setting the server info parameters via the command line arguments

This commit is contained in:
Volker Fischer 2011-04-25 13:25:33 +00:00
parent 3322af3bcc
commit 886251367b
5 changed files with 578 additions and 524 deletions

View File

@ -64,6 +64,7 @@ int main ( int argc, char** argv )
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.
@ -196,6 +197,21 @@ int main ( int argc, char** argv )
}
// Server info ---------------------------------------------------------
if ( GetStringArgument ( tsConsole,
argc,
argv,
i,
"-o",
"--serverinfo",
strArgument ) )
{
strServerInfo = strArgument;
tsConsole << "- server info: " << strServerInfo << endl;
continue;
}
// Initialization file -------------------------------------------------
if ( GetStringArgument ( tsConsole,
argc,
@ -328,7 +344,8 @@ int main ( int argc, char** argv )
strHTMLStatusFileName,
strHistoryFileName,
strServerName,
strCentralServer );
strCentralServer,
strServerInfo );
if ( bUseGUI )
{
@ -394,6 +411,9 @@ QString UsageArguments ( char **argv )
" -y, --history enable connection history and set file\n"
" name (server only)\n"
" -e, --centralserver address of the central server (server only)\n"
" -o, --serverinfo infos of the server in the format:"
" [name];[city];[country as QLocale ID] (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"

View File

@ -169,10 +169,12 @@ CServer::CServer ( const QString& strLoggingFileName,
const QString& strHTMLStatusFileName,
const QString& strHistoryFileName,
const QString& strServerNameForHTMLStatusFile,
const QString& strCentralServer ) :
const QString& strCentralServer,
const QString& strServerInfo ) :
Socket ( this, iPortNumber ),
bWriteStatusHTMLFile ( false ),
ServerListManager ( strCentralServer,
strServerInfo,
&ConnLessProtocol )
{
int i;

View File

@ -108,7 +108,8 @@ public:
const QString& strHTMLStatusFileName,
const QString& strHistoryFileName,
const QString& strServerNameForHTMLStatusFile,
const QString& strCentralServer );
const QString& strCentralServer,
const QString& strServerInfo );
void Start();
void Stop();

View File

@ -27,6 +27,7 @@
/* Implementation *************************************************************/
CServerListManager::CServerListManager ( const QString& sNCentServAddr,
const QString& strServerInfo,
CProtocol* pNConLProt )
: strCentralServerAddress ( sNCentServAddr ),
pConnLessProtocol ( pNConLProt )
@ -54,17 +55,46 @@ CServerListManager::CServerListManager ( const QString& sNCentServAddr,
// never be deleted
ServerList.clear();
// per definition the client substitudes the IP address of the central server
// itself for his server list
ServerList.append ( CServerListEntry (
// init server list entry (server info for this server) with defaults, per
// definition the client substitudes the IP address of the central server
// itself for his server list
CServerListEntry ThisServerListEntry (
CHostAddress(),
"Master Server", // TEST
"",
QLocale::Germany, // TEST
"Munich", // TEST
"",
QLocale::AnyCountry,
"",
USED_NUM_CHANNELS,
true ) ); // TEST
false );
// parse the server info string according to definition:
// [name];[city];[country as QLocale ID]
if ( !strServerInfo.isEmpty() )
{
// split the different parameter strings
QStringList slSeparateParameters = strServerInfo.split ( ";" );
// per definition, we expect three parameters
if ( slSeparateParameters.count() == 3 )
{
// [name]
ThisServerListEntry.strName = slSeparateParameters[0];
// [city]
ThisServerListEntry.strCity = slSeparateParameters[1];
// [country as QLocale ID]
const int iCountry = slSeparateParameters[2].toInt();
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
{
ThisServerListEntry.eCountry = static_cast<QLocale::Country> (
iCountry );
}
}
}
// per definition, the first entry in the server list it the own server
ServerList.append ( ThisServerListEntry );
// Connections -------------------------------------------------------------

View File

@ -122,6 +122,7 @@ class CServerListManager : public QObject
public:
CServerListManager ( const QString& sNCentServAddr,
const QString& strServerInfo,
CProtocol* pNConLProt );
void SetEnabled ( const bool bState );