Change CAfvMapReader url to public AFV API

The previous one was a private API and got removed.
This commit is contained in:
Roland Rossgotterer
2019-10-28 15:44:47 +01:00
committed by Mat Sutcliffe
parent 6e5638d15e
commit a32e38b6a8

View File

@@ -1,12 +1,14 @@
#include "afvmapreader.h" #include "afvmapreader.h"
#include "blackcore/application.h" #include "blackcore/application.h"
#include "blackcore/afv/dto.h" #include "blackcore/afv/dto.h"
#include "blackmisc/aviation/callsign.h"
#include <QEventLoop> #include <QEventLoop>
#include <QNetworkReply> #include <QNetworkReply>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
using namespace BlackMisc::Aviation;
namespace BlackCore namespace BlackCore
{ {
@@ -28,7 +30,7 @@ namespace BlackCore
QEventLoop loop; QEventLoop loop;
connect(sApp->getNetworkAccessManager(), &QNetworkAccessManager::finished, &loop, &QEventLoop::quit); connect(sApp->getNetworkAccessManager(), &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
QNetworkReply *reply = sApp->getNetworkAccessManager()->get(QNetworkRequest(QUrl("https://afv-map.vatsim.net/atis-map-data"))); QNetworkReply *reply = sApp->getNetworkAccessManager()->get(QNetworkRequest(QUrl("https://voice1.vatsim.uk/api/v1/network/online/callsigns")));
while (! reply->isFinished()) { loop.exec(); } while (! reply->isFinished()) { loop.exec(); }
QByteArray jsonData = reply->readAll(); QByteArray jsonData = reply->readAll();
reply->deleteLater(); reply->deleteLater();
@@ -36,50 +38,32 @@ namespace BlackCore
if (jsonData.isEmpty()) { return; } if (jsonData.isEmpty()) { return; }
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData); QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isObject()) if (jsonDoc.isArray())
{ {
const QJsonObject rootObject = jsonDoc.object(); const QJsonArray rootArray = jsonDoc.array();
QVector<CSampleAtcStation> transceivers; QVector<CSampleAtcStation> transceivers;
QString callsign;
if (rootObject.contains("controllers")) for (auto it = rootArray.begin(); it != rootArray.end(); ++it)
{ {
const QJsonObject otherObject = rootObject.value("controllers").toObject(); if (it->isObject())
for (auto it = otherObject.begin(); it != otherObject.end(); ++it)
{ {
const QString callsign = it.key(); const QJsonObject stationObject = it->toObject();
if (it.value().isObject())
if (stationObject.contains("callsign"))
{ {
const QJsonObject stationObject = it.value().toObject(); callsign = stationObject.value("callsign").toString();
if (stationObject.contains("transceivers"))
{
QJsonArray txArray = stationObject.value("transceivers").toArray();
for (auto jt = txArray.begin(); jt != txArray.end(); ++jt)
{
const TransceiverDto transceiver = TransceiverDto::fromJson(jt->toObject());
transceivers.push_back({ callsign, transceiver});
}
}
} }
}
}
if (rootObject.contains("other") && rootObject.value("other").isObject()) if (callsign.isEmpty() || !CCallsign::looksLikeAtcCallsign(callsign)) { continue; }
{
const QJsonObject otherObject = rootObject.value("other").toObject(); if (stationObject.contains("transceivers"))
for (auto it = otherObject.begin(); it != otherObject.end(); ++it)
{
const QString callsign = it.key();
if (it.value().isObject())
{ {
QJsonObject stationObject = it.value().toObject(); QJsonArray txArray = stationObject.value("transceivers").toArray();
if (stationObject.contains("transceivers")) for (auto jt = txArray.begin(); jt != txArray.end(); ++jt)
{ {
const QJsonArray txArray = stationObject.value("transceivers").toArray(); const TransceiverDto transceiver = TransceiverDto::fromJson(jt->toObject());
for (auto jt = txArray.begin(); jt != txArray.end(); ++jt) transceivers.push_back({ callsign, transceiver});
{
const TransceiverDto transceiver = TransceiverDto::fromJson(jt->toObject());
transceivers.push_back({ callsign, transceiver});
}
} }
} }
} }