diff options
author | daniel-Jones <daniel@danieljon.es> | 2017-06-22 20:44:08 +0930 |
---|---|---|
committer | daniel-Jones <daniel@danieljon.es> | 2017-06-22 20:44:08 +0930 |
commit | 9834782c287b1dc6df59a03e5992911d8fb70a83 (patch) | |
tree | f9a4da49aabd9b957fc5330e1e3fae952f79691e /qt/RGBController | |
parent | a34b9e649c6041bc69d522dfc3d7005b3c60e1b0 (diff) | |
download | RGB-Controller-9834782c287b1dc6df59a03e5992911d8fb70a83.tar.gz RGB-Controller-9834782c287b1dc6df59a03e5992911d8fb70a83.zip |
So, uh, I fixed the IRC reconnect feature, it was completely broken.
Diffstat (limited to 'qt/RGBController')
-rw-r--r-- | qt/RGBController/irc.cpp | 25 | ||||
-rw-r--r-- | qt/RGBController/irc.h | 6 |
2 files changed, 18 insertions, 13 deletions
diff --git a/qt/RGBController/irc.cpp b/qt/RGBController/irc.cpp index 4365e19..3a2ac14 100644 --- a/qt/RGBController/irc.cpp +++ b/qt/RGBController/irc.cpp @@ -15,8 +15,8 @@ void irc::setup(QString srv, int p, QString c, QString n) /* setup socket, connect signal/slot */ socket = new QTcpSocket(this); connect(socket, SIGNAL(readyRead()), this, SLOT(read())); - contest = new QTimer(this); - connect(contest, SIGNAL(timeout()), this, SLOT(testcon())); + pingcheck = new QTimer(this); + connect(pingcheck, SIGNAL(timeout()), this, SLOT(pingcheckfunc())); /* connect */ con(); } @@ -26,6 +26,7 @@ void irc::read() QString line = socket->readLine(); if (line.contains("PING :")) { + pinged = true; QString sline = "PONG :" + line.split(":")[1]; socket->write(sline.toLatin1()); } @@ -43,19 +44,20 @@ void irc::read() void irc::con() { + pinged = false; socket->connectToHost(server, port); buf = "NICK " + name + "\r\n"; socket->write(buf.toUtf8()); buf = "USER " + name + " 8 * :" + name + "\r\n"; socket->write(buf.toUtf8()); - contest->start(60000); + pingcheck->start(60000); } void irc::discon() { socket->write("QUIT :elegant quit \r\n"); socket->close(); - contest->stop(); + pingcheck->stop(); } void irc::handle(QString str) @@ -80,7 +82,6 @@ void irc::handle(QString str) for (int x = 0; x < tmp.size(); x++) { emit sendcmd(tmp.at(x)); - } } else @@ -98,14 +99,18 @@ void irc::sendmsg(QString msg) socket->write(buf.toUtf8()); } -void irc::testcon() +void irc::pingcheckfunc() { - qDebug() << socket->state(); - if (socket->state() == QAbstractSocket::UnconnectedState) + if (pinged) { - qDebug() << "reconnect needed"; - discon(); + qDebug() << "reconnection not needed"; + pinged = false; + } + else + { + qDebug() << "reconnection needed"; name = name + "_"; + discon(); con(); } } diff --git a/qt/RGBController/irc.h b/qt/RGBController/irc.h index d6c88e6..733bebf 100644 --- a/qt/RGBController/irc.h +++ b/qt/RGBController/irc.h @@ -20,14 +20,14 @@ class irc : public QObject QString channel; QString name; QString buf; - int pingcount; - QTimer *contest; + bool pinged; + QTimer *pingcheck; private slots: void read(); void con(); void handle(QString str); - void testcon(); + void pingcheckfunc(); signals: void sendcmd(QString cmd); |