diff --git a/samples/cli_client/sample_cli_client.pro b/samples/cli_client/sample_cli_client.pro index b3587e31b..94464d205 100644 --- a/samples/cli_client/sample_cli_client.pro +++ b/samples/cli_client/sample_cli_client.pro @@ -8,7 +8,7 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -CONFIG += blackmisc blackcore +CONFIG += blackmisc blackcore blacksim DEPENDPATH += . ../../src INCLUDEPATH += . ../../src @@ -17,9 +17,11 @@ SOURCES += *.cpp HEADERS += *.h win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib + ../../lib/blackcore.lib \ + ../../lib/blacksim.lib else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a + ../../lib/libblackcore.a \ + ../../lib/blacksim.a DESTDIR = ../../bin diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index 05925943d..a2c0c5a74 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -33,6 +33,7 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Geo; using namespace BlackMisc::Audio; using namespace BlackMisc::Simulation; +using namespace BlackSim; namespace BlackCore { @@ -176,6 +177,14 @@ namespace BlackCore this->m_network->presetLoginMode(mode); this->m_network->presetCallsign(ownAircraft.getCallsign()); this->m_network->presetIcaoCodes(ownAircraft.getIcaoInfo()); + if (getIContextSimulator()) + { + this->m_network->presetSimulatorInfo(getIContextSimulator()->getSimulatorInfo()); + } + else + { + this->m_network->presetSimulatorInfo(CSimulatorInfo::UnspecifiedSim()); + } this->m_network->initiateConnection(); return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection pending " + server.getAddress() + " " + QString::number(server.getPort())); } diff --git a/src/blackcore/network.h b/src/blackcore/network.h index a5613a9b0..4397b368a 100644 --- a/src/blackcore/network.h +++ b/src/blackcore/network.h @@ -12,6 +12,7 @@ #ifndef BLACKCORE_NETWORK_H #define BLACKCORE_NETWORK_H +#include "blacksim/simulatorinfo.h" #include "blackmisc/avaircraft.h" #include "blackmisc/pqfrequency.h" #include "blackmisc/coordinategeodetic.h" @@ -177,6 +178,12 @@ namespace BlackCore */ virtual void presetLoginMode(LoginMode mode) = 0; + /*! + * Set simulator info before connecting. + * \pre Network must be disconnected when calling this function. + */ + virtual void presetSimulatorInfo(const BlackSim::CSimulatorInfo &simInfo) = 0; + /*! * Initiate a connection to the network server. * \pre Network must be disconnected when calling this function. diff --git a/src/blackcore/network_vatlib.cpp b/src/blackcore/network_vatlib.cpp index 06ab5db0d..bf5c794c7 100644 --- a/src/blackcore/network_vatlib.cpp +++ b/src/blackcore/network_vatlib.cpp @@ -28,6 +28,7 @@ using namespace BlackMisc::Aviation; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc; +using namespace BlackSim; namespace BlackCore { @@ -254,6 +255,15 @@ namespace BlackCore return escaped; } + VatSimType CNetworkVatlib::convertToSimType(CSimulatorInfo &simInfo) + { + if (simInfo.isUnspecified()) { return vatSimTypeUnknown; } + if (CSimulatorInfo::FS9().isSameSimulator(simInfo)) { return vatSimTypeMSCFS; } + if (CSimulatorInfo::FSX().isSameSimulator(simInfo)) { return vatSimTypeMSCFS; } + if (CSimulatorInfo::XP().isSameSimulator(simInfo)) { return vatSimTypeXPLANE; } + return vatSimTypeUnknown; + } + /********************************** * * * * * * * * * * * * * * * * * * * ************************************/ /********************************** INetwork slots ************************************/ /********************************** * * * * * * * * * * * * * * * * * * * ************************************/ @@ -264,6 +274,12 @@ namespace BlackCore m_server = server; } + void CNetworkVatlib::presetSimulatorInfo(const CSimulatorInfo &simInfo) + { + Q_ASSERT_X(isDisconnected(), "CNetworkVatlib", "Can't change server details while still connected"); + m_simulatorInfo = simInfo; + } + void CNetworkVatlib::presetCallsign(const BlackMisc::Aviation::CCallsign &callsign) { Q_ASSERT_X(isDisconnected(), "CNetworkVatlib", "Can't change callsign while still connected"); @@ -318,7 +334,7 @@ namespace BlackCore info.callsign = callsign.data(); info.name = name.data(); info.rating = vatPilotRatingStudent; //TODO - info.simType = vatSimTypeMSFS98; //TODO + info.simType = convertToSimType(m_simulatorInfo); Vat_SpecifyPilotLogon(m_net.data(), toFSD(m_server.getAddress()), m_server.getPort(), toFSD(m_server.getUser().getId()), toFSD(m_server.getUser().getPassword()), @@ -856,7 +872,7 @@ namespace BlackCore default: case vatFlightTypeVFR: rules = BlackMisc::Aviation::CFlightPlan::VFR; break; case vatFlightTypeIFR: rules = BlackMisc::Aviation::CFlightPlan::IFR; break; -// case Cvatlib_Network::fpRuleType_SVFR: rules = BlackMisc::Aviation::CFlightPlan::SVFR; break; + // case Cvatlib_Network::fpRuleType_SVFR: rules = BlackMisc::Aviation::CFlightPlan::SVFR; break; } auto cruiseAltString = cbvar_cast(cbvar)->fromFSD(fp->cruiseAltitude); @@ -868,7 +884,6 @@ namespace BlackCore BlackMisc::Aviation::CAltitude cruiseAlt; cruiseAlt.parseFromString(cruiseAltString); - QString depTimePlanned = QString("0000").append(QString::number(fp->departTime)).right(4); QString depTimeActual = QString("0000").append(QString::number(fp->departTimeActual)).right(4); diff --git a/src/blackcore/network_vatlib.h b/src/blackcore/network_vatlib.h index 2fe8ec5ca..dcbedb5bd 100644 --- a/src/blackcore/network_vatlib.h +++ b/src/blackcore/network_vatlib.h @@ -51,6 +51,7 @@ namespace BlackCore virtual void presetServer(const BlackMisc::Network::CServer &server) override; virtual void presetCallsign(const BlackMisc::Aviation::CCallsign &callsign) override; virtual void presetIcaoCodes(const BlackMisc::Aviation::CAircraftIcao &icao) override; + virtual void presetSimulatorInfo(const BlackSim::CSimulatorInfo &simInfo) override; virtual void initiateConnection() override; virtual void terminateConnection() override; virtual void sendPing(const BlackMisc::Aviation::CCallsign &callsign) override; @@ -129,7 +130,8 @@ namespace BlackCore void initializeSession(); void changeConnectionStatus(VatConnectionStatus newStatus); bool isDisconnected() const { return m_status != vatStatusConnecting && m_status != vatStatusConnected; } - QString convertToUnicodeEscaped(const QString &str); + static QString convertToUnicodeEscaped(const QString &str); + static VatSimType convertToSimType(BlackSim::CSimulatorInfo &simInfo); static void networkErrorHandler(const char *message); struct JsonPackets @@ -158,6 +160,7 @@ namespace BlackCore LoginMode m_loginMode; VatConnectionStatus m_status; BlackMisc::Network::CServer m_server; + BlackSim::CSimulatorInfo m_simulatorInfo; BlackMisc::Aviation::CCallsign m_callsign; //!< "buffered callsign", as this must not change when connected BlackMisc::Aviation::CAircraftIcao m_icaoCode; //!< "buffered icao", as this must not change when connected bool m_sendInterimPositions = false; //!< send interim positions diff --git a/src/blacksim/simulatorinfo.h b/src/blacksim/simulatorinfo.h index ba91608fb..973654594 100644 --- a/src/blacksim/simulatorinfo.h +++ b/src/blacksim/simulatorinfo.h @@ -89,10 +89,10 @@ namespace BlackSim } BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::CSimulatorInfo, ( - o.m_fullName, - o.m_shortName, - attr(o.m_simsetup, flags()) -)) + o.m_fullName, + o.m_shortName, + attr(o.m_simsetup, flags()) + )) Q_DECLARE_METATYPE(BlackSim::CSimulatorInfo) #endif // guard diff --git a/tests/blackcore/test_blackcore.pro b/tests/blackcore/test_blackcore.pro index 74b1b7e9d..54ebc6e7c 100644 --- a/tests/blackcore/test_blackcore.pro +++ b/tests/blackcore/test_blackcore.pro @@ -8,7 +8,7 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -CONFIG += blackmisc blackcore +CONFIG += blackmisc blackcore blacksim CONFIG += testcase DEPENDPATH += . ../../src @@ -18,9 +18,11 @@ HEADERS += *.h SOURCES += *.cpp win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib + ../../lib/blackcore.lib \ + ../../lib/blacksim.lib else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a + ../../lib/libblackcore.a \ + ../../lib/libblacksim.a DESTDIR = ../../bin