mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
[AFV] Add client version to API auth
This commit is contained in:
committed by
Klaus Basan
parent
f980fd02d5
commit
2362e25593
@@ -47,7 +47,8 @@ public:
|
||||
//! \copydoc BlackCore::Afv::Clients::CAfvClient::connectTo
|
||||
Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &callsign)
|
||||
{
|
||||
m_afvClient->connectTo(cid, password, callsign);
|
||||
const QString client = "swift " % BlackConfig::CBuildConfig::getShortVersionString();
|
||||
m_afvClient->connectTo(cid, password, callsign, client);
|
||||
}
|
||||
|
||||
//! \copydoc BlackCore::Afv::Clients::CAfvClient::disconnectFrom
|
||||
|
||||
@@ -167,6 +167,13 @@ namespace BlackConfig
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CBuildConfig::getShortVersionString()
|
||||
{
|
||||
static const QVersionNumber v { versionMajor(), versionMinor(), versionMicro() };
|
||||
static const QString s(v.toString());
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CBuildConfig::getVersionStringPlatform()
|
||||
{
|
||||
static const QString s = getPlatformString() % u' ' % getVersionString();
|
||||
|
||||
@@ -133,6 +133,9 @@ namespace BlackConfig
|
||||
//! Version as QVersionNumber
|
||||
static const QString &getVersionString();
|
||||
|
||||
//! Version as QVersionNumber
|
||||
static const QString &getShortVersionString();
|
||||
|
||||
//! Version as QVersionNumber plus platform info
|
||||
static const QString &getVersionStringPlatform();
|
||||
|
||||
|
||||
@@ -119,13 +119,13 @@ namespace BlackCore
|
||||
m_connectedWithContext = true;
|
||||
}
|
||||
|
||||
void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign)
|
||||
void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign, const QString &client)
|
||||
{
|
||||
if (QThread::currentThread() != thread())
|
||||
{
|
||||
// Method needs to be executed in the object thread since it will create new QObject children
|
||||
QPointer<CAfvClient> myself(this);
|
||||
QMetaObject::invokeMethod(this, [ = ]() { if (myself) { connectTo(cid, password, callsign); }});
|
||||
QMetaObject::invokeMethod(this, [ = ]() { if (myself) { connectTo(cid, password, callsign, client); }});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace BlackCore
|
||||
QMutexLocker lock(&m_mutexConnection);
|
||||
|
||||
// async connection
|
||||
m_connection->connectTo(cid, password, callsign, { this, [ = ](bool authenticated)
|
||||
m_connection->connectTo(cid, password, callsign, client, { this, [ = ](bool authenticated)
|
||||
{
|
||||
// this is the callback when the connection has been established
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace BlackCore
|
||||
//! Connect to network
|
||||
//! \threadsafe
|
||||
//! \remark runs in thread of CAfvClient object and is ASYNC when called from another thread
|
||||
Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &getCallsign);
|
||||
Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &getCallsign, const QString &client);
|
||||
|
||||
//! Disconnect from network
|
||||
//! \threadsafe
|
||||
|
||||
@@ -43,13 +43,14 @@ namespace BlackCore
|
||||
CLogMessage(this).debug(u"ApiServerConnection instantiated");
|
||||
}
|
||||
|
||||
void CApiServerConnection::connectTo(const QString &username, const QString &password, const QUuid &networkVersion, ConnectionCallback callback)
|
||||
void CApiServerConnection::connectTo(const QString &username, const QString &password, const QString &client, const QUuid &networkVersion, ConnectionCallback callback)
|
||||
{
|
||||
if (isShuttingDown()) { return; }
|
||||
|
||||
m_username = username;
|
||||
m_password = password;
|
||||
m_networkVersion = networkVersion;
|
||||
m_client = client;
|
||||
m_isAuthenticated = false;
|
||||
|
||||
QUrl url(m_addressUrl);
|
||||
@@ -60,6 +61,7 @@ namespace BlackCore
|
||||
{"username", username},
|
||||
{"password", password},
|
||||
{"networkversion", networkVersion.toString()},
|
||||
{"client", client}
|
||||
};
|
||||
|
||||
QNetworkRequest request(url);
|
||||
@@ -295,7 +297,7 @@ namespace BlackCore
|
||||
{
|
||||
if (QDateTime::currentDateTimeUtc() > m_expiryLocalUtc.addSecs(-5 * 60))
|
||||
{
|
||||
this->connectTo(m_username, m_password, m_networkVersion, { this, [ = ](bool) {}});
|
||||
this->connectTo(m_username, m_password, m_client, m_networkVersion, { this, [ = ](bool) {}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace BlackCore
|
||||
|
||||
//! Connect to network
|
||||
//! \remark ASYNC, calling callback when done
|
||||
void connectTo(const QString &username, const QString &password, const QUuid &networkVersion, ConnectionCallback callback);
|
||||
void connectTo(const QString &username, const QString &password, const QString &client, const QUuid &networkVersion, ConnectionCallback callback);
|
||||
|
||||
//! Add callsign to network
|
||||
PostCallsignResponseDto addCallsign(const QString &callsign);
|
||||
@@ -172,6 +172,7 @@ namespace BlackCore
|
||||
QString m_username;
|
||||
QString m_password;
|
||||
QUuid m_networkVersion;
|
||||
QString m_client;
|
||||
QDateTime m_expiryLocalUtc;
|
||||
qint64 m_serverToUserOffsetMs;
|
||||
bool m_isAuthenticated = false;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace BlackCore
|
||||
connect(m_udpSocket, qOverload<QAbstractSocket::SocketError>(&QUdpSocket::error), this, &CClientConnection::handleSocketError);
|
||||
}
|
||||
|
||||
void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign, ConnectionCallback callback)
|
||||
void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign, const QString &client, ConnectionCallback callback)
|
||||
{
|
||||
if (m_connection.isConnected())
|
||||
{
|
||||
@@ -49,7 +49,7 @@ namespace BlackCore
|
||||
m_connection.setCallsign(callsign);
|
||||
|
||||
QPointer<CClientConnection> myself(this);
|
||||
m_apiServerConnection->connectTo(userName, password, m_networkVersion,
|
||||
m_apiServerConnection->connectTo(userName, password, client, m_networkVersion,
|
||||
{
|
||||
// callback called when connected
|
||||
this, [ = ](bool authenticated)
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace BlackCore
|
||||
|
||||
//! Connect
|
||||
//! \remark ASYNC, calling callback when done
|
||||
void connectTo(const QString &userName, const QString &password, const QString &callsign, ConnectionCallback callback);
|
||||
void connectTo(const QString &userName, const QString &password, const QString &callsign, const QString &client, ConnectionCallback callback);
|
||||
|
||||
//! Disconnect
|
||||
void disconnectFrom(const QString &reason = {});
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
@@ -399,7 +400,8 @@ namespace BlackCore
|
||||
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
|
||||
|
||||
const CUser connectedUser = this->getIContextNetwork()->getConnectedServer().getUser();
|
||||
m_voiceClient->connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString());
|
||||
const QString client = "swift " % BlackConfig::CBuildConfig::getShortVersionString();
|
||||
m_voiceClient->connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString(), client);
|
||||
}
|
||||
else if (to.isDisconnected())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user