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