From b2ae4e56816d4a44b56d99f77055dcd8e95ac25c Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Mon, 10 Jun 2024 20:37:56 +0200 Subject: [PATCH] build: Add ifdef to disable VATSIM build --- CMakeLists.txt | 3 +++ samples/fsd/main.cpp | 2 ++ src/blackconfig/buildconfig.h | 2 ++ src/blackconfig/buildconfig_gen.cpp.in | 2 ++ src/blackcore/CMakeLists.txt | 5 ++++- src/blackcore/context/contextnetwork.cpp | 4 ++++ src/blackcore/context/contextnetwork.h | 2 ++ src/blackcore/context/contextnetworkimpl.cpp | 2 ++ src/blackcore/fsd/fsdclient.cpp | 16 ++++++++++++++++ src/blackcore/fsd/fsdclient.h | 16 +++++++++++++++- src/swiftlauncher/swiftlauncher.cpp | 2 ++ .../fsd/testfsdclient/testfsdclient.cpp | 2 ++ 12 files changed, 56 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dc9d028e..9f6040e1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,9 @@ option(SWIFT_USE_CRASHPAD "Use crashpad" OFF) option(SWIFT_VATSIM_SUPPORT "Build with VATSIM support" ON) set(VATSIM_KEY_JSON "" CACHE STRING "Path to JSON containing VATSIM key") load_vatsim_key() +if(SWIFT_VATSIM_SUPPORT) + add_compile_definitions(SWIFT_VATSIM_SUPPORT) +endif() if(NOT CMAKE_BUILD_TYPE) message(STATUS "CMAKE_BUILD_TYPE not defined. Falling back to Debug") diff --git a/samples/fsd/main.cpp b/samples/fsd/main.cpp index ac0f72b07..c2c09c903 100644 --- a/samples/fsd/main.cpp +++ b/samples/fsd/main.cpp @@ -25,8 +25,10 @@ int main(int argc, char *argv[]) client.setClientName("Test Client"); client.setHostApplication("None"); client.setVersion(0, 8); +#ifdef SWIFT_VATSIM_SUPPORT QString key("727d1efd5cb9f8d2c28372469d922bb4"); client.setClientIdAndKey(0xb9ba, key.toLocal8Bit()); +#endif client.setClientCapabilities(Capabilities::AtcInfo | Capabilities::AircraftInfo | Capabilities::AircraftConfig); const CUser user("1234567", "Test user - EDDM", "", "123456"); diff --git a/src/blackconfig/buildconfig.h b/src/blackconfig/buildconfig.h index cc06c09ec..2de9d3f01 100644 --- a/src/blackconfig/buildconfig.h +++ b/src/blackconfig/buildconfig.h @@ -98,11 +98,13 @@ namespace BlackConfig //! Known executable static bool isKnownExecutableName(const QString &executable); +#ifdef SWIFT_VATSIM_SUPPORT //! Vatsim client id static int vatsimClientId(); // defined in buildconfig_gen.cpp.in //! Vatsim client key static const QString &vatsimPrivateKey(); // defined in buildconfig_gen.cpp.in +#endif //! Backtrace token for minidump uploads static const QString &backtraceToken(); // defined in buildconfig_gen.cpp.in diff --git a/src/blackconfig/buildconfig_gen.cpp.in b/src/blackconfig/buildconfig_gen.cpp.in index 84548b9ae..c8915f0d0 100644 --- a/src/blackconfig/buildconfig_gen.cpp.in +++ b/src/blackconfig/buildconfig_gen.cpp.in @@ -5,6 +5,7 @@ #include #include +#ifdef SWIFT_VATSIM_SUPPORT int BlackConfig::CBuildConfig::vatsimClientId() { static const int id { ${SWIFT_VATSIM_ID} }; @@ -16,6 +17,7 @@ const QString &BlackConfig::CBuildConfig::vatsimPrivateKey() static const auto pk = QString { "${SWIFT_VATSIM_KEY}" }; return pk; } +#endif const QString &BlackConfig::CBuildConfig::backtraceToken() { diff --git a/src/blackcore/CMakeLists.txt b/src/blackcore/CMakeLists.txt index ee871b83a..25e922f19 100644 --- a/src/blackcore/CMakeLists.txt +++ b/src/blackcore/CMakeLists.txt @@ -262,13 +262,16 @@ target_link_libraries(core externals_sodium externals_msgpack blackconfig - externals_vatsim_auth PRIVATE Qt::Qml Qt::Xml QJsonWebToken ) +if(SWIFT_VATSIM_SUPPORT) + target_link_libraries(core PUBLIC externals_vatsim_auth) +endif() + target_compile_definitions(core PRIVATE BUILD_BLACKCORE_LIB) target_precompile_headers(core diff --git a/src/blackcore/context/contextnetwork.cpp b/src/blackcore/context/contextnetwork.cpp index 110af4cd8..b9c8c1d01 100644 --- a/src/blackcore/context/contextnetwork.cpp +++ b/src/blackcore/context/contextnetwork.cpp @@ -32,14 +32,17 @@ namespace BlackCore::Context { static const QList e; static const QList opts { +#ifdef SWIFT_VATSIM_SUPPORT QCommandLineOption({ "idAndKey", "clientIdAndKey" }, QCoreApplication::translate("CContextNetwork", "Client id and key pair separated by ':', e.g. :."), "clientIdAndKey") +#endif }; // only in not officially shipped versions return (CBuildConfig::isLocalDeveloperDebugBuild()) ? opts : e; } +#ifdef SWIFT_VATSIM_SUPPORT bool IContextNetwork::getCmdLineClientIdAndKey(int &id, QString &key) { // init values @@ -59,5 +62,6 @@ namespace BlackCore::Context key = stringList[1]; return true; } +#endif } // namesapce diff --git a/src/blackcore/context/contextnetwork.h b/src/blackcore/context/contextnetwork.h index c53c90cb2..195167f81 100644 --- a/src/blackcore/context/contextnetwork.h +++ b/src/blackcore/context/contextnetwork.h @@ -362,8 +362,10 @@ namespace BlackCore::Context //! Cmd.line arguments static const QList &getCmdLineOptions(); +#ifdef SWIFT_VATSIM_SUPPORT //! Client id and key from cmd.line static bool getCmdLineClientIdAndKey(int &id, QString &key); +#endif protected: //! Constructor diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp index aa1e0d0ed..12f402a84 100644 --- a/src/blackcore/context/contextnetworkimpl.cpp +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -273,6 +273,7 @@ namespace BlackCore::Context m_fsdClient->setClientName(sApp->swiftVersionChar()); m_fsdClient->setVersion(CBuildConfig::getVersion().majorVersion(), CBuildConfig::getVersion().minorVersion()); +#ifdef SWIFT_VATSIM_SUPPORT int clientId = 0; QString clientKey; if (!getCmdLineClientIdAndKey(clientId, clientKey)) @@ -282,6 +283,7 @@ namespace BlackCore::Context } m_fsdClient->setClientIdAndKey(static_cast(clientId), clientKey.toLocal8Bit()); +#endif m_fsdClient->setClientCapabilities(Capabilities::AircraftInfo | Capabilities::FastPos | Capabilities::VisPos | Capabilities::AtcInfo | Capabilities::AircraftConfig | Capabilities::IcaoEquipment); m_fsdClient->setServer(server); diff --git a/src/blackcore/fsd/fsdclient.cpp b/src/blackcore/fsd/fsdclient.cpp index e3fb780db..89c5f610c 100644 --- a/src/blackcore/fsd/fsdclient.cpp +++ b/src/blackcore/fsd/fsdclient.cpp @@ -138,12 +138,14 @@ namespace BlackCore::Fsd connect(m_socket.get(), &QTcpSocket::errorOccurred, this, &CFSDClient::handleSocketError, Qt::QueuedConnection); } +#ifdef SWIFT_VATSIM_SUPPORT void CFSDClient::setClientIdAndKey(quint16 id, const QByteArray &key) { QWriteLocker l(&m_lockUserClientBuffered); m_clientAuth = vatsim_auth_create(id, qPrintable(key)); m_serverAuth = vatsim_auth_create(id, qPrintable(key)); } +#endif void CFSDClient::setServer(const CServer &server) { @@ -970,7 +972,9 @@ namespace BlackCore::Fsd const int altitude = situation.getAltitude().valueInteger(CLengthUnit::ft()); std::array sysuid = {}; +#ifdef SWIFT_VATSIM_SUPPORT vatsim_get_system_unique_id(sysuid.data()); +#endif const QString userInfo = QStringLiteral("CID=") % cid % " " % m_clientName % " IP=" % m_socket->localAddress().toString() % " SYS_UID=" % sysuid.data() % " FSVER=" % m_hostApplication % " LT=" % QString::number(latitude) % @@ -990,6 +994,7 @@ namespace BlackCore::Fsd } } +#ifdef SWIFT_VATSIM_SUPPORT void CFSDClient::sendClientIdentification(const QString &fsdChallenge) { std::array sysuid = {}; @@ -1013,6 +1018,7 @@ namespace BlackCore::Fsd } increaseStatisticsValue(QStringLiteral("sendClientIdentification")); } +#endif void CFSDClient::getVatsimAuthToken(const QString &cid, const QString &password, const BlackMisc::CSlot &callback) { @@ -1129,6 +1135,7 @@ namespace BlackCore::Fsd m_atcStations.replaceOrAddObjectByCallsign({ cs, {}, freq, position, range }); } +#ifdef SWIFT_VATSIM_SUPPORT void CFSDClient::handleAuthChallenge(const QStringList &tokens) { const AuthChallenge authChallenge = AuthChallenge::fromTokens(tokens); @@ -1141,7 +1148,9 @@ namespace BlackCore::Fsd m_lastServerAuthChallenge = QString(challenge); sendAuthChallenge(m_lastServerAuthChallenge); } +#endif +#ifdef SWIFT_VATSIM_SUPPORT void CFSDClient::handleAuthResponse(const QStringList &tokens) { const AuthResponse authResponse = AuthResponse::fromTokens(tokens); @@ -1154,6 +1163,7 @@ namespace BlackCore::Fsd disconnectFromServer(); } } +#endif void CFSDClient::handleDeleteATC(const QStringList &tokens) { @@ -1798,6 +1808,7 @@ namespace BlackCore::Fsd } } +#ifdef SWIFT_VATSIM_SUPPORT void CFSDClient::handleFsdIdentification(const QStringList &tokens) { if (m_protocolRevision >= PROTOCOL_REVISION_VATSIM_AUTH) @@ -1816,6 +1827,7 @@ namespace BlackCore::Fsd disconnectFromServer(); } } +#endif void CFSDClient::handleUnknownPacket(const QString &line) { @@ -2294,14 +2306,18 @@ namespace BlackCore::Fsd // handled ones case MessageType::AtcDataUpdate: handleAtcDataUpdate(tokens); break; +#ifdef SWIFT_VATSIM_SUPPORT case MessageType::AuthChallenge: handleAuthChallenge(tokens); break; case MessageType::AuthResponse: handleAuthResponse(tokens); break; +#endif case MessageType::ClientQuery: handleClientQuery(tokens); break; case MessageType::ClientResponse: handleClientResponse(tokens); break; case MessageType::DeleteATC: handleDeleteATC(tokens); break; case MessageType::DeletePilot: handleDeletePilot(tokens); break; case MessageType::FlightPlan: handleFlightPlan(tokens); break; +#ifdef SWIFT_VATSIM_SUPPORT case MessageType::FsdIdentification: handleFsdIdentification(tokens); break; +#endif case MessageType::KillRequest: handleKillRequest(tokens); break; case MessageType::PilotDataUpdate: handlePilotDataUpdate(tokens); break; case MessageType::Ping: handlePing(tokens); break; diff --git a/src/blackcore/fsd/fsdclient.h b/src/blackcore/fsd/fsdclient.h index 728db119e..ee7592dff 100644 --- a/src/blackcore/fsd/fsdclient.h +++ b/src/blackcore/fsd/fsdclient.h @@ -30,7 +30,9 @@ #include "blackmisc/digestsignal.h" #include "blackmisc/tokenbucket.h" -#include "vatsim/vatsimauth.h" +#ifdef SWIFT_VATSIM_SUPPORT +# include "vatsim/vatsimauth.h" +#endif #include #include @@ -114,7 +116,11 @@ namespace BlackCore::Fsd m_versionMajor = major; m_versionMinor = minor; } + +#ifdef SWIFT_VATSIM_SUPPORT void setClientIdAndKey(quint16 id, const QByteArray &key); +#endif + void setClientCapabilities(Capabilities capabilities) { QWriteLocker l(&m_lockUserClientBuffered); @@ -404,7 +410,9 @@ namespace BlackCore::Fsd void sendAuthResponse(const QString &response); void sendPong(const QString &receiver, const QString ×tamp); void sendClientResponse(ClientQueryType queryType, const QString &receiver); +#ifdef SWIFT_VATSIM_SUPPORT void sendClientIdentification(const QString &fsdChallenge); +#endif void sendIncrementalAircraftConfig(); void readDataFromSocket() { this->readDataFromSocketMaxLines(); } @@ -423,8 +431,10 @@ namespace BlackCore::Fsd //! @{ //! Handle response tokens void handleAtcDataUpdate(const QStringList &tokens); +#ifdef SWIFT_VATSIM_SUPPORT void handleAuthChallenge(const QStringList &tokens); void handleAuthResponse(const QStringList &tokens); +#endif void handleDeleteATC(const QStringList &tokens); void handleDeletePilot(const QStringList &tokens); void handleTextMessage(const QStringList &tokens); @@ -440,7 +450,9 @@ namespace BlackCore::Fsd void handleClientResponse(const QStringList &tokens); void handleServerError(const QStringList &tokens); void handleCustomPilotPacket(const QStringList &tokens); +#ifdef SWIFT_VATSIM_SUPPORT void handleFsdIdentification(const QStringList &tokens); +#endif void handleRevBClientPartsPacket(const QStringList &tokens); void handleRehost(const QStringList &tokens); void handleMute(const QStringList &tokens); @@ -529,8 +541,10 @@ namespace BlackCore::Fsd //! Convert FlightRules to FlightType static FlightType getFlightType(BlackMisc::Aviation::CFlightPlan::FlightRules flightRule); +#ifdef SWIFT_VATSIM_SUPPORT vatsim_auth *m_clientAuth = nullptr; vatsim_auth *m_serverAuth = nullptr; +#endif QString m_lastServerAuthChallenge; qint64 m_loginSince = -1; //!< when login was triggered static constexpr qint64 PendingConnectionTimeoutMs = 7500; diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index b8bac8ff1..be0abcb5d 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -298,6 +298,7 @@ bool CSwiftLauncher::setSwiftDataExecutable() m_executable = CSwiftDirectories::executableFilePath(CBuildConfig::swiftDataExecutableName()); QStringList fsdArgs; +#ifdef SWIFT_VATSIM_SUPPORT int id = 0; QString key; if (IContextNetwork::getCmdLineClientIdAndKey(id, key)) @@ -306,6 +307,7 @@ bool CSwiftLauncher::setSwiftDataExecutable() fsdArgs << "--idAndKey"; fsdArgs << sApp->getParserValue("clientIdAndKey"); // as typed in } +#endif m_executableArgs = sGui->argumentsJoined({}, fsdArgs); return true; diff --git a/tests/blackcore/fsd/testfsdclient/testfsdclient.cpp b/tests/blackcore/fsd/testfsdclient/testfsdclient.cpp index 2ba85cc8d..153444924 100644 --- a/tests/blackcore/fsd/testfsdclient/testfsdclient.cpp +++ b/tests/blackcore/fsd/testfsdclient/testfsdclient.cpp @@ -152,8 +152,10 @@ namespace BlackFsdTest m_client->setPilotRating(PilotRating::Student); m_client->setSimType(CSimulatorInfo::xplane()); m_client->setPilotRating(PilotRating::Student); +#ifdef SWIFT_VATSIM_SUPPORT QString key("727d1efd5cb9f8d2c28372469d922bb4"); m_client->setClientIdAndKey(0xb9ba, key.toLocal8Bit()); +#endif } void CTestFSDClient::cleanup()