From e25c9d650eb7c7633fd1a768bff9cde013c7b057 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 16 Apr 2016 00:01:16 +0200 Subject: Rename file --- irc/botircdiceparser.cpp | 123 +++++++++++++++++++++++++++++++++++++++++++++++ irc/botircdiceparser.h | 36 ++++++++++++++ irc/mainwindow.cpp | 123 ----------------------------------------------- irc/mainwindow.h | 36 -------------- 4 files changed, 159 insertions(+), 159 deletions(-) create mode 100644 irc/botircdiceparser.cpp create mode 100644 irc/botircdiceparser.h delete mode 100644 irc/mainwindow.cpp delete mode 100644 irc/mainwindow.h diff --git a/irc/botircdiceparser.cpp b/irc/botircdiceparser.cpp new file mode 100644 index 0000000..39bac4e --- /dev/null +++ b/irc/botircdiceparser.cpp @@ -0,0 +1,123 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + // Create socket + m_socket = new QTcpSocket(this); + + m_parser = new DiceParser(); + + // Connect signals and slots! + connect(m_socket, SIGNAL(readyRead()), this, SLOT(readData())); + connect(m_socket,SIGNAL(connected()),this,SLOT(authentificationProcess())); + connect(m_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorOccurs(QAbstractSocket::SocketError))); + connect(ui->m_connectButton, SIGNAL(clicked()), this, SLOT(connectToServer())); + connect(ui->m_disconnectButton, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); + connect(ui->m_joinButton, SIGNAL(clicked()), this, SLOT(joinChannel())); + +} + +MainWindow::~MainWindow() +{ + delete ui; +} +void MainWindow::connectToServer() +{ + qDebug() << "start connection"; + m_socket->connectToHost(QString("irc.freenode.net"), 8001); +} +void MainWindow::errorOccurs(QAbstractSocket::SocketError) +{ + qDebug() << "ERROR" << m_socket->errorString(); +} + +void MainWindow::readData() +{ + + qDebug() << "Reply"; + QString readLine = m_socket->readLine(); + + if(readLine.startsWith("!")) + readLine = readLine.remove(0,1); + + + if(readLine.contains("!")) + { + + // qDebug()<< "in /dice"; + QString dice=".*PRIVMSG.*!(.*)"; + QRegExp exp(dice); + exp.indexIn(readLine); + + + + QStringList list = exp.capturedTexts(); + qDebug()<parseLine(cmd.simplified())) + { + m_parser->Start(); + QString result = m_parser->displayResult(); + QString msg("PRIVMSG #Rolisteam :%1 \r\n"); + m_socket->write(msg.arg(result).toLatin1()); + } + } + else + { + return; + } + + + } + else if(readLine.contains("PING :")) + { + QString dice="PING :(.*)"; + QRegExp exp(dice); + exp.indexIn(readLine); + QStringList list = exp.capturedTexts(); + if(list.size()==2) + { + QString resp = "PONG :"+list[1]; + + m_socket->write(resp.toLatin1()); + } + } + if(readLine.contains("Found your hostname")) + { + authentificationProcess(); + } + // Add to ouput + ui->m_output->append(readLine.trimmed()); + // Next data?? + if(m_socket->canReadLine()) readData(); +} + +void MainWindow::disconnectFromServer() +{ + // Disconnect from IRC server + m_socket->write("QUIT Good bye \r\n"); // Good bye is optional message + m_socket->flush(); + m_socket->disconnect(); // Now we can try it :-) +} + void MainWindow::authentificationProcess() + { + qDebug() << "authentification"; + m_socket->write("NICK rolisteamDice \r\n"); + m_socket->write("USER rolisteamDice rolisteamDice rolisteamDice :rolisteamDice BOT \r\n"); + m_socket->write("MSG NickServ identify \r\n"); + + } +void MainWindow::joinChannel() +{ + m_socket->write("JOIN #Rolisteam \r\n"); +} diff --git a/irc/botircdiceparser.h b/irc/botircdiceparser.h new file mode 100644 index 0000000..d7139d6 --- /dev/null +++ b/irc/botircdiceparser.h @@ -0,0 +1,36 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "diceparser.h" + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + virtual ~MainWindow(); + +public slots: + void errorOccurs(QAbstractSocket::SocketError); +private: + Ui::MainWindow *ui; + QTcpSocket * m_socket; + DiceParser* m_parser; + +private slots: + void readData(); + void connectToServer(); + void disconnectFromServer(); + void authentificationProcess(); + void joinChannel(); +}; + +#endif // MAINWINDOW_H diff --git a/irc/mainwindow.cpp b/irc/mainwindow.cpp deleted file mode 100644 index 39bac4e..0000000 --- a/irc/mainwindow.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -#include -#include - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - // Create socket - m_socket = new QTcpSocket(this); - - m_parser = new DiceParser(); - - // Connect signals and slots! - connect(m_socket, SIGNAL(readyRead()), this, SLOT(readData())); - connect(m_socket,SIGNAL(connected()),this,SLOT(authentificationProcess())); - connect(m_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorOccurs(QAbstractSocket::SocketError))); - connect(ui->m_connectButton, SIGNAL(clicked()), this, SLOT(connectToServer())); - connect(ui->m_disconnectButton, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); - connect(ui->m_joinButton, SIGNAL(clicked()), this, SLOT(joinChannel())); - -} - -MainWindow::~MainWindow() -{ - delete ui; -} -void MainWindow::connectToServer() -{ - qDebug() << "start connection"; - m_socket->connectToHost(QString("irc.freenode.net"), 8001); -} -void MainWindow::errorOccurs(QAbstractSocket::SocketError) -{ - qDebug() << "ERROR" << m_socket->errorString(); -} - -void MainWindow::readData() -{ - - qDebug() << "Reply"; - QString readLine = m_socket->readLine(); - - if(readLine.startsWith("!")) - readLine = readLine.remove(0,1); - - - if(readLine.contains("!")) - { - - // qDebug()<< "in /dice"; - QString dice=".*PRIVMSG.*!(.*)"; - QRegExp exp(dice); - exp.indexIn(readLine); - - - - QStringList list = exp.capturedTexts(); - qDebug()<parseLine(cmd.simplified())) - { - m_parser->Start(); - QString result = m_parser->displayResult(); - QString msg("PRIVMSG #Rolisteam :%1 \r\n"); - m_socket->write(msg.arg(result).toLatin1()); - } - } - else - { - return; - } - - - } - else if(readLine.contains("PING :")) - { - QString dice="PING :(.*)"; - QRegExp exp(dice); - exp.indexIn(readLine); - QStringList list = exp.capturedTexts(); - if(list.size()==2) - { - QString resp = "PONG :"+list[1]; - - m_socket->write(resp.toLatin1()); - } - } - if(readLine.contains("Found your hostname")) - { - authentificationProcess(); - } - // Add to ouput - ui->m_output->append(readLine.trimmed()); - // Next data?? - if(m_socket->canReadLine()) readData(); -} - -void MainWindow::disconnectFromServer() -{ - // Disconnect from IRC server - m_socket->write("QUIT Good bye \r\n"); // Good bye is optional message - m_socket->flush(); - m_socket->disconnect(); // Now we can try it :-) -} - void MainWindow::authentificationProcess() - { - qDebug() << "authentification"; - m_socket->write("NICK rolisteamDice \r\n"); - m_socket->write("USER rolisteamDice rolisteamDice rolisteamDice :rolisteamDice BOT \r\n"); - m_socket->write("MSG NickServ identify \r\n"); - - } -void MainWindow::joinChannel() -{ - m_socket->write("JOIN #Rolisteam \r\n"); -} diff --git a/irc/mainwindow.h b/irc/mainwindow.h deleted file mode 100644 index d7139d6..0000000 --- a/irc/mainwindow.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include "diceparser.h" - -#include - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - virtual ~MainWindow(); - -public slots: - void errorOccurs(QAbstractSocket::SocketError); -private: - Ui::MainWindow *ui; - QTcpSocket * m_socket; - DiceParser* m_parser; - -private slots: - void readData(); - void connectToServer(); - void disconnectFromServer(); - void authentificationProcess(); - void joinChannel(); -}; - -#endif // MAINWINDOW_H -- cgit v1.2.3-70-g09d2