mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 22:29:13 +08:00
Passing connection status to airspace monitor.
When the network connection is terminated, airspace monitor can still recevice pending signals from vatlib. Those have to be ignored. Otherwise it can happen aircraft (.. etc.) are added again to airspace, which gives inconsistent results.
This commit is contained in:
@@ -352,10 +352,19 @@ namespace BlackCore
|
|||||||
removeAllOtherClients();
|
removeAllOtherClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAirspaceMonitor::setConnected(bool connected)
|
||||||
|
{
|
||||||
|
this->m_connected = connected;
|
||||||
|
if (!connected)
|
||||||
|
{
|
||||||
|
this->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
|
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
|
||||||
{
|
{
|
||||||
Q_ASSERT(this->m_vatsimDataFileReader);
|
Q_ASSERT(this->m_vatsimDataFileReader);
|
||||||
if (realname.isEmpty()) { return; }
|
if (!this->m_connected || realname.isEmpty()) { return; }
|
||||||
CPropertyIndexVariantMap vm({CAtcStation::IndexController, CUser::IndexRealName}, realname);
|
CPropertyIndexVariantMap vm({CAtcStation::IndexController, CUser::IndexRealName}, realname);
|
||||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||||
@@ -376,7 +385,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags)
|
void CAirspaceMonitor::ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags)
|
||||||
{
|
{
|
||||||
if (callsign.isEmpty()) { return; }
|
if (!this->m_connected || callsign.isEmpty()) { return; }
|
||||||
CPropertyIndexVariantMap capabilities;
|
CPropertyIndexVariantMap capabilities;
|
||||||
capabilities.addValue(CClient::FsdAtisCanBeReceived, (flags & INetwork::AcceptsAtisResponses));
|
capabilities.addValue(CClient::FsdAtisCanBeReceived, (flags & INetwork::AcceptsAtisResponses));
|
||||||
capabilities.addValue(CClient::FsdWithInterimPositions, (flags & INetwork::SupportsInterimPosUpdates));
|
capabilities.addValue(CClient::FsdWithInterimPositions, (flags & INetwork::SupportsInterimPosUpdates));
|
||||||
@@ -398,7 +407,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::ps_fsipirCustomPacketReceived(const CCallsign &callsign, const QString &airlineIcao, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model)
|
void CAirspaceMonitor::ps_fsipirCustomPacketReceived(const CCallsign &callsign, const QString &airlineIcao, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &model)
|
||||||
{
|
{
|
||||||
if (callsign.isEmpty() || model.isEmpty()) { return; }
|
if (!this->m_connected || callsign.isEmpty() || model.isEmpty()) { return; }
|
||||||
|
|
||||||
// Request of other client, I can get the other's model from that
|
// Request of other client, I can get the other's model from that
|
||||||
CPropertyIndexVariantMap vm({ CClient::IndexModel, CAircraftModel::IndexModelString }, model);
|
CPropertyIndexVariantMap vm({ CClient::IndexModel, CAircraftModel::IndexModelString }, model);
|
||||||
@@ -433,7 +442,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::ps_serverReplyReceived(const CCallsign &callsign, const QString &server)
|
void CAirspaceMonitor::ps_serverReplyReceived(const CCallsign &callsign, const QString &server)
|
||||||
{
|
{
|
||||||
if (callsign.isEmpty() || server.isEmpty()) { return; }
|
if (!this->m_connected || callsign.isEmpty() || server.isEmpty()) { return; }
|
||||||
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
|
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
|
||||||
CPropertyIndexVariantMap vm(CClient::IndexServer, server);
|
CPropertyIndexVariantMap vm(CClient::IndexServer, server);
|
||||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||||
@@ -441,7 +450,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::ps_metarReceived(const QString &metarMessage)
|
void CAirspaceMonitor::ps_metarReceived(const QString &metarMessage)
|
||||||
{
|
{
|
||||||
if (metarMessage.length() < 10) return; // invalid
|
if (!this->m_connected || metarMessage.length() < 10) return; // invalid
|
||||||
const QString icaoCode = metarMessage.left(4).toUpper();
|
const QString icaoCode = metarMessage.left(4).toUpper();
|
||||||
const QString icaoCodeTower = icaoCode + "_TWR";
|
const QString icaoCodeTower = icaoCode + "_TWR";
|
||||||
CCallsign callsignTower(icaoCodeTower);
|
CCallsign callsignTower(icaoCodeTower);
|
||||||
@@ -465,6 +474,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::sendFsipiCustomPacket(const CCallsign &recipientCallsign) const
|
void CAirspaceMonitor::sendFsipiCustomPacket(const CCallsign &recipientCallsign) const
|
||||||
{
|
{
|
||||||
|
if (!this->m_connected) { return; }
|
||||||
CAircraftIcao icao = ownAircraft().getIcaoInfo();
|
CAircraftIcao icao = ownAircraft().getIcaoInfo();
|
||||||
QString modelString = ownAircraft().getModel().getModelString();
|
QString modelString = ownAircraft().getModel().getModelString();
|
||||||
if (modelString.isEmpty()) { modelString = CProject::systemNameAndVersion(); }
|
if (modelString.isEmpty()) { modelString = CProject::systemNameAndVersion(); }
|
||||||
@@ -473,6 +483,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::sendFsipirCustomPacket(const CCallsign &recipientCallsign) const
|
void CAirspaceMonitor::sendFsipirCustomPacket(const CCallsign &recipientCallsign) const
|
||||||
{
|
{
|
||||||
|
if (!this->m_connected) { return; }
|
||||||
CAircraftIcao icao = ownAircraft().getIcaoInfo();
|
CAircraftIcao icao = ownAircraft().getIcaoInfo();
|
||||||
QString modelString = ownAircraft().getModel().getModelString();
|
QString modelString = ownAircraft().getModel().getModelString();
|
||||||
if (modelString.isEmpty()) { modelString = CProject::systemNameAndVersion(); }
|
if (modelString.isEmpty()) { modelString = CProject::systemNameAndVersion(); }
|
||||||
@@ -553,7 +564,7 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::ps_sendReadyForModelMatching(const CCallsign &callsign, int trial)
|
void CAirspaceMonitor::ps_sendReadyForModelMatching(const CCallsign &callsign, int trial)
|
||||||
{
|
{
|
||||||
// some checks for special conditions, e.g. logout -> empty list, but still signals pending
|
// some checks for special conditions, e.g. logout -> empty list, but still signals pending
|
||||||
if (this->m_aircraftInRange.isEmpty()) { return; }
|
if (!this->m_connected || this->m_aircraftInRange.isEmpty()) { return; }
|
||||||
if (!this->m_aircraftInRange.containsCallsign(callsign)) { return; }
|
if (!this->m_aircraftInRange.containsCallsign(callsign)) { return; }
|
||||||
|
|
||||||
// build simulated aircraft and crosscheck if all data are available
|
// build simulated aircraft and crosscheck if all data are available
|
||||||
@@ -583,6 +594,7 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::ps_atcPositionUpdate(const CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range)
|
void CAirspaceMonitor::ps_atcPositionUpdate(const CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range)
|
||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||||
|
if (!this->m_connected) { return; }
|
||||||
CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign);
|
CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign);
|
||||||
if (stationsWithCallsign.isEmpty())
|
if (stationsWithCallsign.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -644,7 +656,7 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::ps_atisReceived(const CCallsign &callsign, const CInformationMessage &atisMessage)
|
void CAirspaceMonitor::ps_atisReceived(const CCallsign &callsign, const CInformationMessage &atisMessage)
|
||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||||
if (callsign.isEmpty()) return;
|
if (!this->m_connected || callsign.isEmpty()) return;
|
||||||
CPropertyIndexVariantMap vm(CAtcStation::IndexAtis, atisMessage.toCVariant());
|
CPropertyIndexVariantMap vm(CAtcStation::IndexAtis, atisMessage.toCVariant());
|
||||||
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||||
|
|
||||||
@@ -658,6 +670,7 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::ps_atisVoiceRoomReceived(const CCallsign &callsign, const QString &url)
|
void CAirspaceMonitor::ps_atisVoiceRoomReceived(const CCallsign &callsign, const QString &url)
|
||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||||
|
if (!this->m_connected) { return; }
|
||||||
QString trimmedUrl = url.trimmed();
|
QString trimmedUrl = url.trimmed();
|
||||||
CPropertyIndexVariantMap vm({ CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }, trimmedUrl);
|
CPropertyIndexVariantMap vm({ CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }, trimmedUrl);
|
||||||
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
|
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm, true);
|
||||||
@@ -684,6 +697,7 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::ps_atisLogoffTimeReceived(const CCallsign &callsign, const QString &zuluTime)
|
void CAirspaceMonitor::ps_atisLogoffTimeReceived(const CCallsign &callsign, const QString &zuluTime)
|
||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||||
|
if (!this->m_connected) { return; }
|
||||||
if (zuluTime.length() == 4)
|
if (zuluTime.length() == 4)
|
||||||
{
|
{
|
||||||
// Logic to set logoff time
|
// Logic to set logoff time
|
||||||
@@ -708,6 +722,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||||
Q_ASSERT(!callsign.isEmpty());
|
Q_ASSERT(!callsign.isEmpty());
|
||||||
|
if (!this->m_connected) { return; }
|
||||||
|
|
||||||
// update
|
// update
|
||||||
CPropertyIndexVariantMap vm(CAircraft::IndexIcao, icaoData.toCVariant());
|
CPropertyIndexVariantMap vm(CAircraft::IndexIcao, icaoData.toCVariant());
|
||||||
@@ -735,6 +750,7 @@ namespace BlackCore
|
|||||||
void CAirspaceMonitor::ps_aircraftUpdateReceived(const CCallsign &callsign, const CAircraftSituation &situation, const CTransponder &transponder)
|
void CAirspaceMonitor::ps_aircraftUpdateReceived(const CCallsign &callsign, const CAircraftSituation &situation, const CTransponder &transponder)
|
||||||
{
|
{
|
||||||
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
|
||||||
|
if (!this->m_connected) { return; }
|
||||||
|
|
||||||
// store situation history
|
// store situation history
|
||||||
CAircraftSituation situationWithCallsign(situation);
|
CAircraftSituation situationWithCallsign(situation);
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ namespace BlackCore
|
|||||||
//! Clear the contents
|
//! Clear the contents
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
//! Connection status
|
||||||
|
void setConnected(bool connected);
|
||||||
|
|
||||||
//! Request to update other clients' data from the network
|
//! Request to update other clients' data from the network
|
||||||
void requestDataUpdates();
|
void requestDataUpdates();
|
||||||
|
|
||||||
@@ -173,6 +176,7 @@ namespace BlackCore
|
|||||||
CAirspaceWatchdog m_atcWatchdog;
|
CAirspaceWatchdog m_atcWatchdog;
|
||||||
CAirspaceWatchdog m_aircraftWatchdog;
|
CAirspaceWatchdog m_aircraftWatchdog;
|
||||||
bool m_serverSupportsNameQuery = false; //!< not all servers support name query
|
bool m_serverSupportsNameQuery = false; //!< not all servers support name query
|
||||||
|
bool m_connected = false; //!< retrieve data
|
||||||
|
|
||||||
// TODO FIXME (MS) should be in INetwork
|
// TODO FIXME (MS) should be in INetwork
|
||||||
void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &recipientCallsign) const;
|
void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &recipientCallsign) const;
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ namespace BlackCore
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect
|
this->m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect
|
||||||
|
this->m_airspace->setConnected(true);
|
||||||
INetwork::LoginMode mode = static_cast<INetwork::LoginMode>(loginMode);
|
INetwork::LoginMode mode = static_cast<INetwork::LoginMode>(loginMode);
|
||||||
this->getIContextOwnAircraft()->updatePilot(server.getUser());
|
this->getIContextOwnAircraft()->updatePilot(server.getUser());
|
||||||
const CAircraft ownAircraft = this->ownAircraft();
|
const CAircraft ownAircraft = this->ownAircraft();
|
||||||
@@ -186,7 +187,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
this->m_currentStatus = INetwork::Disconnecting; // as semaphore we are going to disconnect
|
this->m_currentStatus = INetwork::Disconnecting; // as semaphore we are going to disconnect
|
||||||
this->m_network->terminateConnection();
|
this->m_network->terminateConnection();
|
||||||
this->m_airspace->clear();
|
this->m_airspace->setConnected(false);
|
||||||
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection terminating");
|
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection terminating");
|
||||||
}
|
}
|
||||||
else if (this->isPendingConnection())
|
else if (this->isPendingConnection())
|
||||||
|
|||||||
Reference in New Issue
Block a user