aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--irc/irc.pri9
-rw-r--r--irc/mainwindow.cpp109
-rw-r--r--irc/mainwindow.h34
-rw-r--r--irc/mainwindow.ui75
4 files changed, 227 insertions, 0 deletions
diff --git a/irc/irc.pri b/irc/irc.pri
new file mode 100644
index 0000000..c987e1e
--- /dev/null
+++ b/irc/irc.pri
@@ -0,0 +1,9 @@
+QT += widgets gui network
+FORMS += \
+ irc/mainwindow.ui
+
+HEADERS += \
+ irc/mainwindow.h
+
+SOURCES += \
+ irc/mainwindow.cpp
diff --git a/irc/mainwindow.cpp b/irc/mainwindow.cpp
new file mode 100644
index 0000000..dede122
--- /dev/null
+++ b/irc/mainwindow.cpp
@@ -0,0 +1,109 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <math.h>
+#include <QDebug>
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+
+ // Create socket
+ socket = new QTcpSocket(this);
+
+ m_parser = new DiceParser();
+
+ // Connect signals and slots!
+ connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
+ connect(socket,SIGNAL(connected()),this,SLOT(authentificationProcess()));
+ 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()
+{
+ socket->connectToHost(QString("irc.epiknet.org"), 6667);
+}
+
+void MainWindow::readData()
+{
+ QString readLine = 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()<<list;
+ if(list.size()==2)
+ {
+ QString cmd = list[1];
+ if(m_parser->parseLine(cmd))
+ {
+ m_parser->Start();
+ QString result = m_parser->displayResult();
+ QString msg("PRIVMSG #opale-roliste :%1 \r\n");
+ 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];
+
+ socket->write(resp.toLatin1());
+ }
+ }
+ // Add to ouput
+ ui->m_output->append(readLine.trimmed());
+ // Next data??
+ if(socket->canReadLine()) readData();
+}
+
+void MainWindow::disconnectFromServer()
+{
+ // Disconnect from IRC server
+ socket->write("QUIT Good bye \r\n"); // Good bye is optional message
+ socket->flush();
+ socket->disconnect(); // Now we can try it :-)
+}
+ void MainWindow::authentificationProcess()
+ {
+ socket->write("NICK diceBot \r\n");
+ socket->write("USER diceBot diceBot diceBot :diceBot BOT \r\n");
+
+ }
+void MainWindow::joinChannel()
+{
+ socket->write("JOIN #opale-roliste \r\n");
+}
diff --git a/irc/mainwindow.h b/irc/mainwindow.h
new file mode 100644
index 0000000..9098e56
--- /dev/null
+++ b/irc/mainwindow.h
@@ -0,0 +1,34 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include "diceparser.h"
+
+#include <QTcpSocket>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+ QTcpSocket * socket;
+ DiceParser* m_parser;
+
+private slots:
+ void readData();
+ void connectToServer();
+ void disconnectFromServer();
+ void authentificationProcess();
+ void joinChannel();
+};
+
+#endif // MAINWINDOW_H
diff --git a/irc/mainwindow.ui b/irc/mainwindow.ui
new file mode 100644
index 0000000..d15d229
--- /dev/null
+++ b/irc/mainwindow.ui
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>604</width>
+ <height>458</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="m_connectButton">
+ <property name="text">
+ <string>Connect</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_joinButton">
+ <property name="text">
+ <string>join</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_disconnectButton">
+ <property name="text">
+ <string>Disconnect</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="m_output"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>604</width>
+ <height>25</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>