mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 02:06:08 +08:00
Set simulator info when connecting to network
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -89,10 +89,10 @@ namespace BlackSim
|
||||
}
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::CSimulatorInfo, (
|
||||
o.m_fullName,
|
||||
o.m_shortName,
|
||||
attr(o.m_simsetup, flags<DisabledForComparison>())
|
||||
))
|
||||
o.m_fullName,
|
||||
o.m_shortName,
|
||||
attr(o.m_simsetup, flags<DisabledForComparison>())
|
||||
))
|
||||
Q_DECLARE_METATYPE(BlackSim::CSimulatorInfo)
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user