From a81f1075ec18fde4e98a488cfccaf59f96758442 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 13 Jun 2021 09:49:36 +0100 Subject: [PATCH] Re-order and refactor help for client/server validation --- src/main.cpp | 583 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 356 insertions(+), 227 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 68144f3ce4..cf39461ad7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,8 @@ int main ( int argc, char** argv ) QString strArgument; double rDbleArgument; QList CommandLineOptions; + QList ServerOnlyOptions; + QList ClientOnlyOptions; // initialize all flags and string which might be changed by command line // arguments @@ -105,144 +107,131 @@ int main ( int argc, char** argv ) } #endif + // When adding new options, follow the same order as --help output + // QT docu: argv()[0] is the program name, argv()[1] is the first // argument and argv()[argc()-1] is the last argument. // Start with first argument, therefore "i = 1" for ( int i = 1; i < argc; i++ ) { - // Server mode flag ---------------------------------------------------- - if ( GetFlagArgument ( argv, i, "-s", "--server" ) ) + + // Help (usage) flag --------------------------------------------------- + if ( ( !strcmp ( argv[i], "--help" ) ) || ( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) ) { - bIsClient = false; - qInfo() << "- server mode chosen"; - CommandLineOptions << "--server"; - continue; + const QString strHelp = UsageArguments ( argv ); + qInfo() << qUtf8Printable ( strHelp ); + exit ( 0 ); } - // Use GUI flag -------------------------------------------------------- - if ( GetFlagArgument ( argv, i, "-n", "--nogui" ) ) + // Version number ------------------------------------------------------ + if ( ( !strcmp ( argv[i], "--version" ) ) || ( !strcmp ( argv[i], "-v" ) ) ) { - bUseGUI = false; - qInfo() << "- no GUI mode chosen"; - CommandLineOptions << "--nogui"; - continue; + qCritical() << qUtf8Printable ( GetVersionAndNameStr ( false ) ); + exit ( 1 ); } - // Use licence flag ---------------------------------------------------- - if ( GetFlagArgument ( argv, i, "-L", "--licence" ) ) + // Common options: + + // Initialization file ------------------------------------------------- + if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) { - // right now only the creative commons licence is supported - eLicenceType = LT_CREATIVECOMMONS; - qInfo() << "- licence required"; - CommandLineOptions << "--licence"; + strIniFileName = strArgument; + qInfo() << qUtf8Printable ( QString ( "- initialization file name: %1" ).arg ( strIniFileName ) ); + CommandLineOptions << "--inifile"; continue; } - // Use 64 samples frame size mode -------------------------------------- - if ( GetFlagArgument ( argv, i, "-F", "--fastupdate" ) ) + // Disable GUI flag ---------------------------------------------------- + if ( GetFlagArgument ( argv, i, "-n", "--nogui" ) ) { - bUseDoubleSystemFrameSize = false; // 64 samples frame size - qInfo() << qUtf8Printable ( QString ( "- using %1 samples frame size mode" ).arg ( SYSTEM_FRAME_SIZE_SAMPLES ) ); - CommandLineOptions << "--fastupdate"; + bUseGUI = false; + qInfo() << "- no GUI mode chosen"; + CommandLineOptions << "--nogui"; continue; } - // Use multithreading -------------------------------------------------- - if ( GetFlagArgument ( argv, i, "-T", "--multithreading" ) ) + // Port number --------------------------------------------------------- + if ( GetNumericArgument ( argc, argv, i, "-p", "--port", 0, 65535, rDbleArgument ) ) { - bUseMultithreading = true; - qInfo() << "- using multithreading"; - CommandLineOptions << "--multithreading"; + iPortNumber = static_cast ( rDbleArgument ); + bCustomPortNumberGiven = true; + qInfo() << qUtf8Printable ( QString ( "- selected port number: %1" ).arg ( iPortNumber ) ); + CommandLineOptions << "--port"; continue; } - // Maximum number of channels ------------------------------------------ - if ( GetNumericArgument ( argc, argv, i, "-u", "--numchannels", 1, MAX_NUM_CHANNELS, rDbleArgument ) ) + // Quality of Service -------------------------------------------------- + if ( GetNumericArgument ( argc, argv, i, "-Q", "--qos", 0, 255, rDbleArgument ) ) { - iNumServerChannels = static_cast ( rDbleArgument ); - - qInfo() << qUtf8Printable ( QString ( "- maximum number of channels: %1" ).arg ( iNumServerChannels ) ); - - CommandLineOptions << "--numchannels"; + iQosNumber = static_cast ( rDbleArgument ); + qInfo() << qUtf8Printable ( QString ( "- selected QoS value: %1" ).arg ( iQosNumber ) ); + CommandLineOptions << "--qos"; continue; } - // Start minimized ----------------------------------------------------- - if ( GetFlagArgument ( argv, i, "-z", "--startminimized" ) ) + // Disable translations ------------------------------------------------ + if ( GetFlagArgument ( argv, i, "-t", "--notranslation" ) ) { - bStartMinimized = true; - qInfo() << "- start minimized enabled"; - CommandLineOptions << "--startminimized"; + bUseTranslation = false; + qInfo() << "- translations disabled"; + CommandLineOptions << "--notranslation"; continue; } + // Server only: + // Disconnect all clients on quit -------------------------------------- if ( GetFlagArgument ( argv, i, "-d", "--discononquit" ) ) { bDisconnectAllClientsOnQuit = true; qInfo() << "- disconnect all clients on quit"; CommandLineOptions << "--discononquit"; + ServerOnlyOptions << "--discononquit"; continue; } - // Disabling auto Jack connections ------------------------------------- - if ( GetFlagArgument ( argv, i, "-j", "--nojackconnect" ) ) - { - bNoAutoJackConnect = true; - qInfo() << "- disable auto Jack connections"; - CommandLineOptions << "--nojackconnect"; - continue; - } - - // Disable translations ------------------------------------------------ - if ( GetFlagArgument ( argv, i, "-t", "--notranslation" ) ) + // Directory server ---------------------------------------------------- + if ( GetStringArgument ( argc, argv, i, "-e", "--directoryserver", strArgument ) ) { - bUseTranslation = false; - qInfo() << "- translations disabled"; - CommandLineOptions << "--notranslation"; + strCentralServer = strArgument; + qInfo() << qUtf8Printable ( QString ( "- directory server: %1" ).arg ( strCentralServer ) ); + CommandLineOptions << "--directoryserver"; + ServerOnlyOptions << "--directoryserver"; 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 - // possible or not. - if ( GetFlagArgument ( argv, - i, - "--showallservers", // no short form - "--showallservers" ) ) + // Central server ** D E P R E C A T E D ** ---------------------------- + if ( GetStringArgument ( argc, + argv, + i, + "--centralserver", // no short form + "--centralserver", + strArgument ) ) { - bShowComplRegConnList = true; - qInfo() << "- show all registered servers in server list"; - CommandLineOptions << "--showallservers"; + strCentralServer = strArgument; + qInfo() << qUtf8Printable ( QString ( "- directory server: %1" ).arg ( strCentralServer ) ); + CommandLineOptions << "--directoryserver"; + ServerOnlyOptions << "--directoryserver"; continue; } - // Show analyzer console ----------------------------------------------- - // Undocumented debugging command line argument: Show the analyzer - // console to debug network buffer properties. - if ( GetFlagArgument ( argv, - i, - "--showanalyzerconsole", // no short form - "--showanalyzerconsole" ) ) + // Server list filter -------------------------------------------------- + if ( GetStringArgument ( argc, argv, i, "-f", "--listfilter", strArgument ) ) { - bShowAnalyzerConsole = true; - qInfo() << "- show analyzer console"; - CommandLineOptions << "--showanalyzerconsole"; + strServerListFilter = strArgument; + qInfo() << qUtf8Printable ( QString ( "- server list filter: %1" ).arg ( strServerListFilter ) ); + CommandLineOptions << "--listfilter"; + ServerOnlyOptions << "--listfilter"; continue; } - // Controller MIDI channel --------------------------------------------- - if ( GetStringArgument ( argc, - argv, - i, - "--ctrlmidich", // no short form - "--ctrlmidich", - strArgument ) ) + // Use 64 samples frame size mode -------------------------------------- + if ( GetFlagArgument ( argv, i, "-F", "--fastupdate" ) ) { - strMIDISetup = strArgument; - qInfo() << qUtf8Printable ( QString ( "- MIDI controller settings: %1" ).arg ( strMIDISetup ) ); - CommandLineOptions << "--ctrlmidich"; + bUseDoubleSystemFrameSize = false; // 64 samples frame size + qInfo() << qUtf8Printable ( QString ( "- using %1 samples frame size mode" ).arg ( SYSTEM_FRAME_SIZE_SAMPLES ) ); + CommandLineOptions << "--fastupdate"; + ServerOnlyOptions << "--fastupdate"; continue; } @@ -252,25 +241,18 @@ int main ( int argc, char** argv ) strLoggingFileName = strArgument; qInfo() << qUtf8Printable ( QString ( "- logging file name: %1" ).arg ( strLoggingFileName ) ); CommandLineOptions << "--log"; + ServerOnlyOptions << "--log"; continue; } - // Port number --------------------------------------------------------- - if ( GetNumericArgument ( argc, argv, i, "-p", "--port", 0, 65535, rDbleArgument ) ) - { - iPortNumber = static_cast ( rDbleArgument ); - bCustomPortNumberGiven = true; - qInfo() << qUtf8Printable ( QString ( "- selected port number: %1" ).arg ( iPortNumber ) ); - CommandLineOptions << "--port"; - continue; - } - - // Quality of Service -------------------------------------------------- - if ( GetNumericArgument ( argc, argv, i, "-Q", "--qos", 0, 255, rDbleArgument ) ) + // Use licence flag ---------------------------------------------------- + if ( GetFlagArgument ( argv, i, "-L", "--licence" ) ) { - iQosNumber = static_cast ( rDbleArgument ); - qInfo() << qUtf8Printable ( QString ( "- selected QoS value: %1" ).arg ( iQosNumber ) ); - CommandLineOptions << "--qos"; + // LT_CREATIVECOMMONS is now used just to enable the pop up + eLicenceType = LT_CREATIVECOMMONS; + qInfo() << "- licence required"; + CommandLineOptions << "--licence"; + ServerOnlyOptions << "--licence"; continue; } @@ -280,20 +262,42 @@ int main ( int argc, char** argv ) strHTMLStatusFileName = strArgument; qInfo() << qUtf8Printable ( QString ( "- HTML status file name: %1" ).arg ( strHTMLStatusFileName ) ); CommandLineOptions << "--htmlstatus"; + ServerOnlyOptions << "--htmlstatus"; continue; } - // Client Name --------------------------------------------------------- + // Server info --------------------------------------------------------- + if ( GetStringArgument ( argc, argv, i, "-o", "--serverinfo", strArgument ) ) + { + strServerInfo = strArgument; + qInfo() << qUtf8Printable ( QString ( "- server info: %1" ).arg ( strServerInfo ) ); + CommandLineOptions << "--serverinfo"; + ServerOnlyOptions << "--serverinfo"; + continue; + } + + // Server Public IP ---------------------------------------------------- if ( GetStringArgument ( argc, argv, i, - "--clientname", // no short form - "--clientname", + "--serverpublicip", // no short form + "--serverpublicip", strArgument ) ) { - strClientName = strArgument; - qInfo() << qUtf8Printable ( QString ( "- client name: %1" ).arg ( strClientName ) ); - CommandLineOptions << "--clientname"; + strServerPublicIP = strArgument; + qInfo() << qUtf8Printable ( QString ( "- server public IP: %1" ).arg ( strServerPublicIP ) ); + CommandLineOptions << "--serverpublicip"; + ServerOnlyOptions << "--serverpublicip"; + continue; + } + + // Enable delay panning on startup ------------------------------------- + if ( GetFlagArgument ( argv, i, "-P", "--delaypan" ) ) + { + bDelayPan = true; + qInfo() << "- starting with delay panning"; + CommandLineOptions << "--delaypan"; + ServerOnlyOptions << "--delaypan"; continue; } @@ -303,6 +307,7 @@ int main ( int argc, char** argv ) strRecordingDirName = strArgument; qInfo() << qUtf8Printable ( QString ( "- recording directory name: %1" ).arg ( strRecordingDirName ) ); CommandLineOptions << "--recording"; + ServerOnlyOptions << "--recording"; continue; } @@ -315,52 +320,17 @@ int main ( int argc, char** argv ) bDisableRecording = true; qInfo() << "- recording will not take place until enabled"; CommandLineOptions << "--norecord"; + ServerOnlyOptions << "--norecord"; continue; } - // Enable delay panning on startup ------------------------------------- - if ( GetFlagArgument ( argv, i, "-P", "--delaypan" ) ) - { - bDelayPan = true; - qInfo() << "- starting with delay panning"; - CommandLineOptions << "--delaypan"; - continue; - } - - // Directory server ---------------------------------------------------- - if ( GetStringArgument ( argc, argv, i, "-e", "--directoryserver", strArgument ) ) - { - strCentralServer = strArgument; - qInfo() << qUtf8Printable ( QString ( "- directory server: %1" ).arg ( strCentralServer ) ); - CommandLineOptions << "--directoryserver"; - continue; - } - - // Central server ** D E P R E C A T E D ** ---------------------------- - if ( GetStringArgument ( argc, - argv, - i, - "--centralserver", // no short form - "--centralserver", - strArgument ) ) - { - strCentralServer = strArgument; - qInfo() << qUtf8Printable ( QString ( "- directory server: %1" ).arg ( strCentralServer ) ); - CommandLineOptions << "--directoryserver"; - continue; - } - - // Server Public IP ---------------------------------------------------- - if ( GetStringArgument ( argc, - argv, - i, - "--serverpublicip", // no short form - "--serverpublicip", - strArgument ) ) + // Server mode flag ---------------------------------------------------- + if ( GetFlagArgument ( argv, i, "-s", "--server" ) ) { - strServerPublicIP = strArgument; - qInfo() << qUtf8Printable ( QString ( "- server public IP: %1" ).arg ( strServerPublicIP ) ); - CommandLineOptions << "--serverpublicip"; + bIsClient = false; + qInfo() << "- server mode chosen"; + CommandLineOptions << "--server"; + ServerOnlyOptions << "--server"; continue; } @@ -375,24 +345,29 @@ int main ( int argc, char** argv ) strServerBindIP = strArgument; qInfo() << qUtf8Printable ( QString ( "- server bind IP: %1" ).arg ( strServerBindIP ) ); CommandLineOptions << "--serverbindip"; + ServerOnlyOptions << "--serverbindip"; continue; } - // Server info --------------------------------------------------------- - if ( GetStringArgument ( argc, argv, i, "-o", "--serverinfo", strArgument ) ) + // Use multithreading -------------------------------------------------- + if ( GetFlagArgument ( argv, i, "-T", "--multithreading" ) ) { - strServerInfo = strArgument; - qInfo() << qUtf8Printable ( QString ( "- server info: %1" ).arg ( strServerInfo ) ); - CommandLineOptions << "--serverinfo"; + bUseMultithreading = true; + qInfo() << "- using multithreading"; + CommandLineOptions << "--multithreading"; + ServerOnlyOptions << "--multithreading"; continue; } - // Server list filter -------------------------------------------------- - if ( GetStringArgument ( argc, argv, i, "-f", "--listfilter", strArgument ) ) + // Maximum number of channels ------------------------------------------ + if ( GetNumericArgument ( argc, argv, i, "-u", "--numchannels", 1, MAX_NUM_CHANNELS, rDbleArgument ) ) { - strServerListFilter = strArgument; - qInfo() << qUtf8Printable ( QString ( "- server list filter: %1" ).arg ( strServerListFilter ) ); - CommandLineOptions << "--listfilter"; + iNumServerChannels = static_cast ( rDbleArgument ); + + qInfo() << qUtf8Printable ( QString ( "- maximum number of channels: %1" ).arg ( iNumServerChannels ) ); + + CommandLineOptions << "--numchannels"; + ServerOnlyOptions << "--numchannels"; continue; } @@ -402,24 +377,39 @@ int main ( int argc, char** argv ) strWelcomeMessage = strArgument; qInfo() << qUtf8Printable ( QString ( "- welcome message: %1" ).arg ( strWelcomeMessage ) ); CommandLineOptions << "--welcomemessage"; + ServerOnlyOptions << "--welcomemessage"; continue; } - // Initialization file ------------------------------------------------- - if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) + // Start minimized ----------------------------------------------------- + if ( GetFlagArgument ( argv, i, "-z", "--startminimized" ) ) { - strIniFileName = strArgument; - qInfo() << qUtf8Printable ( QString ( "- initialization file name: %1" ).arg ( strIniFileName ) ); - CommandLineOptions << "--inifile"; + bStartMinimized = true; + qInfo() << "- start minimized enabled"; + CommandLineOptions << "--startminimized"; + ServerOnlyOptions << "--startminimized"; continue; } + // Client only: + // Connect on startup -------------------------------------------------- if ( GetStringArgument ( argc, argv, i, "-c", "--connect", strArgument ) ) { strConnOnStartupAddress = NetworkUtil::FixAddress ( strArgument ); qInfo() << qUtf8Printable ( QString ( "- connect on startup to address: %1" ).arg ( strConnOnStartupAddress ) ); CommandLineOptions << "--connect"; + ClientOnlyOptions << "--connect"; + continue; + } + + // Disabling auto Jack connections ------------------------------------- + if ( GetFlagArgument ( argv, i, "-j", "--nojackconnect" ) ) + { + bNoAutoJackConnect = true; + qInfo() << "- disable auto Jack connections"; + CommandLineOptions << "--nojackconnect"; + ClientOnlyOptions << "--nojackconnect"; continue; } @@ -429,6 +419,7 @@ int main ( int argc, char** argv ) bMuteStream = true; qInfo() << "- mute stream activated"; CommandLineOptions << "--mutestream"; + ClientOnlyOptions << "--mutestream"; continue; } @@ -441,22 +432,71 @@ int main ( int argc, char** argv ) bMuteMeInPersonalMix = true; qInfo() << "- mute me in my personal mix"; CommandLineOptions << "--mutemyown"; + ClientOnlyOptions << "--mutemyown"; continue; } - // Version number ------------------------------------------------------ - if ( ( !strcmp ( argv[i], "--version" ) ) || ( !strcmp ( argv[i], "-v" ) ) ) + // Client Name --------------------------------------------------------- + if ( GetStringArgument ( argc, + argv, + i, + "--clientname", // no short form + "--clientname", + strArgument ) ) { - qCritical() << qUtf8Printable ( GetVersionAndNameStr ( false ) ); - exit ( 1 ); + strClientName = strArgument; + qInfo() << qUtf8Printable ( QString ( "- client name: %1" ).arg ( strClientName ) ); + CommandLineOptions << "--clientname"; + ClientOnlyOptions << "--clientname"; + continue; } - // Help (usage) flag --------------------------------------------------- - if ( ( !strcmp ( argv[i], "--help" ) ) || ( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) ) + // Controller MIDI channel --------------------------------------------- + if ( GetStringArgument ( argc, + argv, + i, + "--ctrlmidich", // no short form + "--ctrlmidich", + strArgument ) ) { - const QString strHelp = UsageArguments ( argv ); - qInfo() << qUtf8Printable ( strHelp ); - exit ( 0 ); + strMIDISetup = strArgument; + qInfo() << qUtf8Printable ( QString ( "- MIDI controller settings: %1" ).arg ( strMIDISetup ) ); + CommandLineOptions << "--ctrlmidich"; + ClientOnlyOptions << "--ctrlmidich"; + continue; + } + + // Undocumented: + + // 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 + // possible or not. + if ( GetFlagArgument ( argv, + i, + "--showallservers", // no short form + "--showallservers" ) ) + { + bShowComplRegConnList = true; + qInfo() << "- show all registered servers in server list"; + CommandLineOptions << "--showallservers"; + ClientOnlyOptions << "--showallservers"; + continue; + } + + // Show analyzer console ----------------------------------------------- + // Undocumented debugging command line argument: Show the analyzer + // console to debug network buffer properties. + if ( GetFlagArgument ( argv, + i, + "--showanalyzerconsole", // no short form + "--showanalyzerconsole" ) ) + { + bShowAnalyzerConsole = true; + qInfo() << "- show analyzer console"; + CommandLineOptions << "--showanalyzerconsole"; + ClientOnlyOptions << "--showanalyzerconsole"; + continue; } // Unknown option ------------------------------------------------------ @@ -490,53 +530,139 @@ int main ( int argc, char** argv ) } #endif - // the inifile is not supported for the headless server mode - if ( !bIsClient && !bUseGUI && !strIniFileName.isEmpty() ) + if ( bIsClient ) { - qWarning() << "No initialization file support in headless server mode."; - } + if ( ServerOnlyOptions.size() != 0 ) + { + qCritical() << qUtf8Printable ( QString ( "%1: Server only option(s) '%2' used. Did you omit '--server'?" ) + .arg ( argv[0] ) + .arg ( ServerOnlyOptions.join ( ", " ) ) ); + exit ( 1 ); + } - // mute my own signal in personal mix is only supported for headless mode - if ( bIsClient && bUseGUI && bMuteMeInPersonalMix ) - { - bMuteMeInPersonalMix = false; - qWarning() << "Mute my own signal in my personal mix is only supported in headless mode."; - } + // mute my own signal in personal mix is only supported for headless mode + if ( bUseGUI && bMuteMeInPersonalMix ) + { + bMuteMeInPersonalMix = false; + qWarning() << "Mute my own signal in my personal mix is only supported in headless mode."; + } - if ( !strServerPublicIP.isEmpty() ) + // adjust default port number for client: use different default port than the server since + // if the client is started before the server, the server would get a socket bind error + if ( !bCustomPortNumberGiven ) + { + iPortNumber += 10; // increment by 10 + qInfo() << qUtf8Printable ( QString ( "- allocated port number: %1" ).arg ( iPortNumber ) ); + } + } + else { - QHostAddress InetAddr; - if ( !InetAddr.setAddress ( strServerPublicIP ) ) + if ( ClientOnlyOptions.size() != 0 ) { - qWarning() << "Server Public IP is invalid. Only plain IP addresses are supported."; + qCritical() << qUtf8Printable ( + QString ( "%1: Client only option(s) '%2' used. See '--help' for help" ).arg ( argv[0] ).arg ( ClientOnlyOptions.join ( ", " ) ) ); + exit ( 1 ); } - if ( strCentralServer.isEmpty() || bIsClient ) + + if ( bUseGUI ) { - qWarning() << "Server Public IP will only take effect when registering a server with a directory server."; + if ( strCentralServer.isEmpty() ) + { + // per definition: if we are in "GUI" server mode and no directory server + // address is given, we use the default directory server address + strCentralServer = DEFAULT_SERVER_ADDRESS; + qInfo() << qUtf8Printable ( QString ( "- default directory server set: %1" ).arg ( strCentralServer ) ); + } + } + else + { + // the inifile is not supported for the headless server mode + if ( !strIniFileName.isEmpty() ) + { + qWarning() << "No initialization file support in headless server mode."; + } } - } - if ( !strServerBindIP.isEmpty() ) - { - QHostAddress InetAddr; - if ( !InetAddr.setAddress ( strServerBindIP ) ) + if ( strCentralServer.isEmpty() ) { - qWarning() << "Server Bind IP is invalid. Only plain IP addresses are supported."; + // per definition, we must be a headless server and ignoring inifile, so we have all the information + + if ( !strServerListFilter.isEmpty() ) + { + qWarning() << "Server list filter will only take effect when running as a directory server."; + strServerListFilter = ""; + } + + if ( !strServerPublicIP.isEmpty() ) + { + qWarning() << "Server Public IP will only take effect when registering a server with a directory server."; + strServerPublicIP = ""; + } } - } + else + { + // either we are not headless and there is an inifile, or a directory server was supplied on the command line - // per definition: if we are in "GUI" server mode and no directory server - // address is given, we use the default directory server address - if ( !bIsClient && bUseGUI && strCentralServer.isEmpty() ) - { - strCentralServer = DEFAULT_SERVER_ADDRESS; - } + // if we are not headless, certain checks cannot be made, as the inifile state is not yet known + if ( !bUseGUI && strCentralServer.compare ( "localhost", Qt::CaseInsensitive ) != 0 && strCentralServer.compare ( "127.0.0.1" ) != 0 ) + { + if ( !strServerListFilter.isEmpty() ) + { + qWarning() << "Server list filter will only take effect when running as a directory server."; + strServerListFilter = ""; + } + } + else + { + if ( !strServerListFilter.isEmpty() ) + { + QStringList slWhitelistAddresses = strServerListFilter.split ( ";" ); + for ( int iIdx = 0; iIdx < slWhitelistAddresses.size(); iIdx++ ) + { + // check for special case: [version] + if ( ( slWhitelistAddresses.at ( iIdx ).length() > 2 ) && ( slWhitelistAddresses.at ( iIdx ).left ( 1 ) == "[" ) && + ( slWhitelistAddresses.at ( iIdx ).right ( 1 ) == "]" ) ) + { + // Good case - it seems QVersionNumber isn't fussy + } + else if ( slWhitelistAddresses.at ( iIdx ).isEmpty() ) + { + qWarning() << "There is empty entry in the server list filter that will be ignored"; + } + else + { + QHostAddress InetAddr; + if ( !InetAddr.setAddress ( slWhitelistAddresses.at ( iIdx ) ) ) + { + qWarning() << qUtf8Printable ( + QString ( "%1 is not a valid server list filter entry. Only plain IP addresses are supported" ) + .arg ( slWhitelistAddresses.at ( iIdx ) ) ); + } + } + } + } + } - // adjust default port number for client: use different default port than the server since - // if the client is started before the server, the server would get a socket bind error - if ( bIsClient && !bCustomPortNumberGiven ) - { - iPortNumber += 10; // increment by 10 + if ( !strServerPublicIP.isEmpty() ) + { + QHostAddress InetAddr; + if ( !InetAddr.setAddress ( strServerPublicIP ) ) + { + qWarning() << "Server Public IP is invalid. Only plain IP addresses are supported."; + strServerPublicIP = ""; + } + } + } + + if ( !strServerBindIP.isEmpty() ) + { + QHostAddress InetAddr; + if ( !InetAddr.setAddress ( strServerBindIP ) ) + { + qWarning() << "Server Bind IP is invalid. Only plain IP addresses are supported."; + strServerBindIP = ""; + } + } } // Application/GUI setup --------------------------------------------------- @@ -739,59 +865,62 @@ int main ( int argc, char** argv ) QString UsageArguments ( char** argv ) { // clang-format off - return "\n" - "Usage: " + QString ( argv[0] ) + " [option] [optional argument]\n" + return QString ( + "\n" + "Usage: %1 [option] [option argument] ...\n" "\n" - "General options:\n" " -h, -?, --help display this help text and exit\n" + " -v, --version display version information and exit\n" + "\n" + "Common options:\n" " -i, --inifile initialization file name\n" " (not supported for headless server mode)\n" - " -n, --nogui disable GUI\n" + " -n, --nogui disable GUI (\"headless\")\n" " -p, --port set the local port number\n" " -Q, --qos set the QoS value. Default is 128. Disable with 0\n" " (see the Jamulus website to enable QoS on Windows)\n" " -t, --notranslation disable translation (use English language)\n" - " -v, --version output version information and exit\n" "\n" "Server only:\n" " -d, --discononquit disconnect all clients on quit\n" " -e, --directoryserver address of the directory server with which to register\n" " (or 'localhost' to host a server list on this server)\n" - " -f, --listfilter server list whitelist filter in the format:\n" + " -f, --listfilter server list whitelist filter. Format:\n" " [IP address 1];[IP address 2];[IP address 3]; ...\n" " -F, --fastupdate use 64 samples frame size mode\n" " -l, --log enable logging, set file name\n" " -L, --licence show an agreement window before users can connect\n" " -m, --htmlstatus enable HTML status file, set file name\n" - " -o, --serverinfo infos of this server in the format:\n" + " -o, --serverinfo registration info for this server. Format:\n" " [name];[city];[country as QLocale ID]\n" + " --serverpublicip public IP address for this server. Needed when\n" + " registering with a server list hosted\n" + " behind the same NAT\n" " -P, --delaypan start with delay panning enabled\n" " -R, --recording sets directory to contain recorded jams\n" " --norecord disables recording (when enabled by default by -R)\n" " -s, --server start server\n" + " --serverbindip IP address the server will bind to (rather than all)\n" " -T, --multithreading use multithreading to make better use of\n" " multi-core CPUs and support more clients\n" " -u, --numchannels maximum number of channels\n" - " -w, --welcomemessage welcome message on connect\n" + " -w, --welcomemessage welcome message to display on connect\n" + " (string or filename)\n" " -z, --startminimized start minimizied\n" - " --serverpublicip specify your public IP address when\n" - " running a slave and your own directory server\n" - " behind the same NAT\n" - " --serverbindip specify the IP address the server will bind to\n" "\n" "Client only:\n" + " -c, --connect connect to given server address on startup\n" + " -j, --nojackconnect disable auto Jack connections\n" " -M, --mutestream starts the application in muted state\n" " --mutemyown mute me in my personal mix (headless only)\n" - " -c, --connect connect to given server address on startup\n" - " -j, --nojackconnect disable auto JACK connections\n" + " --clientname client name (window title and jack client name)\n" " --ctrlmidich MIDI controller channel to listen\n" - " --clientname client name (window title and JACK client name)\n" "\n" - "Example: " + QString ( argv[0] ) + " -s --inifile myinifile.ini\n" + "Example: %1 -s --inifile myinifile.ini\n" "\n" "For more information and localized help see:\n" - "\n" - "https://jamulus.io/wiki/Command-Line-Options\n"; + "https://jamulus.io/wiki/Command-Line-Options\n" + ).arg( argv[0] ); // clang-format on } @@ -813,7 +942,7 @@ bool GetStringArgument ( int argc, char** argv, int& i, QString strShortOpt, QSt { if ( ++i >= argc ) { - qCritical() << qUtf8Printable ( QString ( "%1: '%2' needs a string argument." ).arg ( argv[0] ).arg ( strLongOpt ) ); + qCritical() << qUtf8Printable ( QString ( "%1: '%2' needs a string argument." ).arg ( argv[0] ).arg ( argv[i - 1] ) ); exit ( 1 ); } @@ -841,7 +970,7 @@ bool GetNumericArgument ( int argc, QString errmsg = "%1: '%2' needs a numeric argument between '%3' and '%4'."; if ( ++i >= argc ) { - qCritical() << qUtf8Printable ( errmsg.arg ( argv[0] ).arg ( strLongOpt ).arg ( rRangeStart ).arg ( rRangeStop ) ); + qCritical() << qUtf8Printable ( errmsg.arg ( argv[0] ).arg ( argv[i - 1] ).arg ( rRangeStart ).arg ( rRangeStop ) ); exit ( 1 ); } @@ -849,7 +978,7 @@ bool GetNumericArgument ( int argc, rValue = strtod ( argv[i], &p ); if ( *p || ( rValue < rRangeStart ) || ( rValue > rRangeStop ) ) { - qCritical() << qUtf8Printable ( errmsg.arg ( argv[0] ).arg ( strLongOpt ).arg ( rRangeStart ).arg ( rRangeStop ) ); + qCritical() << qUtf8Printable ( errmsg.arg ( argv[0] ).arg ( argv[i - 1] ).arg ( rRangeStart ).arg ( rRangeStop ) ); exit ( 1 ); }