build: Add ifdef to disable VATSIM build

This commit is contained in:
Lars Toenning
2024-06-10 20:37:56 +02:00
parent dfbd8f05c8
commit b2ae4e5681
12 changed files with 56 additions and 2 deletions

View File

@@ -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")

View File

@@ -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");

View File

@@ -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

View File

@@ -5,6 +5,7 @@
#include <QString>
#include <QDateTime>
#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()
{

View File

@@ -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

View File

@@ -32,14 +32,17 @@ namespace BlackCore::Context
{
static const QList<QCommandLineOption> e;
static const QList<QCommandLineOption> opts {
#ifdef SWIFT_VATSIM_SUPPORT
QCommandLineOption({ "idAndKey", "clientIdAndKey" },
QCoreApplication::translate("CContextNetwork", "Client id and key pair separated by ':', e.g. <id>:<key>."), "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

View File

@@ -362,8 +362,10 @@ namespace BlackCore::Context
//! Cmd.line arguments
static const QList<QCommandLineOption> &getCmdLineOptions();
#ifdef SWIFT_VATSIM_SUPPORT
//! Client id and key from cmd.line
static bool getCmdLineClientIdAndKey(int &id, QString &key);
#endif
protected:
//! Constructor

View File

@@ -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<quint16>(clientId), clientKey.toLocal8Bit());
#endif
m_fsdClient->setClientCapabilities(Capabilities::AircraftInfo | Capabilities::FastPos | Capabilities::VisPos | Capabilities::AtcInfo | Capabilities::AircraftConfig | Capabilities::IcaoEquipment);
m_fsdClient->setServer(server);

View File

@@ -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<char, 50> 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<char, 50> sysuid = {};
@@ -1013,6 +1018,7 @@ namespace BlackCore::Fsd
}
increaseStatisticsValue(QStringLiteral("sendClientIdentification"));
}
#endif
void CFSDClient::getVatsimAuthToken(const QString &cid, const QString &password, const BlackMisc::CSlot<void(const QString &)> &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;

View File

@@ -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 <QtGlobal>
#include <QHash>
@@ -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 &timestamp);
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;

View File

@@ -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;

View File

@@ -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()