From 1401b2f956b0612a96400576877f403b87c9a659 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 28 Jan 2017 00:41:04 +0100 Subject: [PATCH] Add new command line argument 'serverType' ServerType allows to override the ServerType at runtime refs #872 --- src/blackcore/vatsim/networkvatlib.cpp | 29 +++++++++++++++++++++++--- src/blackcore/vatsim/networkvatlib.h | 3 ++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/blackcore/vatsim/networkvatlib.cpp b/src/blackcore/vatsim/networkvatlib.cpp index d0a3ae301..c0f383b4b 100644 --- a/src/blackcore/vatsim/networkvatlib.cpp +++ b/src/blackcore/vatsim/networkvatlib.cpp @@ -117,7 +117,10 @@ namespace BlackCore clientKey = CBuildConfig::vatsimPrivateKey(); } - VatServerType serverType = CBuildConfig::isVatsimVersion() ? vatServerVatsim : vatServerLegacyFsd; + VatServerType serverType; + bool success = getCmdLineServerType(serverType); + if(!success) { serverType = CBuildConfig::isVatsimVersion() ? vatServerVatsim : vatServerLegacyFsd; } + m_net.reset(Vat_CreateNetworkSession(serverType, sApp->swiftVersionChar(), CVersion::versionMajor(), CVersion::versionMinor(), "None", clientId, clientKey.toLocal8Bit().constData(), @@ -683,8 +686,11 @@ namespace BlackCore static const QList opts { QCommandLineOption({ "idAndKey", "clientIdAndKey" }, - QCoreApplication::translate("application", "Client id and key pair separated by ':', e.g. :."), - "clientIdAndKey") + QCoreApplication::translate("networkvatlib", "Client id and key pair separated by ':', e.g. :."), + "clientIdAndKey"), + QCommandLineOption({ "s", "serverType" }, + QCoreApplication::translate("networkvatlib", "FSD server type. Possible values: vatsim, fsd"), + "serverType") }; // only in not officially shipped versions @@ -704,6 +710,23 @@ namespace BlackCore return true; } + bool CNetworkVatlib::getCmdLineServerType(VatServerType &serverType) const + { + QString serverTypeAsString = sApp->getParserValue("serverType").toLower(); + if(QString::compare(serverTypeAsString, "vatsim", Qt::CaseInsensitive) == 0) + { + serverType = vatServerVatsim; + return true; + } + + if(QString::compare(serverTypeAsString, "fsd", Qt::CaseInsensitive) == 0) + { + serverType = vatServerLegacyFsd; + return true; + } + return false; + } + void CNetworkVatlib::sendCustomFsinnQuery(const BlackMisc::Aviation::CCallsign &callsign) { Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected"); diff --git a/src/blackcore/vatsim/networkvatlib.h b/src/blackcore/vatsim/networkvatlib.h index 1ba64bf2b..ef9e53214 100644 --- a/src/blackcore/vatsim/networkvatlib.h +++ b/src/blackcore/vatsim/networkvatlib.h @@ -121,8 +121,9 @@ namespace BlackCore //! Cmd. line options this library can handle static const QList &getCmdLineOptions(); - //! Client id and key if any from command line arguments + private: bool getCmdLineClientIdAndKey(int &id, QString &key) const; + bool getCmdLineServerType(VatServerType &serverType) const; private slots: void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign);