diff --git a/mkspecs/features/defines.pri b/mkspecs/features/defines.pri index 8dba21926..7f79e26ba 100644 --- a/mkspecs/features/defines.pri +++ b/mkspecs/features/defines.pri @@ -1,4 +1,10 @@ +# some global compile options +# DEFINES += SWIFT_BETA +# DEFINES += SWIFT_SHIPPED DEFINES += BLACK_VERSION=$$BLACK_VERSION +DEFINES += BLACK_CLIENT_PUBLIC_ID=0xb9ba +DEFINES += BLACK_CLIENT_PRIVATE_KEY=727d1efd5cb9f8d2c28372469d922bb4 +DEFINES += BLACK_EOL=20170101 contains(BLACK_CONFIG, BlackSound) { DEFINES += WITH_BLACKSOUND } contains(BLACK_CONFIG, BlackInput) { DEFINES += WITH_BLACKINPUT } diff --git a/src/blackcore/networkvatlib.cpp b/src/blackcore/networkvatlib.cpp index 4fa0da266..44c2a36ab 100644 --- a/src/blackcore/networkvatlib.cpp +++ b/src/blackcore/networkvatlib.cpp @@ -10,6 +10,7 @@ //! \cond PRIVATE #include "networkvatlib.h" +#include "application.h" #include "blackmisc/project.h" #include "blackmisc/logmessage.h" #include @@ -19,11 +20,13 @@ static_assert(! std::is_abstract::value, "Must implement all pure virtuals"); static_assert(VAT_LIBVATLIB_VERSION == 905, "Wrong vatlib header installed"); -// TODO just placeholders to allow this to compile -// This is just a test key and is NOT valid on the live network. -// Replace it with the BoG assigned key before shipping the installer -#define CLIENT_PUBLIC_ID 0xb9ba -#define CLIENT_PRIVATE_KEY "727d1efd5cb9f8d2c28372469d922bb4" +#if !defined(BLACK_CLIENT_PUBLIC_ID) +#error Missing definition of id +#endif + +#if !defined(BLACK_CLIENT_PRIVATE_KEY) +#error Missing definition of pk +#endif using namespace BlackMisc; using namespace BlackMisc::Aviation; @@ -35,7 +38,6 @@ using namespace BlackMisc::Simulation; namespace BlackCore { - CNetworkVatlib::CNetworkVatlib(Simulation::IOwnAircraftProvider *ownAircraft, QObject *parent) : INetwork(parent), COwnAircraftAware(ownAircraft), m_loginMode(LoginNormal), @@ -69,9 +71,11 @@ namespace BlackCore clientCapabilities |= vatCapsStealth; } - m_net.reset(Vat_CreateNetworkSession(vatServerLegacyFsd, CProject::swiftVersionChar(), + static const QString pkDef(BLACK_STRINGIFY(BLACK_CLIENT_PRIVATE_KEY)); + static const QByteArray pk(this->getCmdLineFsdKey().isEmpty() ? pkDef.toLocal8Bit() : this->getCmdLineFsdKey().toLocal8Bit()); + m_net.reset(Vat_CreateNetworkSession(vatServerLegacyFsd, sApp->swiftVersionChar(), CProject::versionMajor(), CProject::versionMinor(), - "None", CLIENT_PUBLIC_ID, CLIENT_PRIVATE_KEY, + "None", BLACK_CLIENT_PUBLIC_ID, pk.constData(), clientCapabilities)); Vat_SetStateChangeHandler(m_net.data(), onConnectionStatusChanged, this); @@ -591,6 +595,25 @@ namespace BlackCore Vat_RequestMetar(m_net.data(), toFSD(airportIcao.asString())); } + const QList &CNetworkVatlib::getCmdLineOptions() + { + static const QList e; + static const QList opts + { + QCommandLineOption({ "key", "fsdkey" }, + QCoreApplication::translate("application", "Key for FSD"), + "fsdkey") + }; + + // only in not officially shipped versions + return (CProject::isShippedVersion() && !CProject::isBetaTest()) ? e : opts; + } + + QString CNetworkVatlib::getCmdLineFsdKey() const + { + return sApp->getParserValue("fsdkey").toLower(); + } + void CNetworkVatlib::sendCustomFsinnQuery(const BlackMisc::Aviation::CCallsign &callsign) { Q_ASSERT_X(isConnected(), "CNetworkVatlib", "Can't send to server when disconnected"); @@ -643,7 +666,7 @@ namespace BlackCore /********************************** shimlib callbacks ************************************/ /********************************** * * * * * * * * * * * * * * * * * * * ************************************/ - //! Cast void* to a pointer of CNetworkVatlib +//! Cast void* to a pointer of CNetworkVatlib CNetworkVatlib *cbvar_cast(void *cbvar) { return static_cast(cbvar); diff --git a/src/blackcore/networkvatlib.h b/src/blackcore/networkvatlib.h index 9a9645d9d..057d36bf5 100644 --- a/src/blackcore/networkvatlib.h +++ b/src/blackcore/networkvatlib.h @@ -23,13 +23,14 @@ #include #include #include +#include namespace BlackCore { //! Implementation of INetwork using the vatlib shim class BLACKCORE_EXPORT CNetworkVatlib : - public INetwork, - public BlackMisc::Simulation::COwnAircraftAware // network vatlib consumes own aircraft data and sets ICAO/callsign data + public INetwork, + public BlackMisc::Simulation::COwnAircraftAware // network vatlib consumes own aircraft data and sets ICAO/callsign data { Q_OBJECT @@ -91,6 +92,12 @@ namespace BlackCore virtual void sendMetarQuery(const BlackMisc::Aviation::CAirportIcaoCode &airportIcao) override; //! @} + //! Cmd.line options this library can handle + static const QList &getCmdLineOptions(); + + //! Key if any from cmd.line arguments + QString getCmdLineFsdKey() const; + private slots: void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign); void replyToNameQuery(const BlackMisc::Aviation::CCallsign &callsign); @@ -189,6 +196,6 @@ namespace BlackCore CTokenBucket m_tokenBucket; }; -} //namespace BlackCore +} //namespace #endif // guard