Skip to content

Commit

Permalink
Complain about wrong credentials after 3 login attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBriza committed Oct 10, 2023
1 parent 27a8077 commit e0e0338
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/Lith/Core/lith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 20 additions & 7 deletions modules/Lith/Core/weechat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -218,6 +226,7 @@ QCoro::Task<void> Weechat::onHandshakeAccepted(StringMap data) {
}

m_initializationStatus = (Initialization) (m_initializationStatus | HANDSHAKE);
m_passwordAttempts++;

m_connection->write(QString("init"), QString(), hashString);
m_connection->write(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion modules/Lith/Core/weechat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -102,6 +104,7 @@ private slots:

qint64 m_messageOrder {0};
qint64 m_lastReceivedPong {0};
int m_passwordAttempts {0};

Lith* m_lith;
};
Expand Down

0 comments on commit e0e0338

Please sign in to comment.