diff --git a/modules/Lith/Core/lith.cpp b/modules/Lith/Core/lith.cpp index 67ac8dd..6bab145 100644 --- a/modules/Lith/Core/lith.cpp +++ b/modules/Lith/Core/lith.cpp @@ -288,7 +288,7 @@ void Lith::resetData() { void Lith::reconnect() { // Network code lives in a different thread // TODO use signals/slots to make it cleaner - QMetaObject::invokeMethod(m_weechat, "restart", Qt::QueuedConnection); + QMetaObject::invokeMethod(m_weechat, "userRequestedRestart", Qt::QueuedConnection); } void Lith::selectBufferNumber(int bufferNumber) { diff --git a/modules/Lith/Core/weechat.cpp b/modules/Lith/Core/weechat.cpp index 83eebb0..0c2f52c 100644 --- a/modules/Lith/Core/weechat.cpp +++ b/modules/Lith/Core/weechat.cpp @@ -134,6 +134,12 @@ void Weechat::start() { restart(); } +void Weechat::userRequestedRestart() { + m_passwordAttempts = 0; + m_reconnectTimer->setInterval(100); + restart(); +} + void Weechat::restart() { if (m_networkProxy->mode() == ReplayProxy::Replay) { return; @@ -160,6 +166,8 @@ void Weechat::restart() { } void Weechat::onConnectionSettingsChanged() { + m_passwordAttempts = 0; + bool hasPassphrase = Lith::settingsGet()->hasPassphraseGet(); #ifndef __EMSCRIPTEN__ bool usesWebsockets = Lith::settingsGet()->useWebsocketsGet(); @@ -218,6 +226,7 @@ QCoro::Task Weechat::onHandshakeAccepted(StringMap data) { } m_initializationStatus = (Initialization) (m_initializationStatus | HANDSHAKE); + m_passwordAttempts++; m_connection->write(QString("init"), QString(), hashString); m_connection->write( @@ -283,13 +292,16 @@ void Weechat::onDisconnected() { m_bytesRemaining = 0; m_hotlistTimer->stop(); - if (m_initializationStatus != COMPLETE && m_initializationStatus | HANDSHAKE) { - lith()->log(Logger::Protocol, QString("Authentication failed.")); - lith()->statusSet(Lith::ERROR); - lith()->errorStringSet(tr("Authentication failed with remote host. Please check your login credentials")); - m_initializationStatus = UNINITIALIZED; - m_reconnectTimer->stop(); - return; + if (m_initializationStatus == UNTIL_HANDSHAKE) { + lith()->log(Logger::Protocol, QStringLiteral("Authentication failed, attempt number %1.").arg(m_passwordAttempts)); + if (m_passwordAttempts == 3) { + lith()->statusSet(Lith::ERROR); + lith()->errorStringSet(tr("Authentication failed with remote host. Please check your login credentials")); + m_initializationStatus = UNINITIALIZED; + m_reconnectTimer->stop(); + m_passwordAttempts = 0; + return; + } } lith()->log(Logger::Protocol, QString("WeeChat connection lost, will reconnect in %1ms").arg(m_reconnectTimer->interval() * 2)); @@ -351,6 +363,7 @@ void Weechat::onMessageReceived(QByteArray& data) { lith()->log(Logger::Unexpected, QString("Possible unhandled message: %1").arg(id)); } if (m_initializationStatus & COMPLETE) { + m_passwordAttempts = 0; m_reconnectTimer->setInterval(100); } } else { diff --git a/modules/Lith/Core/weechat.h b/modules/Lith/Core/weechat.h index c57d675..97bbca4 100644 --- a/modules/Lith/Core/weechat.h +++ b/modules/Lith/Core/weechat.h @@ -56,13 +56,15 @@ class LITHCORE_EXPORT Weechat : public QObject { REQUEST_FIRST_LINE = 1 << 3, REQUEST_HOTLIST = 1 << 4, REQUEST_NICKLIST = 1 << 5, - COMPLETE = CONNECTION_OPENED | HANDSHAKE | REQUEST_BUFFERS | REQUEST_FIRST_LINE | REQUEST_HOTLIST | REQUEST_NICKLIST + COMPLETE = CONNECTION_OPENED | HANDSHAKE | REQUEST_BUFFERS | REQUEST_FIRST_LINE | REQUEST_HOTLIST | REQUEST_NICKLIST, + UNTIL_HANDSHAKE = CONNECTION_OPENED | HANDSHAKE, }; public slots: void init(); void start(); + void userRequestedRestart(); void restart(); bool input(pointer_t ptr, const QString& data); @@ -102,6 +104,7 @@ private slots: qint64 m_messageOrder {0}; qint64 m_lastReceivedPong {0}; + int m_passwordAttempts {0}; Lith* m_lith; };