mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 03:15:34 +08:00
Handled some potentially "dangerous" parsing issues for VATSIM file (no coordinate)
https://discordapp.com/channels/539048679160676382/539486489977946112/593081121512751116
This commit is contained in:
@@ -283,12 +283,27 @@ namespace BlackCore
|
|||||||
const CUser user(clientPartsMap["cid"], clientPartsMap["realname"], callsign);
|
const CUser user(clientPartsMap["cid"], clientPartsMap["realname"], callsign);
|
||||||
const QString clientType = clientPartsMap["clienttype"].toLower();
|
const QString clientType = clientPartsMap["clienttype"].toLower();
|
||||||
if (clientType.isEmpty()) { break; } // sometimes type is empty
|
if (clientType.isEmpty()) { break; } // sometimes type is empty
|
||||||
const double lat = clientPartsMap["latitude"].toDouble();
|
|
||||||
const double lng = clientPartsMap["longitude"].toDouble();
|
bool ok;
|
||||||
const double alt = clientPartsMap["altitude"].toDouble();
|
bool validPos = true;
|
||||||
|
const double lat = clientPartsMap["latitude"].toDouble(&ok);
|
||||||
|
QStringList posMsg;
|
||||||
|
if (!ok) { validPos = false; posMsg << QStringLiteral("latitude: '%1'").arg(clientPartsMap["latitude"]); }
|
||||||
|
|
||||||
|
const double lng = clientPartsMap["longitude"].toDouble(&ok);
|
||||||
|
if (!ok) { validPos = false; posMsg << QStringLiteral("longitude: '%1'").arg(clientPartsMap["longitude"]); }
|
||||||
|
|
||||||
|
const double alt = clientPartsMap["altitude"].toDouble(&ok);
|
||||||
|
if (!ok) { validPos = false; posMsg << QStringLiteral("altitude: '%1'").arg(clientPartsMap["altitude"]); }
|
||||||
|
CCoordinateGeodetic position = validPos ? CCoordinateGeodetic(lat, lng, alt) : CCoordinateGeodetic::null();
|
||||||
|
|
||||||
|
Q_ASSERT_X((validPos && posMsg.isEmpty()) || (!validPos && !posMsg.isEmpty()), Q_FUNC_INFO, "Inconsisten data");
|
||||||
|
if (!posMsg.isEmpty())
|
||||||
|
{
|
||||||
|
CLogMessage(this).validationWarning(u"Callsign '%1' %2") << callsign << posMsg.join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
const CFrequency frequency = CFrequency(clientPartsMap["frequency"].toDouble(), CFrequencyUnit::MHz());
|
const CFrequency frequency = CFrequency(clientPartsMap["frequency"].toDouble(), CFrequencyUnit::MHz());
|
||||||
CCoordinateGeodetic position(lat, lng, alt);
|
|
||||||
const CAltitude altitude(alt, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
|
||||||
const QString flightPlanRemarks = clientPartsMap["planned_remarks"].trimmed();
|
const QString flightPlanRemarks = clientPartsMap["planned_remarks"].trimmed();
|
||||||
|
|
||||||
// Voice capabilities
|
// Voice capabilities
|
||||||
@@ -326,7 +341,8 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
// ATC section
|
// ATC section
|
||||||
CLength range;
|
CLength range;
|
||||||
position.setGeodeticHeight(altitude); // the altitude is elevation for a station
|
// should be alread have alt/height position.setGeodeticHeight(altitude);
|
||||||
|
// the altitude is elevation for a station
|
||||||
CAtcStation station(user.getCallsign().getStringAsSet(), user, frequency, position, range);
|
CAtcStation station(user.getCallsign().getStringAsSet(), user, frequency, position, range);
|
||||||
station.setOnline(true);
|
station.setOnline(true);
|
||||||
atcStations.push_back(station);
|
atcStations.push_back(station);
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ namespace BlackMisc
|
|||||||
return CCoordinateGeodetic(lat, lon, geodeticHeight);
|
return CCoordinateGeodetic(lat, lon, geodeticHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CCoordinateGeodetic &CCoordinateGeodetic::null()
|
||||||
|
{
|
||||||
|
static const CCoordinateGeodetic n;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
CLength calculateGreatCircleDistance(const ICoordinateGeodetic &coordinate1, const ICoordinateGeodetic &coordinate2)
|
CLength calculateGreatCircleDistance(const ICoordinateGeodetic &coordinate1, const ICoordinateGeodetic &coordinate2)
|
||||||
{
|
{
|
||||||
if (coordinate1.isNull() || coordinate2.isNull()) { return CLength::null(); }
|
if (coordinate1.isNull() || coordinate2.isNull()) { return CLength::null(); }
|
||||||
@@ -177,10 +183,10 @@ namespace BlackMisc
|
|||||||
const CLatitude lat = this->latitude();
|
const CLatitude lat = this->latitude();
|
||||||
const CLongitude lng = this->longitude();
|
const CLongitude lng = this->longitude();
|
||||||
return QStringLiteral("Geodetic: {%1/%2, %3/%4, %5}").arg(lat.valueRoundedWithUnit(CAngleUnit::deg(), 6, i18n),
|
return QStringLiteral("Geodetic: {%1/%2, %3/%4, %5}").arg(lat.valueRoundedWithUnit(CAngleUnit::deg(), 6, i18n),
|
||||||
lat.valueRoundedWithUnit(CAngleUnit::rad(), 6, i18n),
|
lat.valueRoundedWithUnit(CAngleUnit::rad(), 6, i18n),
|
||||||
lng.valueRoundedWithUnit(CAngleUnit::deg(), 6, i18n),
|
lng.valueRoundedWithUnit(CAngleUnit::deg(), 6, i18n),
|
||||||
lng.valueRoundedWithUnit(CAngleUnit::rad(), 6, i18n),
|
lng.valueRoundedWithUnit(CAngleUnit::rad(), 6, i18n),
|
||||||
this->geodeticHeight().valueRoundedWithUnit(CLengthUnit::ft(), 2, i18n));
|
this->geodeticHeight().valueRoundedWithUnit(CLengthUnit::ft(), 2, i18n));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ICoordinateGeodetic::isNaNVector() const
|
bool ICoordinateGeodetic::isNaNVector() const
|
||||||
|
|||||||
@@ -314,6 +314,9 @@ namespace BlackMisc
|
|||||||
//! Coordinate by WGS84 position data
|
//! Coordinate by WGS84 position data
|
||||||
static CCoordinateGeodetic fromWgs84(const QString &latitudeWgs84, const QString &longitudeWgs84, const Aviation::CAltitude &geodeticHeight = {});
|
static CCoordinateGeodetic fromWgs84(const QString &latitudeWgs84, const QString &longitudeWgs84, const Aviation::CAltitude &geodeticHeight = {});
|
||||||
|
|
||||||
|
//! null coordinate
|
||||||
|
static const CCoordinateGeodetic &null();
|
||||||
|
|
||||||
//! \copydoc Mixin::String::toQString
|
//! \copydoc Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
|
|||||||
@@ -251,9 +251,17 @@ namespace BlackMisc
|
|||||||
template <class MU, class PQ>
|
template <class MU, class PQ>
|
||||||
PQ &CPhysicalQuantity<MU, PQ>::switchUnit(const MU &newUnit)
|
PQ &CPhysicalQuantity<MU, PQ>::switchUnit(const MU &newUnit)
|
||||||
{
|
{
|
||||||
|
// NULL check: https://discordapp.com/channels/539048679160676382/539925070550794240/593151683698229258
|
||||||
if (m_unit == newUnit || this->isNull()) { return *derived(); }
|
if (m_unit == newUnit || this->isNull()) { return *derived(); }
|
||||||
m_value = newUnit.convertFrom(m_value, m_unit);
|
if (newUnit.isNull())
|
||||||
m_unit = newUnit;
|
{
|
||||||
|
this->setNull();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_value = newUnit.convertFrom(m_value, m_unit);
|
||||||
|
m_unit = newUnit;
|
||||||
|
}
|
||||||
return *derived();
|
return *derived();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user