mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 15:22:09 +02:00
Better handling of challenge timer
This commit is contained in:
parent
61668d3480
commit
9d0cd83ca4
2 changed files with 24 additions and 26 deletions
|
@ -27,10 +27,23 @@
|
|||
#include "ClientTraitsHandler.h"
|
||||
#include "AvatarLogging.h"
|
||||
|
||||
MixerAvatar::~MixerAvatar() {
|
||||
if (_challengeTimeout) {
|
||||
_challengeTimeout->deleteLater();
|
||||
}
|
||||
MixerAvatar::MixerAvatar() {
|
||||
static constexpr int CHALLENGE_TIMEOUT_MS = 10 * 1000; // 10 s
|
||||
|
||||
_challengeTimer.setSingleShot(true);
|
||||
_challengeTimer.setInterval(CHALLENGE_TIMEOUT_MS);
|
||||
|
||||
_challengeTimer.callOnTimeout([this]() {
|
||||
if (_verifyState == challengeClient) {
|
||||
_pendingEvent = false;
|
||||
_verifyState = verificationFailed;
|
||||
_needsIdentityUpdate = true;
|
||||
qCDebug(avatars) << "Dynamic verification TIMED-OUT for " << getDisplayName() << getSessionUUID();
|
||||
} else {
|
||||
qCDebug(avatars) << "Ignoring timeout of avatar challenge";
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
const char* MixerAvatar::stateToName(VerifyState state) {
|
||||
|
@ -283,7 +296,6 @@ void MixerAvatar::processCertifyEvents() {
|
|||
}
|
||||
|
||||
case requestingOwner:
|
||||
case challengeClient:
|
||||
{ // Qt networking done on this thread:
|
||||
QCoreApplication::processEvents();
|
||||
break;
|
||||
|
@ -313,30 +325,15 @@ void MixerAvatar::sendOwnerChallenge() {
|
|||
nonceHash.addData(nonce);
|
||||
_challengeNonceHash = nonceHash.result();
|
||||
_pendingEvent = false;
|
||||
|
||||
static constexpr int CHALLENGE_TIMEOUT_MS = 10 * 1000; // 10 s
|
||||
if (_challengeTimeout) {
|
||||
_challengeTimeout->deleteLater();
|
||||
}
|
||||
_challengeTimeout = new QTimer();
|
||||
_challengeTimeout->setInterval(CHALLENGE_TIMEOUT_MS);
|
||||
_challengeTimeout->setSingleShot(true);
|
||||
_challengeTimeout->connect(_challengeTimeout, &QTimer::timeout, this, [this]() {
|
||||
if (_verifyState == challengeClient) {
|
||||
_pendingEvent = false;
|
||||
_verifyState = verificationFailed;
|
||||
_needsIdentityUpdate = true;
|
||||
qCDebug(avatars) << "Dynamic verification TIMED-OUT for " << getDisplayName() << getSessionUUID();
|
||||
} else {
|
||||
qCDebug(avatars) << "Ignoring timeout of avatar challenge";
|
||||
}
|
||||
});
|
||||
_challengeTimeout->start();
|
||||
|
||||
// QTimer::start is a set of overloaded functions.
|
||||
QMetaObject::invokeMethod(&_challengeTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
|
||||
}
|
||||
|
||||
void MixerAvatar::handleChallengeResponse(ReceivedMessage& response) {
|
||||
QByteArray avatarID;
|
||||
QMutexLocker certifyLocker(&_avatarCertifyLock);
|
||||
QMetaObject::invokeMethod(&_challengeTimer, &QTimer::stop);
|
||||
if (_verifyState == challengeClient) {
|
||||
QByteArray responseData = response.readAll();
|
||||
if (responseData.length() < 8) {
|
||||
|
|
|
@ -22,7 +22,8 @@ class ResourceRequest;
|
|||
class MixerAvatar : public AvatarData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
~MixerAvatar();
|
||||
MixerAvatar();
|
||||
|
||||
bool getNeedsHeroCheck() const { return _needsHeroCheck; }
|
||||
void setNeedsHeroCheck(bool needsHeroCheck = true) { _needsHeroCheck = needsHeroCheck; }
|
||||
|
||||
|
@ -57,7 +58,7 @@ private:
|
|||
QString _dynamicMarketResponse;
|
||||
QString _ownerPublicKey;
|
||||
QByteArray _challengeNonceHash;
|
||||
QTimer* _challengeTimeout { nullptr };
|
||||
QTimer _challengeTimer;
|
||||
bool _needsIdentityUpdate { false };
|
||||
|
||||
bool generateFSTHash();
|
||||
|
|
Loading…
Reference in a new issue