mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
feat: Migrate to new VATSIM Status JSON file
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
"url": "http://metar.vatsim.net/metar.php"
|
||||
},
|
||||
"vatsimStatusFileUrl": {
|
||||
"url": "https://status.vatsim.net"
|
||||
"url": "https://status.vatsim.net/status.json"
|
||||
},
|
||||
"comNavEquipmentHelpUrl": {
|
||||
"url": "https://en.wikipedia.org/wiki/Equipment_codes#Radio_communication,_navigation_and_approach_aid_equipment_and_capabilities"
|
||||
|
||||
@@ -86,56 +86,33 @@ namespace BlackCore::Vatsim
|
||||
|
||||
if (nwReply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
const QString dataFileData = nwReply->readAll();
|
||||
const QString statusFileData = nwReply->readAll();
|
||||
nwReply->close(); // close asap
|
||||
|
||||
if (dataFileData.isEmpty()) return;
|
||||
const QList<QStringRef> lines = splitLinesRefs(dataFileData);
|
||||
if (lines.isEmpty()) { return; }
|
||||
if (statusFileData.isEmpty()) return;
|
||||
auto jsonDoc = QJsonDocument::fromJson(statusFileData.toUtf8());
|
||||
if (jsonDoc.isEmpty()) { return; }
|
||||
|
||||
CUrl dataFileUrl;
|
||||
CUrl serverFileUrl;
|
||||
CUrl metarFileUrl;
|
||||
|
||||
QString currentLine; // declared outside of the for loop, to amortize the cost of allocation
|
||||
for (const QStringRef &clRef : lines)
|
||||
// Always taking the first URL from the file
|
||||
// (at the time of writing, also only one URL per service is available anyway)
|
||||
if (const QJsonArray dataUrls = jsonDoc["data"]["v3"].toArray(); !dataUrls.empty())
|
||||
{
|
||||
if (!this->doWorkCheck())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info(u"Terminated status parsing process"); // for users
|
||||
return; // stop, terminate straight away, ending thread
|
||||
}
|
||||
dataFileUrl = QUrl(dataUrls.at(0).toString());
|
||||
}
|
||||
|
||||
// parse lines
|
||||
currentLine = clRef.toString().trimmed();
|
||||
if (currentLine.isEmpty()) { continue; }
|
||||
if (currentLine.startsWith(";")) { continue; }
|
||||
if (!currentLine.contains("=")) { continue; }
|
||||
if (const QJsonArray serverFileUrls = jsonDoc["data"]["servers"].toArray(); !serverFileUrls.empty())
|
||||
{
|
||||
serverFileUrl = QUrl(serverFileUrls.at(0).toString());
|
||||
}
|
||||
|
||||
const QStringList parts(currentLine.split('='));
|
||||
if (parts.length() != 2) { continue; }
|
||||
const QString key(parts[0].trimmed().toLower());
|
||||
const QString value(parts[1].trimmed());
|
||||
const CUrl url(value);
|
||||
// Always taking last in the file (at the time of writing, the status file also only contains a single URL for each type either)
|
||||
if (key.startsWith("json3"))
|
||||
{
|
||||
dataFileUrl = url;
|
||||
}
|
||||
else if (key.startsWith("url1"))
|
||||
{
|
||||
serverFileUrl = url;
|
||||
}
|
||||
else if (key.startsWith("metar"))
|
||||
{
|
||||
metarFileUrl = url;
|
||||
}
|
||||
else if (key.startsWith("atis"))
|
||||
{
|
||||
// not yet used
|
||||
}
|
||||
} // for each line
|
||||
if (const QJsonArray metarUrls = jsonDoc["metar"].toArray(); !metarUrls.empty())
|
||||
{
|
||||
metarFileUrl = QUrl(metarUrls.at(0).toString());
|
||||
}
|
||||
|
||||
// cache itself is thread safe, avoid writing with unchanged data
|
||||
CVatsimSetup vs(m_lastGoodSetup.get());
|
||||
@@ -151,8 +128,8 @@ namespace BlackCore::Vatsim
|
||||
Q_UNUSED(changed);
|
||||
|
||||
// data read finished
|
||||
emit this->dataFileRead(lines.count());
|
||||
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFinished, lines.count());
|
||||
emit this->statusFileRead(statusFileData.count());
|
||||
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFinished, statusFileData.count());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -42,10 +42,10 @@ namespace BlackCore::Vatsim
|
||||
|
||||
signals:
|
||||
//! Data have been read
|
||||
void dataFileRead(int lines);
|
||||
void statusFileRead(int bytes);
|
||||
|
||||
//! Data have been read
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int bytes);
|
||||
|
||||
private:
|
||||
//! Read / re-read data file
|
||||
|
||||
@@ -1026,7 +1026,7 @@ namespace BlackCore
|
||||
if (readersNeeded.testFlag(CWebReaderFlags::VatsimStatusReader) || readersNeeded.testFlag(CWebReaderFlags::VatsimDataReader) || readersNeeded.testFlag(CWebReaderFlags::VatsimMetarReader))
|
||||
{
|
||||
m_vatsimStatusReader = new CVatsimStatusFileReader(this);
|
||||
c = connect(m_vatsimStatusReader, &CVatsimStatusFileReader::dataFileRead, this, &CWebDataServices::vatsimStatusFileRead, Qt::QueuedConnection);
|
||||
c = connect(m_vatsimStatusReader, &CVatsimStatusFileReader::statusFileRead, this, &CWebDataServices::vatsimStatusFileRead, Qt::QueuedConnection);
|
||||
CLogMessage(this).info(u"Trigger read of VATSIM status file");
|
||||
m_vatsimStatusReader->start(QThread::LowPriority);
|
||||
|
||||
@@ -1293,9 +1293,9 @@ namespace BlackCore
|
||||
CLogMessage(this).info(u"Read VATSIM data file, %1 kB") << kB;
|
||||
}
|
||||
|
||||
void CWebDataServices::vatsimStatusFileRead(int lines)
|
||||
void CWebDataServices::vatsimStatusFileRead(int bytes)
|
||||
{
|
||||
CLogMessage(this).info(u"Read VATSIM status file, %1 lines") << lines;
|
||||
CLogMessage(this).info(u"Read VATSIM status file, %1 bytes") << bytes;
|
||||
}
|
||||
|
||||
void CWebDataServices::vatsimServerFileRead(int bytes)
|
||||
|
||||
@@ -550,7 +550,7 @@ namespace BlackCore
|
||||
void vatsimDataFileRead(int kB);
|
||||
|
||||
//! VATSIM status file has been read
|
||||
void vatsimStatusFileRead(int lines);
|
||||
void vatsimStatusFileRead(int bytes);
|
||||
|
||||
//! VATSIM server file has been read
|
||||
void vatsimServerFileRead(int bytes);
|
||||
|
||||
Reference in New Issue
Block a user