|
@@ -18,6 +18,7 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
|
|
|
*/
|
|
|
|
|
|
#include "SshClient.h"
|
|
|
+#include "App.h"
|
|
|
#include <QProcess>
|
|
|
#include <QRegExp>
|
|
|
#include <QDateTime>
|
|
@@ -25,10 +26,11 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
|
|
|
#include <QStringList>
|
|
|
#include <QDebug>
|
|
|
|
|
|
-SshClient::SshClient(QObject *parent) :
|
|
|
+SshClient::SshClient(App* app, QObject *parent) :
|
|
|
QObject(parent),
|
|
|
+ myApp(app),
|
|
|
myProcess(new QProcess(this)),
|
|
|
- myCommandRegex(new QRegExp("^([0-9]{4}-[0-9]{2}-[0-9]{2}\\s[0-9]{2}:[0-9]{2}:[0-9]{2}\\s\\+[0-9]{4}):\\s([A-Za-z]+):?\\s?(.*)$")),
|
|
|
+ myCommandRegex(new QRegExp("^([0-9]{4}-[0-9]{2}-[0-9]{2}\\s[0-9]{2}:[0-9]{2}:[0-9]{2})\\s(\\+[0-9]{4}):\\s(.+)$")),
|
|
|
myConnectedFlag(false),
|
|
|
myConnectionTimerID(0),
|
|
|
myPingTimerID(0),
|
|
@@ -63,10 +65,12 @@ void SshClient::read()
|
|
|
line = line.trimmed();
|
|
|
if(myCommandRegex->indexIn(line) != -1)
|
|
|
{
|
|
|
- QDateTime time = QDateTime::fromString(myCommandRegex->capturedTexts().at(1).section(' ', 0, 1), "yyyy-MM-dd HH:mm:ss");
|
|
|
+ QDateTime time = QDateTime::fromString(myCommandRegex->cap(1), "yyyy-MM-dd HH:mm:ss");
|
|
|
+ time = time.addSecs(-myCommandRegex->cap(2).toInt()/100*60*60);
|
|
|
+
|
|
|
parse(time,
|
|
|
- myCommandRegex->capturedTexts().at(2),
|
|
|
- myCommandRegex->capturedTexts().at(3)
|
|
|
+ myCommandRegex->cap(3).section(' ', 0, 0),
|
|
|
+ myCommandRegex->cap(3).section(' ', 1)
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -97,15 +101,13 @@ void SshClient::write(const QString &data)
|
|
|
|
|
|
void SshClient::parse(const QDateTime &time, const QString &command, const QString &commandData)
|
|
|
{
|
|
|
- QString cmdData = commandData.trimmed();
|
|
|
- if(cmdData.startsWith(": "))
|
|
|
- cmdData.remove(0, 2);
|
|
|
+ qDebug() << time << command << commandData;
|
|
|
|
|
|
/* JOINED - Another user has just joined central */
|
|
|
if(command == "JOINED")
|
|
|
{
|
|
|
QRegExp a("^User '([a-zA-Z]+)'.+$");
|
|
|
- if(a.indexIn(commandData) == -1)
|
|
|
+ if(a.indexIn(commandData) != -1)
|
|
|
{
|
|
|
if(!myClients->contains(a.capturedTexts().at(1)))
|
|
|
myClients->push_back(a.capturedTexts().at(1));
|
|
@@ -117,7 +119,7 @@ void SshClient::parse(const QDateTime &time, const QString &command, const QStri
|
|
|
if(command == "PARTED")
|
|
|
{
|
|
|
QRegExp a("^User '([a-zA-Z]+)'.+$");
|
|
|
- if(a.indexIn(commandData) == -1)
|
|
|
+ if(a.indexIn(commandData) != -1)
|
|
|
myClients->removeAll(a.capturedTexts().at(1));
|
|
|
return;
|
|
|
}
|
|
@@ -153,13 +155,13 @@ void SshClient::parse(const QDateTime &time, const QString &command, const QStri
|
|
|
if(a.indexIn(commandData) == -1)
|
|
|
return;
|
|
|
|
|
|
+ int serverCount, userCount;
|
|
|
+
|
|
|
+ myApp->broadcast(a.cap(3) + " " + a.cap(5) + " - " + a.cap(4) + " : " + a.cap(6), &serverCount, &userCount);
|
|
|
+ write("BC_RE " + a.cap(1) + " " + QString::number(userCount) + "," + QString::number(serverCount) + "\n");
|
|
|
|
|
|
- qDebug() << "Broadcast Request" << commandData;
|
|
|
-// BC 0x0hash hash QDEV,-dev-,qw://123.123,'testuser','test, with '',``twists''$ hehe'
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- qDebug() << time << command << cmdData;
|
|
|
}
|
|
|
|
|
|
bool SshClient::connectToHost(const QString &user, const QString &host)
|