6 #ifndef SWIFT_CORE_FSD_CLIENT_H
7 #define SWIFT_CORE_FSD_CLIENT_H
29 #include "misc/tokenbucket.h"
32 #ifdef SWIFT_VATSIM_SUPPORT
33 # include "vatsim/vatsimauth.h"
38 #include <QCommandLineOption>
42 #include <QReadWriteLock>
58 namespace SwiftFsdTest
62 namespace swift::core::fsd
105 m_clientName = clientName;
110 m_hostApplication = hostApplication;
115 m_versionMajor = major;
116 m_versionMinor = minor;
119 #ifdef SWIFT_VATSIM_SUPPORT
120 void setClientIdAndKey(quint16
id,
const QByteArray &key);
126 m_capabilities = capabilities;
138 m_partnerCallsign = callsign;
141 void setLiveryAndModelString(
const QString &livery,
bool sendLiveryString,
const QString &modelString,
142 bool sendModelString);
144 void setSimType(swift::misc::simulation::CSimulatorInfo::Simulator simulator);
148 m_pilotRating = rating;
153 m_atcRating = rating;
176 return m_ownCallsign;
184 return m_partnerCallsign;
200 return m_pilotRating;
205 void connectToServer();
206 void disconnectFromServer();
213 m_interimPositionReceivers.push_back(receiver);
217 m_interimPositionReceivers.remove(receiver);
252 return m_connectionStatus;
254 bool isConnected()
const {
return this->getConnectionStatus().isConnected(); }
255 bool isDisconnected()
const {
return this->getConnectionStatus().isDisconnected(); }
256 bool isPendingConnection()
const;
263 m_statistics = enabled;
270 void clearStatistics();
273 QString getNetworkStatisticsAsText(
bool reset,
const QString &separator =
"\n");
279 void gracefulShutdown();
299 swift::misc::network::CClient::Capabilities capabilities);
311 qint64 currentOffsetTimeMs,
const QString &model,
const QString &livery);
314 const QString &airlineIcaoDesignator,
const QString &aircraftDesignator,
348 void sendLogin(
const QString &token = {});
349 void sendDeletePilot();
350 void sendDeleteAtc();
351 void sendPilotDataUpdate();
352 void sendInterimPilotDataUpdate();
353 void sendVisualPilotDataUpdate(
bool slowUpdate =
false);
354 void sendAtcDataUpdate(
double latitude,
double longitude);
355 void sendPing(
const QString &receiver);
360 void sendTextMessage(
const QString &receiver,
const QString &message);
361 void sendPlaneInformation(
const QString &receiver,
const QString &aircraft,
const QString &airline = {},
364 void sendAircraftConfiguration(
const QString &receiver,
const QString &aircraftConfigJson);
366 void sendMessageString(
const QString &message);
367 void sendQueuedMessage();
372 int increaseStatisticsValue(
const QString &identifier,
const QString &appendix = {});
373 int increaseStatisticsValue(
const QString &identifier,
int value);
378 void sendQueuedMessage(
const T &message)
380 if (!message.isValid()) {
return; }
383 this->sendDirectMessage(message);
391 void sendDirectMessage(
const T &message)
393 if (!message.isValid()) {
return; }
399 void sendFsdMessage(
const QString &message);
400 void setUnitTestMode(
bool on) { m_unitTestMode = on; }
404 static const QString &defaultModelString()
406 static const QString dm(
"Cessna Skyhawk 172SP");
411 static const QString &noModelString()
413 static const QString noms(
"swift empty string");
429 void sendAuthChallenge(
const QString &challenge);
430 void sendAuthResponse(
const QString &response);
432 void sendClientResponse(ClientQueryType queryType,
const QString &receiver);
433 #ifdef SWIFT_VATSIM_SUPPORT
434 void sendClientIdentification(
const QString &fsdChallenge);
436 void sendIncrementalAircraftConfig();
438 void readDataFromSocket() { this->readDataFromSocketMaxLines(); }
439 void readDataFromSocketMaxLines(
int maxLines = -1);
440 void parseMessage(
const QString &lineRaw);
446 void initializeMessageTypes();
453 void handleAtcDataUpdate(
const QStringList &tokens);
454 #ifdef SWIFT_VATSIM_SUPPORT
455 void handleAuthChallenge(
const QStringList &tokens);
456 void handleAuthResponse(
const QStringList &tokens);
461 void handlePilotDataUpdate(
const QStringList &tokens);
463 void handleVisualPilotDataToggle(
const QStringList &tokens);
464 void handleEuroscopeSimData(
const QStringList &tokens);
470 void handleClientResponse(
const QStringList &tokens);
472 void handleCustomPilotPacket(
const QStringList &tokens);
473 #ifdef SWIFT_VATSIM_SUPPORT
474 void handleFsdIdentification(
const QStringList &tokens);
480 void handleUnknownPacket(
const QString &line);
481 void handleUnknownPacket(
const QStringList &tokens);
486 void handleSocketConnected();
495 void emitConsolidatedTextMessages();
499 qint64 markerTs = -1);
515 int maxLastValues = c_maxOffsetTimes)
const;
517 bool isInterimPositionSendingEnabledForServer()
const;
518 bool isInterimPositionReceivingEnabledForServer()
const;
519 bool isVisualPositionSendingEnabledForServer()
const;
528 void fsdMessageSettingsChanged();
531 void emitRawFsdMessage(
const QString &fsdMessage,
bool isSent);
534 bool saveNetworkStatistics(
const QString &server);
538 void startPositionTimers();
539 void stopPositionTimers();
543 void updateAtisMap(
const QString &callsign, AtisLineType type,
const QString &line);
546 void pendingTimeoutCheck();
562 void getVatsimAuthToken(
const QString &cid,
const QString &password,
568 #ifdef SWIFT_VATSIM_SUPPORT
569 vatsim_auth *m_clientAuth =
nullptr;
570 vatsim_auth *m_serverAuth =
nullptr;
572 QString m_lastServerAuthChallenge;
573 qint64 m_loginSince = -1;
574 static constexpr qint64 PendingConnectionTimeoutMs = 7500;
579 std::shared_ptr<QTcpSocket> m_socket =
580 std::make_shared<QTcpSocket>(
this);
581 void connectSocketSignals();
582 void initiateConnection(std::shared_ptr<QTcpSocket> rehostingSocket = {},
const QString &rehostingHost = {});
583 void resolveLoadBalancing(
const QString &host, std::function<
void(
const QString &)> callback);
584 bool m_rehosting =
false;
586 std::atomic_bool m_unitTestMode {
false };
587 std::atomic_bool m_printToConsole {
false };
596 misc::CDigestSignal m_dsSendTextMessage {
this, &CFSDClient::emitConsolidatedTextMessages,
597 std::chrono::milliseconds(250), 10 };
611 struct PendingAtisQuery
624 this, &CFSDClient::fsdMessageSettingsChanged
626 QFile m_rawFsdMessageLogFile;
627 std::atomic_bool m_rawFsdMessagesEnabled {
false };
628 std::atomic_bool m_filterPasswordFromLogin {
false };
631 QTimer m_scheduledConfigUpdate {
this };
632 QTimer m_positionUpdateTimer {
this };
633 QTimer m_interimPositionUpdateTimer {
this };
634 QTimer m_visualPositionUpdateTimer {
this };
635 QTimer m_fsdSendMessageTimer {
this };
637 qint64 m_additionalOffsetTime = 0;
639 std::atomic_bool m_statistics {
false };
649 SimType m_simType = SimType::Unknown;
651 AtcRating m_atcRating = AtcRating::Unknown;
657 int m_versionMajor = 0;
658 int m_versionMinor = 0;
659 int m_protocolRevision = 0;
660 ServerType m_serverType = ServerType::LegacyFsd;
668 m_ownAircraftIcaoCode;
670 m_ownAirlineIcaoCode;
673 std::atomic_bool m_sendLiveryString {
true };
674 std::atomic_bool m_sendModelString {
true };
679 QString getOwnCallsignAsString()
const
688 void handleIllegalFsdState(
const QString &message);
690 static int constexpr c_maxOffsetTimes = 6;
691 static int constexpr c_processingIntervalMsec = 100;
692 static int constexpr c_updatePositionIntervalMsec =
694 static int constexpr c_updateInterimPositionIntervalMsec =
696 static int constexpr c_updateVisualPositionIntervalMsec =
698 static int constexpr c_sendFsdMsgIntervalMsec = 10;
699 bool m_stoppedSendingVisualPositions =
false;
700 bool m_serverWantsVisualPositions =
false;
701 unsigned m_visualPositionUpdateSentCount = 0;
FSD client Todo: Send (interim) data updates automatically Todo Check ':' in FSD messages....
void customPilotPacketReceived(const QString &sender, const QStringList &data)
Client responses received.
swift::misc::aviation::CCallsign getPresetPartnerCallsign() const
Partner callsign if any.
void planeInformationReceived(const QString &sender, const QString &aircraft, const QString &airline, const QString &livery)
Client responses received.
void flightPlanReceived(const swift::misc::aviation::CCallsign &callsign, const swift::misc::aviation::CFlightPlan &flightPlan)
Client responses received.
void rawFsdMessage(const swift::misc::network::CRawFsdMessage &rawFsdMessage)
Client responses received.
void textMessagesReceived(const swift::misc::network::CTextMessageList &messages)
Client responses received.
bool isConnected() const
Connection status.
void muteRequestReceived(bool mute)
Client responses received.
void atcDataUpdateReceived(const swift::misc::aviation::CCallsign &callsign, const swift::misc::physical_quantities::CFrequency &freq, const swift::misc::geo::CCoordinateGeodetic &pos, const swift::misc::physical_quantities::CLength &range)
Client responses received.
void setAtcRating(AtcRating rating)
Preset functions.
swift::misc::aviation::CCallsign getPresetCallsign() const
Callsign if any.
bool isStatisticsEnabled() const
Statistics enable functions.
void realNameResponseReceived(const QString &sender, const QString &realName)
Client responses received.
void setLoginMode(const swift::misc::network::CLoginMode &mode)
Preset functions.
void connectionStatusChanged(swift::misc::network::CConnectionStatus oldStatus, swift::misc::network::CConnectionStatus newStatus)
Connection status has been changed.
void setClientName(const QString &clientName)
Preset functions.
void interimPilotDataUpdatedReceived(const swift::misc::aviation::CAircraftSituation &situation)
Client responses received.
void planeInformationFsinnReceived(const swift::misc::aviation::CCallsign &callsign, const QString &airlineIcaoDesignator, const QString &aircraftDesignator, const QString &combinedAircraftType, const QString &modelString)
Client responses received.
void capabilityResponseReceived(const swift::misc::aviation::CCallsign &sender, swift::misc::network::CClient::Capabilities capabilities)
Client responses received.
void setClientCapabilities(Capabilities capabilities)
Preset functions.
void setPartnerCallsign(const swift::misc::aviation::CCallsign &callsign)
Preset functions.
void pongReceived(const QString &sender, double elapsedTimeMs)
Client responses received.
const swift::misc::network::CServer & getServer() const
Get the server.
swift::misc::network::CLoginMode getLoginMode() const
Mode.
void printToConsole(bool on)
Debugging and UNIT tests.
void validAtcResponseReceived(const QString &callsign, bool isValidAtc)
Client responses received.
bool setStatisticsEnable(bool enabled)
Statistics enable functions.
void atisReplyReceived(const swift::misc::aviation::CCallsign &callsign, const swift::misc::aviation::CInformationMessage &atis)
We received a reply to one of our ATIS queries.
void visualPilotDataUpdateReceived(const swift::misc::aviation::CAircraftSituation &situation)
Client responses received.
void deleteAtcReceived(const QString &cid)
Client responses received.
PilotRating getPilotRating() const
Rating.
void addInterimPositionReceiver(const swift::misc::aviation::CCallsign &receiver)
Interim positions.
void com1FrequencyResponseReceived(const QString &sender, const swift::misc::physical_quantities::CFrequency &frequency)
Client responses received.
void setHostApplication(const QString &hostApplication)
Preset functions.
void setPilotRating(PilotRating rating)
Preset functions.
void removeInterimPositionReceiver(const swift::misc::aviation::CCallsign &receiver)
Interim positions.
void aircraftConfigReceived(const QString &sender, const QJsonObject &config, qint64 currentOffsetTimeMs)
Client responses received.
void pilotDataUpdateReceived(const swift::misc::aviation::CAircraftSituation &situation, const swift::misc::aviation::CTransponder &transponder)
Client responses received.
void textMessageSent(const swift::misc::network::CTextMessage &sentMessage)
We have sent a text message.
void atisLogoffTimeReplyReceived(const swift::misc::aviation::CCallsign &callsign, const QString &zuluTime)
We received a reply to one of our ATIS queries, containing the controller's planned logoff time.
void killRequestReceived(const QString &reason)
Kill request (aka kicked)
void setVersion(int major, int minor)
Preset functions.
void deletePilotReceived(const QString &cid)
Client responses received.
swift::misc::network::CConnectionStatus getConnectionStatus() const
Connection status.
void euroscopeSimDataUpdatedReceived(const swift::misc::aviation::CAircraftSituation &situation, const swift::misc::aviation::CAircraftParts &parts, qint64 currentOffsetTimeMs, const QString &model, const QString &livery)
Client responses received.
bool isDisconnected() const
Connection status.
void serverResponseReceived(const QString &sender, const QString &hostName)
Client responses received.
void severeNetworkError(const QString &errorMessage)
Network error.
Base class for a long-lived worker object which lives in its own thread.
Callable wrapper for a member function with function signature F.
Value object for ICAO classification.
Value object encapsulating information of aircraft's parts.
Value object encapsulating information of an aircraft's situation.
Value object for ICAO classification.
Value object for a list of ATC stations.
Value object encapsulating information of a callsign.
const QString & asString() const
Get callsign (normalized)
Value object for a set of callsigns.
Value object for a flight plan.
FlightRules
Flight rules (VFR or IFR)
Class which can be directly used to access an.
Value object encapsulating information about a connection status.
Value object for a FSD setup.
Value object encapsulating information about login mode.
Value object for a raw FSD message.
Value object encapsulating information of a server.
Value object encapsulating information of a text message.
Value object encapsulating a list of text messages.
Direct in memory access to client (network client) data.
Direct threadsafe in memory access to current ecosystem.
Physical unit length (length)
Delegating class which can be directly used to access an.
Class which can be directly used to access an.
Comprehensive information of an aircraft.
Class which can be directly used to access an.
Simple hardcoded info about the corresponding simulator.
Direct threadsafe in memory access to own aircraft.
Direct thread safe in memory access to remote aircraft.
ServerType
FSD Server type.
SimType
Flight simulator type.
PilotRating
Pilot ratings.
ClientQueryType
Client query types.
Capabilities
Client capability flags */.
TextMessageGroups
Message groups.
constexpr int PROTOCOL_REVISION_VATSIM_AUTH
Protocol version.
constexpr int PROTOCOL_REVISION_VATSIM_VELOCITY
Protocol version.
constexpr int PROTOCOL_REVISION_CLASSIC
Protocol version.
constexpr int PROTOCOL_REVISION_VATSIM_ATC
Protocol version.
QString messageToFSDString(const T &message)
String which will be send.
QDateTime currentDateTimeUtc()
#define SWIFT_CORE_EXPORT
Export a class or function from the library.