Ref T703, set partner callsign in network vatlib / functions in context adjusted

This commit is contained in:
Klaus Basan
2019-08-16 19:46:55 +02:00
committed by Mat Sutcliffe
parent bfcf553e3f
commit 6adea91618
9 changed files with 44 additions and 21 deletions

View File

@@ -245,7 +245,8 @@ namespace BlackCore
virtual BlackMisc::CStatusMessage connectToNetwork(
const BlackMisc::Network::CServer &server,
const QString &extraLiveryString, bool sendLivery,
const QString &extraModelString, bool sendModelString,
const QString &extraModelString, bool sendModelString,
const BlackMisc::Aviation::CCallsign &partnerCallsign,
BlackCore::INetwork::LoginMode loginMode) = 0;
//! Server which is connected, if not connected empty default object.

View File

@@ -124,7 +124,7 @@ namespace BlackCore
}
//! \copydoc IContextNetwork::connectToNetwork
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, BlackCore::INetwork::LoginMode mode) override
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, const BlackMisc::Aviation::CCallsign &partnerCallsign, BlackCore::INetwork::LoginMode mode) override
{
Q_UNUSED(mode);
Q_UNUSED(server);
@@ -132,6 +132,7 @@ namespace BlackCore
Q_UNUSED(extraLiveryString);
Q_UNUSED(sendLivery);
Q_UNUSED(sendModelString);
Q_UNUSED(partnerCallsign);
logEmptyContextWarning(Q_FUNC_INFO);
return statusMessageEmptyContext();
}

View File

@@ -76,8 +76,8 @@ namespace BlackCore
connect(m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::onFsdConnectionStatusChanged);
connect(m_network, &INetwork::kicked, this, &CContextNetwork::kicked);
connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived);
connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::checkForSupervisiorTextMessage);
connect(m_network, &INetwork::textMessageSent, this, &CContextNetwork::textMessageSent);
connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::onTextMessagesReceived, Qt::QueuedConnection);
connect(m_network, &INetwork::textMessageSent, this, &CContextNetwork::textMessageSent);
// 2. Update timer for data (network data such as frequency)
// we use 2 timers so we can query at different times (not too many queirs at once)
@@ -218,20 +218,21 @@ namespace BlackCore
if (m_airspace) { m_airspace->gracefulShutdown(); }
}
CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, INetwork::LoginMode mode)
CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, const CCallsign &partnerCallsign, INetwork::LoginMode mode)
{
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
QString msg;
if (!server.getUser().hasCredentials()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, u"Invalid user credentials"); }
if (!this->ownAircraft().getAircraftIcaoCode().hasDesignator()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, u"Invalid ICAO data for own aircraft"); }
if (!CNetworkUtils::canConnect(server, msg, 5000)) { return CStatusMessage(CStatusMessage::SeverityError, msg); }
if (m_network->isConnected()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, u"Already connected"); }
if (m_network->isConnected()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, u"Already connected"); }
if (this->isPendingConnection()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, u"Pending connection, please wait"); }
m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect
this->getIContextOwnAircraft()->updateOwnAircraftPilot(server.getUser());
const CSimulatedAircraft ownAircraft(this->ownAircraft());
m_network->presetServer(server);
m_network->presetPartnerCallsign(partnerCallsign);
// Fall back to observer mode, if no simulator is available or not simulating
if (!CBuildConfig::isLocalDeveloperDebugBuild() && !this->getIContextSimulator()->isSimulatorSimulating())
@@ -664,7 +665,7 @@ namespace BlackCore
m_dsAtcStationsOnlineChanged.inputSignal(); // the ATIS data are stored in the station object
}
void CContextNetwork::checkForSupervisiorTextMessage(const CTextMessageList &messages)
void CContextNetwork::onTextMessagesReceived(const CTextMessageList &messages)
{
if (messages.containsPrivateMessages())
{

View File

@@ -252,7 +252,7 @@ namespace BlackCore
virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual BlackMisc::Aviation::CAtcStationList getOnlineStationsForFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ChannelSpacing channelSpacing) const override;
virtual bool isOnlineStation(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, BlackCore::INetwork::LoginMode mode) override;
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, const BlackMisc::Aviation::CCallsign &partnerCallsign, BlackCore::INetwork::LoginMode mode) override;
virtual BlackMisc::Network::CServer getConnectedServer() const override;
virtual INetwork::LoginMode getLoginMode() const override;
virtual BlackMisc::CStatusMessage disconnectFromNetwork() override;
@@ -310,8 +310,8 @@ namespace BlackCore
//! Update METAR collection
void updateMetars(const BlackMisc::Weather::CMetarList &metars);
//! Check if a supervisor message was received
void checkForSupervisiorTextMessage(const BlackMisc::Network::CTextMessageList &messages);
//! Check if a supervisor message was received, message has to be relayed ...
void onTextMessagesReceived(const BlackMisc::Network::CTextMessageList &messages);
//! An ATIS has been received
void onChangedAtisReceived(const BlackMisc::Aviation::CCallsign &callsign);

View File

@@ -353,9 +353,9 @@ namespace BlackCore
return m_dBusInterface->callDBusRet<bool>(QLatin1String("testAddAltitudeOffset"), callsign, offset);
}
CStatusMessage CContextNetworkProxy::connectToNetwork(const CServer &server, const QString &extraLiveryString, bool sendLiveryString, const QString &extraModelString, bool sendModelString, INetwork::LoginMode loginMode)
CStatusMessage CContextNetworkProxy::connectToNetwork(const CServer &server, const QString &extraLiveryString, bool sendLiveryString, const QString &extraModelString, bool sendModelString, const CCallsign &partnerCallsign, INetwork::LoginMode loginMode)
{
return m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1String("connectToNetwork"), server, extraLiveryString, sendLiveryString, extraModelString, sendModelString, loginMode);
return m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1String("connectToNetwork"), server, extraLiveryString, sendLiveryString, extraModelString, sendModelString, partnerCallsign, loginMode);
}
CStatusMessage CContextNetworkProxy::disconnectFromNetwork()

View File

@@ -88,7 +88,7 @@ namespace BlackCore
virtual BlackMisc::Aviation::CAtcStationList getOnlineStationsForFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ChannelSpacing channelSpacing) const override;
virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual bool isOnlineStation(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, BlackCore::INetwork::LoginMode mode) override;
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, const BlackMisc::Aviation::CCallsign &partnerCallsign, BlackCore::INetwork::LoginMode mode) override;
virtual BlackMisc::CStatusMessage disconnectFromNetwork() override;
virtual bool isConnected() const override;
virtual BlackMisc::Network::CServer getConnectedServer() const override;

View File

@@ -203,6 +203,17 @@ namespace BlackCore
*/
virtual void presetCallsign(const BlackMisc::Aviation::CCallsign &callsign) = 0;
/*!
* Set the partner callsign (co-pilot/pilot in shared cockpit) before connecting.
* \pre Network must be disconnected when calling this function.
*/
virtual void presetPartnerCallsign(const BlackMisc::Aviation::CCallsign &callsign) = 0;
/*!
* Get the partner callsign (co-pilot/pilot in shared cockpit) before connecting.
*/
virtual const BlackMisc::Aviation::CCallsign &getPresetPartnerCallsign() const = 0;
/*!
* Set our own aircraft ICAO codes before connecting.
* \pre Network must be disconnected when calling this function.

View File

@@ -190,7 +190,8 @@ namespace BlackCore
m_ownLivery,
m_ownAircraftIcaoCode.getDesignator(),
m_ownAirlineIcaoCode.getVDesignator(),
m_ownCallsign.asString()
m_ownCallsign.asString(),
m_partnerCallsign.asString()
};
return v;
}
@@ -492,7 +493,12 @@ namespace BlackCore
{
Q_ASSERT_X(isDisconnected(), Q_FUNC_INFO, "Can't change callsign while still connected");
m_ownCallsign = callsign;
updateOwnCallsign(callsign);
this->updateOwnCallsign(callsign);
}
void CNetworkVatlib::presetPartnerCallsign(const CCallsign &callsign)
{
m_partnerCallsign = callsign;
}
void CNetworkVatlib::presetIcaoCodes(const CSimulatedAircraft &ownAircraft)
@@ -1505,7 +1511,7 @@ namespace BlackCore
{
QList<qint64> &offsets = m_lastOffsetTimes[callsign];
offsets.push_front(offsetMs);
if (offsets.size() > MaxOffseTimes) { offsets.removeLast(); }
if (offsets.size() > MaxOffsetTimes) { offsets.removeLast(); }
}
qint64 CNetworkVatlib::averageOffsetTimeMs(const CCallsign &callsign, int &count, int maxLastValues) const

View File

@@ -81,9 +81,11 @@ namespace BlackCore
virtual bool isPendingConnection() const override { return m_status == vatStatusConnecting; }
virtual const BlackMisc::Network::CServer &getPresetServer() const override { return m_server; }
virtual QStringList getPresetValues() const override;
virtual const BlackMisc::Aviation::CCallsign &getPresetPartnerCallsign() const override { return m_partnerCallsign; }
virtual void presetLoginMode(LoginMode mode) override;
virtual void presetServer(const BlackMisc::Network::CServer &server) override;
virtual void presetCallsign(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual void presetPartnerCallsign(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual void presetIcaoCodes(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft) override;
virtual void presetLiveryAndModelString(const QString &livery, bool sendLiveryString, const QString &modelString, bool sendModelString) override;
virtual void presetSimulatorInfo(const BlackMisc::Simulation::CSimulatorPluginInfo &simInfo) override;
@@ -140,8 +142,8 @@ namespace BlackCore
static const QList<QCommandLineOption> &getCmdLineOptions();
private:
static int constexpr c_processingIntervalMsec = 100; //!< interval for the processing timer
static int constexpr c_updatePostionIntervalMsec = 5000; //!< interval for the position update timer (send our position to network)
static int constexpr c_processingIntervalMsec = 100; //!< interval for the processing timer
static int constexpr c_updatePostionIntervalMsec = 5000; //!< interval for the position update timer (send our position to network)
static int constexpr c_updateInterimPostionIntervalMsec = 1000; //!< interval for iterim position updates (send our position as interim position)
qint64 m_additionalOffsetTime = 0; //!< additional offset time
@@ -258,10 +260,10 @@ namespace BlackCore
void insertLatestOffsetTime(const BlackMisc::Aviation::CCallsign &callsign, qint64 offsetMs);
//! Average offset time in ms
qint64 averageOffsetTimeMs(const BlackMisc::Aviation::CCallsign &callsign, int &count, int maxLastValues = MaxOffseTimes) const;
qint64 averageOffsetTimeMs(const BlackMisc::Aviation::CCallsign &callsign, int &count, int maxLastValues = MaxOffsetTimes) const;
//! Average offset time in ms
qint64 averageOffsetTimeMs(const BlackMisc::Aviation::CCallsign &callsign, int maxLastValues = MaxOffseTimes) const;
qint64 averageOffsetTimeMs(const BlackMisc::Aviation::CCallsign &callsign, int maxLastValues = MaxOffsetTimes) const;
//! Remove colon
static QString removeColon(const QString &candidate);
@@ -289,6 +291,7 @@ namespace BlackCore
QTextCodec *m_fsdTextCodec = nullptr;
BlackMisc::Simulation::CSimulatorPluginInfo m_simulatorInfo; //!< used simulator
BlackMisc::Aviation::CCallsign m_ownCallsign; //!< "buffered callsign", as this must not change when connected
BlackMisc::Aviation::CCallsign m_partnerCallsign; //!< callsign of partner flying in shared cockpit
BlackMisc::Aviation::CAircraftIcaoCode m_ownAircraftIcaoCode; //!< "buffered icao", as this must not change when connected
BlackMisc::Aviation::CAirlineIcaoCode m_ownAirlineIcaoCode; //!< "buffered icao", as this must not change when connected
QString m_ownLivery; //!< "buffered livery", as this must not change when connected
@@ -318,7 +321,7 @@ namespace BlackCore
QHash<BlackMisc::Aviation::CCallsign, qint64> m_lastPositionUpdate;
QHash<BlackMisc::Aviation::CCallsign, QList<qint64>> m_lastOffsetTimes; //!< latest offset first
static const int MaxOffseTimes = 6; //!< Max offset times kept
static const int MaxOffsetTimes = 6; //!< Max offset times kept
BlackMisc::CSettingReadOnly<BlackCore::Vatsim::TRawFsdMessageSetting> m_fsdMessageSetting { this, &CNetworkVatlib::fsdMessageSettingsChanged };
QFile m_rawFsdMessageLogFile;