mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:28:15 +08:00
refs #607, use cached FSD servers and voice servers. So in case read fails last good data could be used.
This commit is contained in:
committed by
Mathew Sutcliffe
parent
52f0756597
commit
06bcbe2a2f
@@ -46,9 +46,27 @@ namespace BlackCore
|
|||||||
//! VATSIM data file URLs
|
//! VATSIM data file URLs
|
||||||
const BlackMisc::Network::CUrlList &getDataFileUrls() const { return m_dataFileUrls; }
|
const BlackMisc::Network::CUrlList &getDataFileUrls() const { return m_dataFileUrls; }
|
||||||
|
|
||||||
|
//! Set VATSIM data file URLs
|
||||||
|
void setDataFileUrls(const BlackMisc::Network::CUrlList &urls) { m_dataFileUrls = urls; }
|
||||||
|
|
||||||
//! FSD test servers
|
//! FSD test servers
|
||||||
const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; }
|
const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; }
|
||||||
|
|
||||||
|
//! User for last login
|
||||||
|
const BlackMisc::Network::CUser &getLastLoginUser() const { return m_lastLoginUser; }
|
||||||
|
|
||||||
|
//! Set FSD servers
|
||||||
|
void setFsdServers(const BlackMisc::Network::CServerList &servers) { m_fsdServers = servers; }
|
||||||
|
|
||||||
|
//! Voice servers
|
||||||
|
const BlackMisc::Network::CServerList &getVoiceServers() const { return m_voiceServers; }
|
||||||
|
|
||||||
|
//! Set voice servers
|
||||||
|
void setVoiceServers(const BlackMisc::Network::CServerList &servers) { m_voiceServers = servers; }
|
||||||
|
|
||||||
|
//! User for last login
|
||||||
|
void setLastLoginUser(const BlackMisc::Network::CUser &user) { m_lastLoginUser = user; }
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
@@ -66,6 +84,8 @@ namespace BlackCore
|
|||||||
|
|
||||||
BlackMisc::Network::CUrlList m_dataFileUrls; //!< Overall VATSIM data file / merely for bootstrapping the first time
|
BlackMisc::Network::CUrlList m_dataFileUrls; //!< Overall VATSIM data file / merely for bootstrapping the first time
|
||||||
BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers
|
BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers
|
||||||
|
BlackMisc::Network::CServerList m_voiceServers; //!< voice servers
|
||||||
|
BlackMisc::Network::CUser m_lastLoginUser; //!< last login user
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Trait for global setup data
|
//! Trait for global setup data
|
||||||
@@ -89,6 +109,7 @@ Q_DECLARE_METATYPE(BlackCore::Data::CVatsimSetup)
|
|||||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CVatsimSetup, (
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CVatsimSetup, (
|
||||||
attr(o.m_dataFileUrls),
|
attr(o.m_dataFileUrls),
|
||||||
attr(o.m_fsdServers),
|
attr(o.m_fsdServers),
|
||||||
|
attr(o.m_voiceServers),
|
||||||
attr(o.m_timestampMSecsSinceEpoch)
|
attr(o.m_timestampMSecsSinceEpoch)
|
||||||
))
|
))
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "blackcore/vatsimdatafilereader.h"
|
#include "blackcore/vatsimdatafilereader.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
#include "blackmisc/sequence.h"
|
#include "blackmisc/sequence.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
#include "blackmisc/aviation/atcstation.h"
|
#include "blackmisc/aviation/atcstation.h"
|
||||||
#include "blackmisc/network/user.h"
|
#include "blackmisc/network/user.h"
|
||||||
#include "blackmisc/network/server.h"
|
#include "blackmisc/network/server.h"
|
||||||
@@ -59,14 +60,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
CServerList CVatsimDataFileReader::getVoiceServers() const
|
CServerList CVatsimDataFileReader::getVoiceServers() const
|
||||||
{
|
{
|
||||||
QReadLocker rl(&this->m_lock);
|
return this->m_lastGoodSetup.getCopy().getVoiceServers();
|
||||||
return this->m_voiceServers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CServerList CVatsimDataFileReader::getFsdServers() const
|
CServerList CVatsimDataFileReader::getFsdServers() const
|
||||||
{
|
{
|
||||||
QReadLocker rl(&this->m_lock);
|
return this->m_lastGoodSetup.getCopy().getFsdServers();
|
||||||
return this->m_fsdServers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUserList CVatsimDataFileReader::getPilotsForCallsigns(const CCallsignSet &callsigns)
|
CUserList CVatsimDataFileReader::getPilotsForCallsigns(const CCallsignSet &callsigns)
|
||||||
@@ -188,16 +187,16 @@ namespace BlackCore
|
|||||||
nwReply->close(); // close asap
|
nwReply->close(); // close asap
|
||||||
|
|
||||||
if (dataFileData.isEmpty()) return;
|
if (dataFileData.isEmpty()) return;
|
||||||
QStringList lines = dataFileData.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
|
const QStringList lines = dataFileData.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
|
||||||
if (lines.isEmpty()) { return; }
|
if (lines.isEmpty()) { return; }
|
||||||
|
|
||||||
// build on local vars for thread safety
|
// build on local vars for thread safety
|
||||||
CServerList voiceServers;
|
CServerList voiceServers;
|
||||||
CServerList fsdServers;
|
CServerList fsdServers;
|
||||||
CAtcStationList atcStations;
|
CAtcStationList atcStations;
|
||||||
CSimulatedAircraftList aircraft;
|
CSimulatedAircraftList aircraft;
|
||||||
QMap<CCallsign, CVoiceCapabilities> voiceCapabilities;
|
QMap<CCallsign, CVoiceCapabilities> voiceCapabilities;
|
||||||
QDateTime updateTimestampFromFile;
|
QDateTime updateTimestampFromFile;
|
||||||
|
|
||||||
QStringList clientSectionAttributes;
|
QStringList clientSectionAttributes;
|
||||||
Section section = SectionNone;
|
Section section = SectionNone;
|
||||||
@@ -219,7 +218,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
// ; !CLIENTS section
|
// ; !CLIENTS section
|
||||||
int i = currentLine.lastIndexOf(' ');
|
int i = currentLine.lastIndexOf(' ');
|
||||||
QString attributes = currentLine.mid(i).trimmed();
|
const QString attributes = currentLine.mid(i).trimmed();
|
||||||
clientSectionAttributes = attributes.split(':', QString::SkipEmptyParts);
|
clientSectionAttributes = attributes.split(':', QString::SkipEmptyParts);
|
||||||
section = SectionNone; // reset
|
section = SectionNone; // reset
|
||||||
}
|
}
|
||||||
@@ -235,16 +234,16 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
case SectionClients:
|
case SectionClients:
|
||||||
{
|
{
|
||||||
QMap<QString, QString> clientPartsMap = clientPartsToMap(currentLine, clientSectionAttributes);
|
const QMap<QString, QString> clientPartsMap = clientPartsToMap(currentLine, clientSectionAttributes);
|
||||||
CCallsign callsign = CCallsign(clientPartsMap["callsign"]);
|
const CCallsign callsign = CCallsign(clientPartsMap["callsign"]);
|
||||||
if (callsign.isEmpty()) break;
|
if (callsign.isEmpty()) { break; }
|
||||||
BlackMisc::Network::CUser user(clientPartsMap["cid"], clientPartsMap["realname"], callsign);
|
const BlackMisc::Network::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
|
||||||
double lat = clientPartsMap["latitude"].toDouble();
|
const double lat = clientPartsMap["latitude"].toDouble();
|
||||||
double lng = clientPartsMap["longitude"].toDouble();
|
const double lng = clientPartsMap["longitude"].toDouble();
|
||||||
double alt = clientPartsMap["altitude"].toDouble();
|
const double alt = clientPartsMap["altitude"].toDouble();
|
||||||
CFrequency frequency = CFrequency(clientPartsMap["frequency"].toDouble(), CFrequencyUnit::MHz());
|
const CFrequency frequency = CFrequency(clientPartsMap["frequency"].toDouble(), CFrequencyUnit::MHz());
|
||||||
CCoordinateGeodetic position(lat, lng, -1);
|
CCoordinateGeodetic position(lat, lng, -1);
|
||||||
CAltitude altitude(alt, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
CAltitude altitude(alt, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
||||||
QString flightPlanRemarks = clientPartsMap["planned_remarks"];
|
QString flightPlanRemarks = clientPartsMap["planned_remarks"];
|
||||||
@@ -263,7 +262,7 @@ namespace BlackCore
|
|||||||
if (clientType.startsWith('p'))
|
if (clientType.startsWith('p'))
|
||||||
{
|
{
|
||||||
// Pilot section
|
// Pilot section
|
||||||
double groundspeed = clientPartsMap["groundspeed"].toDouble();
|
const double groundspeed = clientPartsMap["groundspeed"].toDouble();
|
||||||
CAircraftSituation situation(position, altitude);
|
CAircraftSituation situation(position, altitude);
|
||||||
situation.setGroundspeed(CSpeed(groundspeed, CSpeedUnit::kts()));
|
situation.setGroundspeed(CSpeed(groundspeed, CSpeedUnit::kts()));
|
||||||
CSimulatedAircraft currentAircraft(user.getCallsign().getStringAsSet(), user, situation);
|
CSimulatedAircraft currentAircraft(user.getCallsign().getStringAsSet(), user, situation);
|
||||||
@@ -298,7 +297,8 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong client type");
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "Wrong client type");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -306,9 +306,9 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (currentLine.contains("UPDATE"))
|
if (currentLine.contains("UPDATE"))
|
||||||
{
|
{
|
||||||
QStringList updateParts = currentLine.replace(" ", "").split('=');
|
const QStringList updateParts = currentLine.replace(" ", "").split('=');
|
||||||
if (updateParts.length() < 2) break;
|
if (updateParts.length() < 2) break;
|
||||||
QString dts = updateParts.at(1).trimmed();
|
const QString dts = updateParts.at(1).trimmed();
|
||||||
updateTimestampFromFile = QDateTime::fromString(dts, "yyyyMMddHHmmss");
|
updateTimestampFromFile = QDateTime::fromString(dts, "yyyyMMddHHmmss");
|
||||||
updateTimestampFromFile.setOffsetFromUtc(0);
|
updateTimestampFromFile.setOffsetFromUtc(0);
|
||||||
bool alreadyRead = (updateTimestampFromFile == this->getUpdateTimestamp());
|
bool alreadyRead = (updateTimestampFromFile == this->getUpdateTimestamp());
|
||||||
@@ -319,7 +319,7 @@ namespace BlackCore
|
|||||||
case SectionFsdServers:
|
case SectionFsdServers:
|
||||||
{
|
{
|
||||||
// ident:hostname_or_IP:location:name:clients_connection_allowed:
|
// ident:hostname_or_IP:location:name:clients_connection_allowed:
|
||||||
QStringList fsdServerParts = currentLine.split(':');
|
const QStringList fsdServerParts = currentLine.split(':');
|
||||||
if (fsdServerParts.size() < 5) break;
|
if (fsdServerParts.size() < 5) break;
|
||||||
if (!fsdServerParts.at(4).trimmed().contains('1')) break; // allowed?
|
if (!fsdServerParts.at(4).trimmed().contains('1')) break; // allowed?
|
||||||
QString description(fsdServerParts.at(2)); // part(3) could be added
|
QString description(fsdServerParts.at(2)); // part(3) could be added
|
||||||
@@ -330,7 +330,7 @@ namespace BlackCore
|
|||||||
case SectionVoiceServers:
|
case SectionVoiceServers:
|
||||||
{
|
{
|
||||||
// hostname_or_IP:location:name:clients_connection_allowed:type_of_voice_server:
|
// hostname_or_IP:location:name:clients_connection_allowed:type_of_voice_server:
|
||||||
QStringList voiceServerParts = currentLine.split(':');
|
const QStringList voiceServerParts = currentLine.split(':');
|
||||||
if (voiceServerParts.size() < 3) break;
|
if (voiceServerParts.size() < 3) break;
|
||||||
if (!voiceServerParts.at(3).trimmed().contains('1')) break; // allowed?
|
if (!voiceServerParts.at(3).trimmed().contains('1')) break; // allowed?
|
||||||
BlackMisc::Network::CServer voiceServer(voiceServerParts.at(1), voiceServerParts.at(2), voiceServerParts.at(0), -1, CUser());
|
BlackMisc::Network::CServer voiceServer(voiceServerParts.at(1), voiceServerParts.at(2), voiceServerParts.at(0), -1, CUser());
|
||||||
@@ -351,9 +351,12 @@ namespace BlackCore
|
|||||||
this->setUpdateTimestamp(updateTimestampFromFile);
|
this->setUpdateTimestamp(updateTimestampFromFile);
|
||||||
this->m_aircraft = aircraft;
|
this->m_aircraft = aircraft;
|
||||||
this->m_atcStations = atcStations;
|
this->m_atcStations = atcStations;
|
||||||
this->m_voiceServers = voiceServers;
|
|
||||||
this->m_fsdServers = fsdServers;
|
|
||||||
this->m_voiceCapabilities = voiceCapabilities;
|
this->m_voiceCapabilities = voiceCapabilities;
|
||||||
|
CVatsimSetup vs(this->m_lastGoodSetup.get());
|
||||||
|
vs.setVoiceServers(voiceServers);
|
||||||
|
vs.setFsdServers(fsdServers);
|
||||||
|
vs.setUtcTimestamp(updateTimestampFromFile);
|
||||||
|
this->m_lastGoodSetup.set(vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// warnings, if required
|
// warnings, if required
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#define BLACKCORE_VATSIMDATAFILEREADER_H
|
#define BLACKCORE_VATSIMDATAFILEREADER_H
|
||||||
|
|
||||||
#include "blackcoreexport.h"
|
#include "blackcoreexport.h"
|
||||||
#include "blackcore/data/globalsetup.h"
|
#include "blackcore/data/vatsimsetup.h"
|
||||||
#include "blackmisc/threadedreader.h"
|
#include "blackmisc/threadedreader.h"
|
||||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||||
#include "blackmisc/aviation/atcstationlist.h"
|
#include "blackmisc/aviation/atcstationlist.h"
|
||||||
@@ -123,10 +123,9 @@ namespace BlackCore
|
|||||||
void ps_read();
|
void ps_read();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlackMisc::Network::CServerList m_voiceServers;
|
BlackMisc::Aviation::CAtcStationList m_atcStations;
|
||||||
BlackMisc::Network::CServerList m_fsdServers;
|
BlackMisc::Simulation::CSimulatedAircraftList m_aircraft;
|
||||||
BlackMisc::Aviation::CAtcStationList m_atcStations;
|
BlackMisc::CData<BlackCore::Data::VatsimSetup> m_lastGoodSetup { this };
|
||||||
BlackMisc::Simulation::CSimulatedAircraftList m_aircraft;
|
|
||||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Network::CVoiceCapabilities> m_voiceCapabilities;
|
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Network::CVoiceCapabilities> m_voiceCapabilities;
|
||||||
|
|
||||||
//! Split line and assign values to their corresponding attribute names
|
//! Split line and assign values to their corresponding attribute names
|
||||||
|
|||||||
Reference in New Issue
Block a user