aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt66
-rw-r--r--cli/CMakeLists.txt67
-rw-r--r--die.cpp1
-rw-r--r--irc/CMakeLists.txt80
-rw-r--r--irc/main.cpp280
-rw-r--r--irc/mainwindow.cpp44
-rw-r--r--irc/mainwindow.h4
7 files changed, 461 insertions, 81 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8306d1a..180c9fa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,70 +1,8 @@
cmake_minimum_required(VERSION 2.8)
-project(dice)
-
-# Find includes in corresponding build directories
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-# Instruct CMake to run moc automatically when needed.
-set(CMAKE_AUTOMOC ON)
-
-# Find the QtWidgets library
-find_package(Qt5Core)
-set(EXECUTABLE_OUTPUT_PATH bin/)
-
-
-include_directories(${Qt5Core_INCLUDES})
-add_definitions(${Qt5Core_DEFINITIONS})
-
-set(MODE "cli")
-
-
-ADD_DEFINITIONS(
- -std=c++11 # Or -std=c++0x
- # Other flags
-)
-add_executable(
- dice
- diceparser.cpp
- range.cpp
- booleancondition.cpp
- validator.cpp
- compositevalidator.cpp
- operationcondition.cpp
- die.cpp
- parsingtoolbox.cpp
- dicealias.cpp
- result/result.cpp
- result/scalarresult.cpp
- result/stringresult.cpp
- result/diceresult.cpp
- node/countexecutenode.cpp
- node/dicerollernode.cpp
- node/executionnode.cpp
- node/explosedicenode.cpp
- node/helpnode.cpp
- node/mergenode.cpp
- node/jumpbackwardnode.cpp
- node/keepdiceexecnode.cpp
- node/listaliasnode.cpp
- node/listsetrollnode.cpp
- node/numbernode.cpp
- node/parenthesesnode.cpp
- node/paintnode.cpp
- node/rerolldicenode.cpp
- node/scalaroperatornode.cpp
- node/sortresult.cpp
- node/startingnode.cpp
- node/ifnode.cpp
- cli/main.cpp
- highlightdice.cpp
- )
-
-#add_executable(dice cli/main.cpp)
-
-
-target_link_libraries(dice ${Qt5Core_LIBRARIES})
-INSTALL_TARGETS(/bin dice)
+add_subdirectory(irc)
+add_subdirectory(cli)
#qt5_use_modules()
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
new file mode 100644
index 0000000..9497b41
--- /dev/null
+++ b/cli/CMakeLists.txt
@@ -0,0 +1,67 @@
+cmake_minimum_required(VERSION 2.8)
+
+
+project(dice)
+# Find includes in corresponding build directories
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+# Instruct CMake to run moc automatically when needed.
+set(CMAKE_AUTOMOC ON)
+
+# Find the QtWidgets library
+find_package(Qt5Core)
+
+set(EXECUTABLE_OUTPUT_PATH bin/)
+
+
+include_directories(${Qt5Core_INCLUDES} ../)
+add_definitions(${Qt5Core_DEFINITIONS})
+
+set(MODE "cli")
+
+
+ADD_DEFINITIONS(
+ -std=c++11 # Or -std=c++0x
+ # Other flags
+)
+add_executable(
+ dice
+ ../diceparser.cpp
+ ../range.cpp
+ ../booleancondition.cpp
+ ../validator.cpp
+ ../compositevalidator.cpp
+ ../operationcondition.cpp
+ ../die.cpp
+ ../parsingtoolbox.cpp
+ ../dicealias.cpp
+ ../result/result.cpp
+ ../result/scalarresult.cpp
+ ../result/stringresult.cpp
+ ../result/diceresult.cpp
+ ../node/countexecutenode.cpp
+ ../node/dicerollernode.cpp
+ ../node/executionnode.cpp
+ ../node/explosedicenode.cpp
+ ../node/helpnode.cpp
+ ../node/mergenode.cpp
+ ../node/jumpbackwardnode.cpp
+ ../node/keepdiceexecnode.cpp
+ ../node/listaliasnode.cpp
+ ../node/listsetrollnode.cpp
+ ../node/numbernode.cpp
+ ../node/parenthesesnode.cpp
+ ../node/paintnode.cpp
+ ../node/rerolldicenode.cpp
+ ../node/scalaroperatornode.cpp
+ ../node/sortresult.cpp
+ ../node/startingnode.cpp
+ ../node/ifnode.cpp
+ main.cpp
+ ../highlightdice.cpp
+ )
+
+target_link_libraries(dice ${Qt5Core_LIBRARIES})
+INSTALL_TARGETS(/bin dice)
+
+#qt5_use_modules()
+
diff --git a/die.cpp b/die.cpp
index 504c1a9..7a79e88 100644
--- a/die.cpp
+++ b/die.cpp
@@ -24,7 +24,6 @@
#include <QDateTime>
#include <QDebug>
-#include <QColor>
Die::Die()
: m_hasValue(false),m_displayStatus(false),m_highlighted(true),m_base(1),m_color("")
diff --git a/irc/CMakeLists.txt b/irc/CMakeLists.txt
new file mode 100644
index 0000000..c7373c6
--- /dev/null
+++ b/irc/CMakeLists.txt
@@ -0,0 +1,80 @@
+cmake_minimum_required(VERSION 2.8)
+
+SET(CMAKE_AUTOUIC ON)
+
+project(irc)
+# Find includes in corresponding build directories
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+# Instruct CMake to run moc automatically when needed.
+set(CMAKE_AUTOMOC ON)
+
+# Find the QtWidgets library
+find_package(Qt5Core)
+find_package(Qt5Gui)
+find_package(Qt5Widgets)
+find_package(Qt5Network)
+
+SET(mainwindow_SOURCES mainwindow.cpp)
+SET(mainwindow_HEADERS mainwindow.h)
+SET(mainwindow_FORMS mainwindow.ui)
+
+set(EXECUTABLE_OUTPUT_PATH bin/)
+
+
+include_directories(${Qt5Core_INCLUDES} ${Qt5Gui_INCLUDES} ${Qt5Widgets_INCLUDES} ${Qt5Network_INCLUDES} ../)
+add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS})
+
+
+qt5_wrap_ui(UI_HEADERS mainwindow.ui)
+#set(MODE "cli")
+
+
+ADD_DEFINITIONS(
+ -std=c++11 # Or -std=c++0x
+ # Other flags
+)
+
+add_executable(
+ irc
+ ../diceparser.cpp
+ ../range.cpp
+ ../highlightdice.cpp
+ ../booleancondition.cpp
+ ../validator.cpp
+ ../compositevalidator.cpp
+ ../operationcondition.cpp
+ ../die.cpp
+ ../parsingtoolbox.cpp
+ ../dicealias.cpp
+ ../result/result.cpp
+ ../result/scalarresult.cpp
+ ../result/stringresult.cpp
+ ../result/diceresult.cpp
+ ../node/countexecutenode.cpp
+ ../node/dicerollernode.cpp
+ ../node/executionnode.cpp
+ ../node/explosedicenode.cpp
+ ../node/helpnode.cpp
+ ../node/mergenode.cpp
+ ../node/jumpbackwardnode.cpp
+ ../node/keepdiceexecnode.cpp
+ ../node/listaliasnode.cpp
+ ../node/listsetrollnode.cpp
+ ../node/numbernode.cpp
+ ../node/parenthesesnode.cpp
+ ../node/paintnode.cpp
+ ../node/rerolldicenode.cpp
+ ../node/scalaroperatornode.cpp
+ ../node/sortresult.cpp
+ ../node/startingnode.cpp
+ ../node/ifnode.cpp
+ ${UI_HEADERS}
+ mainwindow.cpp
+ main.cpp)
+
+
+target_link_libraries(irc ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES})
+INSTALL_TARGETS(/bin irc)
+
+#qt5_use_modules()
+
diff --git a/irc/main.cpp b/irc/main.cpp
new file mode 100644
index 0000000..4a58256
--- /dev/null
+++ b/irc/main.cpp
@@ -0,0 +1,280 @@
+/***************************************************************************
+* Copyright (C) 2014 by Renaud Guezennec *
+* http://www.rolisteam.org/contact/ *
+* *
+* This file is part of DiceParser *
+* *
+* DiceParser is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, *
+* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+* GNU General Public License for more details. *
+* *
+* You should have received a copy of the GNU General Public License *
+* along with this program; if not, write to the *
+* Free Software Foundation, Inc., *
+* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+***************************************************************************/
+
+/*#include <QStringList>
+#include "diceparser.h"
+#include <QCommandLineParser>
+#include <QCommandLineOption>
+#include "highlightdice.h"
+*/
+
+
+
+#include <QApplication>
+#include "mainwindow.h"
+/**
+ * @page Dice
+ * The cli for DiceParser the new dice system from rolisteam.
+ * @section Build and install
+ * To build this program, type these command:
+ * - mkdir build
+ * - cd build
+ * - cmake ../
+ * - make
+ * - make install
+ * @return
+ */
+int main(int argc, char *argv[])
+{
+ QApplication app(argc,argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+
+
+/*QTextStream out(stdout, QIODevice::WriteOnly);
+
+QString diceToText(ExportedDiceResult& dice,bool highlight,bool homogeneous)
+{
+ QStringList resultGlobal;
+ foreach(int face, dice.keys())
+ {
+ QStringList result;
+ ListDiceResult diceResult = dice.value(face);
+ //patternColor = patternColorarg();
+ foreach (HighLightDice tmp, diceResult)
+ {
+ QStringList diceListStr;
+ QStringList diceListChildren;
+
+
+ for(int i =0; i < tmp.getResult().size(); ++i)
+ {
+ qint64 dievalue = tmp.getResult()[i];
+ QString prefix("%1");
+
+ if((tmp.isHighlighted())&&(highlight))
+ {
+ if(tmp.getColor().isEmpty()|| tmp.getColor()=="black")
+ {
+ prefix = "\e[0;31m%1\e[0m";
+ }
+ if(tmp.getColor()=="white")
+ {
+ prefix = "\e[97m%1\e[0m";
+ }
+ if(tmp.getColor()=="blue")
+ {
+ prefix = "\e[34m%1\e[0m";
+ }
+ }
+
+ if(i==0)
+ {
+ diceListStr << prefix.arg(QString::number(dievalue));
+ }
+ else
+ {
+ diceListChildren << prefix.arg(QString::number(dievalue));
+ }
+ }
+ if(!diceListChildren.isEmpty())
+ {
+ diceListStr << QString("[%1]").arg(diceListChildren.join(' '));
+ }
+
+ result << diceListStr.join(' ');
+ // qDebug() << result << tmp.first << tmp.second;
+ }
+
+ if(dice.keys().size()>1)
+ {
+ resultGlobal << QString(" d%2:(%1)").arg(result.join(',')).arg(face);
+ }
+ else
+ {
+ resultGlobal << result;
+ }
+ }
+ return resultGlobal.join(' ');
+}
+
+void startDiceParsing(QString& cmd,QString& treeFile,bool highlight)
+{
+ DiceParser* parser = new DiceParser();
+
+ if(parser->parseLine(cmd))
+ {
+ //
+ if(treeFile.isEmpty())
+ {
+ parser->Start();
+ if(!parser->getErrorMap().isEmpty())
+ {
+ out << "Error" << parser->humanReadableError()<< "\n";
+ return;
+ }
+
+ ExportedDiceResult list;
+ bool homogeneous = true;
+ parser->getLastDiceResult(list,homogeneous);
+ QString diceText = diceToText(list,highlight,homogeneous);
+ QString scalarText;
+ QString str;
+
+ if(parser->hasIntegerResultNotInFirst())
+ {
+ scalarText = QString("%1").arg(parser->getLastIntegerResult());
+ }
+ else if(!list.isEmpty())
+ {
+ scalarText = QString("%1").arg(parser->getSumOfDiceResult());
+ }
+ if(highlight)
+ str = QString("Result: \e[0;31m%1\e[0m, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(parser->getDiceCommand());
+ else
+ str = QString("Result: %1, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(parser->getDiceCommand());
+
+ if(parser->hasStringResult())
+ {
+ str = parser->getStringResult();
+ }
+ out << str << "\n";
+ }
+ else
+ {
+ parser->writeDownDotTree(treeFile);
+ }
+ }
+ else
+ {
+ out << parser->humanReadableError()<< "\n";;
+ }
+}
+
+void usage()
+{
+ QString help = "Usage: ./dice [options]\n\
+\n\
+Options:\n\
+ -c, --color-off Disable color to highlight result\n\
+ -v, --version Show the version and quit.\n\
+ --reset-settings Erase the settings and use the default\n\
+ parameters\n\
+ -d, --dot-file <dotfile> Instead of rolling dice, generate the\n\
+ execution tree and write it in <dotfile>\n\
+ -t, --translation <translationfile> path to the translation file:\n\
+ <translationfile>\n\
+ -h, --help Display this help\n\
+";
+
+ out << help;
+}
+
+
+int main(int argc, char *argv[])
+{
+
+
+
+ QStringList commands;
+ QString cmd;
+ QString dotFileStr;
+
+ bool colorb=true;
+
+ QCommandLineParser optionParser;
+ QCommandLineOption color(QStringList() << "c"<< "color-off", "Disable color to highlight result");
+ QCommandLineOption version(QStringList() << "v"<< "version", "Show the version and quit.");
+ QCommandLineOption reset(QStringList() << "reset-settings", "Erase the settings and use the default parameters");
+ QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", "Instead of rolling dice, generate the execution tree and write it in <dotfile>","dotfile");
+ QCommandLineOption translation(QStringList() << "t"<<"translation", "path to the translation file: <translationfile>","translationfile");
+ QCommandLineOption help(QStringList() << "h"<<"help", "Display this help");
+
+ if(!optionParser.addOption(color))
+ {
+ out << optionParser.errorText() << "\n";
+ }
+
+ optionParser.addOption(version);
+ optionParser.addOption(reset);
+ optionParser.addOption(dotFile);
+ optionParser.addOption(translation);
+ optionParser.addOption(help);
+
+ for(int i=0;i<argc;++i)
+ {
+
+ commands << QString::fromLatin1(argv[i]);
+ }
+
+ optionParser.process(commands);
+
+
+
+
+ if(optionParser.isSet(color))
+ {
+ commands.removeAt(0);
+ colorb = false;
+ }
+ else if(optionParser.isSet(version))
+ {
+ out << "Rolisteam DiceParser v1.0.0"<< "\n";
+ out << "More Details: www.rolisteam.org"<< "\n";
+ return 0;
+ }
+ else if(optionParser.isSet(reset))
+ {
+ return 0;
+ }
+ else if(optionParser.isSet(dotFile))
+ {
+ dotFileStr = optionParser.value(dotFile);
+ }
+ else if(optionParser.isSet(translation))
+ {
+
+ }
+ else if(optionParser.isSet(help))
+ {
+ cmd = "help";
+ }
+ QStringList cmdList = optionParser.positionalArguments();
+ // qDebug()<< "rest"<< cmdList;
+
+ if(!cmdList.isEmpty())
+ {
+ cmd = cmdList.first();
+ }
+ if(!cmd.isEmpty())
+ {
+ startDiceParsing(cmd,dotFileStr,colorb);
+ if(cmd=="help")
+ {
+ usage();
+ }
+ }
+
+ return 0;
+}*/
diff --git a/irc/mainwindow.cpp b/irc/mainwindow.cpp
index cc72b0e..39bac4e 100644
--- a/irc/mainwindow.cpp
+++ b/irc/mainwindow.cpp
@@ -11,13 +11,14 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
// Create socket
- socket = new QTcpSocket(this);
+ m_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(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()));
@@ -30,12 +31,19 @@ MainWindow::~MainWindow()
}
void MainWindow::connectToServer()
{
- socket->connectToHost(QString("irc.epiknet.org"), 6667);
+ qDebug() << "start connection";
+ m_socket->connectToHost(QString("irc.freenode.net"), 8001);
+}
+void MainWindow::errorOccurs(QAbstractSocket::SocketError)
+{
+ qDebug() << "ERROR" << m_socket->errorString();
}
void MainWindow::readData()
{
- QString readLine = socket->readLine();
+
+ qDebug() << "Reply";
+ QString readLine = m_socket->readLine();
if(readLine.startsWith("!"))
readLine = readLine.remove(0,1);
@@ -60,8 +68,8 @@ void MainWindow::readData()
{
m_parser->Start();
QString result = m_parser->displayResult();
- QString msg("PRIVMSG #opale-roliste :%1 \r\n");
- socket->write(msg.arg(result).toLatin1());
+ QString msg("PRIVMSG #Rolisteam :%1 \r\n");
+ m_socket->write(msg.arg(result).toLatin1());
}
}
else
@@ -81,29 +89,35 @@ void MainWindow::readData()
{
QString resp = "PONG :"+list[1];
- socket->write(resp.toLatin1());
+ m_socket->write(resp.toLatin1());
}
}
+ if(readLine.contains("Found your hostname"))
+ {
+ authentificationProcess();
+ }
// Add to ouput
ui->m_output->append(readLine.trimmed());
// Next data??
- if(socket->canReadLine()) readData();
+ if(m_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 :-)
+ 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()
{
- socket->write("NICK diceBot \r\n");
- socket->write("USER diceBot diceBot diceBot :diceBot BOT \r\n");
+ 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()
{
- socket->write("JOIN #opale-roliste \r\n");
+ m_socket->write("JOIN #Rolisteam \r\n");
}
diff --git a/irc/mainwindow.h b/irc/mainwindow.h
index 6a819fd..d7139d6 100644
--- a/irc/mainwindow.h
+++ b/irc/mainwindow.h
@@ -18,9 +18,11 @@ public:
explicit MainWindow(QWidget *parent = 0);
virtual ~MainWindow();
+public slots:
+ void errorOccurs(QAbstractSocket::SocketError);
private:
Ui::MainWindow *ui;
- QTcpSocket * socket;
+ QTcpSocket * m_socket;
DiceParser* m_parser;
private slots: