From a1490fd4e0c4d87c61ad2a40312035ed6da56df9 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 24 Apr 2019 13:38:00 +0200 Subject: [PATCH] Ref T632, mix fixes * avoid empty callsign CClient object (harmless, but stupid) * better validations in client provider * check aircraft config packets (really broadcasts) --- src/blackcore/airspacemonitor.cpp | 3 +++ src/blackmisc/network/clientprovider.cpp | 24 +++++++++++++++---- .../simulation/remoteaircraftprovider.cpp | 7 +++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index c5ca14a8b..3622fc5a0 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -1070,9 +1070,12 @@ namespace BlackCore { Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this)); this->storeAircraftParts(callsign, jsonObject, currentOffsetMs); + BLACK_AUDIT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Need callsign"); + if (callsign.isEmpty()) { return; } // update client capability CClient client = this->getClientOrDefaultForCallsign(callsign); + client.setUserCallsign(callsign); // make valid by setting a callsign if (client.hasCapability(CClient::FsdWithAircraftConfig)) { return; } client.addCapability(CClient::FsdWithAircraftConfig); this->setOtherClient(client); diff --git a/src/blackmisc/network/clientprovider.cpp b/src/blackmisc/network/clientprovider.cpp index 689250fb9..75a653e72 100644 --- a/src/blackmisc/network/clientprovider.cpp +++ b/src/blackmisc/network/clientprovider.cpp @@ -8,6 +8,7 @@ #include "clientprovider.h" #include "blackmisc/aviation/aircraftsituation.h" +#include "blackmisc/verify.h" using namespace BlackMisc::Aviation; @@ -40,17 +41,25 @@ namespace BlackMisc CClientList CClientProvider::getClientsForCallsigns(const CCallsignSet &callsigns) const { + if (callsigns.isEmpty()) { return {}; } return this->getClients().findByCallsigns(callsigns); } CClient CClientProvider::getClientOrDefaultForCallsign(const CCallsign &callsign) const { - QReadLocker l(&m_lockClient); - return m_clients.value(callsign); + if (callsign.isEmpty()) { return {}; } + { + QReadLocker l(&m_lockClient); + if (m_clients.contains(callsign)) { return m_clients.value(callsign); } + } + return CClient(); } bool CClientProvider::setOtherClient(const CClient &client) { + const bool hasCallsign = !client.getCallsign().isEmpty(); + BLACK_VERIFY_X(hasCallsign, Q_FUNC_INFO, "Need callsign in client"); + if (!hasCallsign) { return false; } QWriteLocker l(&m_lockClient); m_clients[client.getCallsign()] = client; return true; @@ -58,6 +67,7 @@ namespace BlackMisc bool CClientProvider::hasClientInfo(const CCallsign &callsign) const { + if (callsign.isEmpty()) { return false; } QReadLocker l(&m_lockClient); return m_clients.contains(callsign); } @@ -65,7 +75,8 @@ namespace BlackMisc bool CClientProvider::addNewClient(const CClient &client) { const CCallsign callsign = client.getCallsign(); - Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "invalid callsign"); + BLACK_VERIFY_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing client callsign"); + if (callsign.isEmpty()) { return false; } if (this->hasClientInfo(callsign)) { return false; } QWriteLocker l(&m_lockClient); m_clients[callsign] = client; @@ -74,7 +85,8 @@ namespace BlackMisc int CClientProvider::updateOrAddClient(const CCallsign &callsign, const CPropertyIndexVariantMap &vm, bool skipEqualValues) { - Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing callsign"); + BLACK_VERIFY_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing client callsign"); + if (callsign.isEmpty()) { return 0; } int c = 0; if (this->hasClientInfo(callsign)) { @@ -113,6 +125,9 @@ namespace BlackMisc bool CClientProvider::setClientGndCapability(const CCallsign &callsign, bool supportGndFlag) { + BLACK_VERIFY_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing client callsign"); + if (callsign.isEmpty()) { return 0; } + CClient client = this->getClientOrDefaultForCallsign(callsign); // need to change? @@ -133,6 +148,7 @@ namespace BlackMisc void CClientProvider::markAsSwiftClient(const CCallsign &callsign) { + if (callsign.isEmpty()) { return; } QWriteLocker l(&m_lockClient); if (!m_clients.contains(callsign)) { return; } m_clients[callsign].setSwiftClient(true); diff --git a/src/blackmisc/simulation/remoteaircraftprovider.cpp b/src/blackmisc/simulation/remoteaircraftprovider.cpp index 6952304c5..f59c7c767 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.cpp +++ b/src/blackmisc/simulation/remoteaircraftprovider.cpp @@ -402,9 +402,14 @@ namespace BlackMisc { const CSimulatedAircraft remoteAircraft(this->getAircraftInRangeForCallsign(callsign)); const bool isFull = jsonObject.value(CAircraftParts::attributeNameIsFullJson()).toBool(); + const bool validCs = remoteAircraft.hasValidCallsign(); + if (!validCs) + { + if (!isFull) { return; } // incremental parts broadcasting + return; // suspicious + } // If we are not yet synchronized, we throw away any incremental packet - if (!remoteAircraft.hasValidCallsign()) { return; } if (!remoteAircraft.isPartsSynchronized() && !isFull) { return; } CAircraftParts parts;