code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
#include "DiscussPane.h" #include "ui_DiscussPane.h" #include "LutController.h" DiscussPane::DiscussPane(int gid, QWidget *parent) : QWidget(parent), ui(new Ui::DiscussPane), guyId(gid) { ui->setupUi(this); ui->textBrowser->setOpenExternalLinks(true); connect(ui->lineEdit, SIGNAL(returnPressed()), ui->pushButton, SIGNAL(clicked())); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(sendMsg())); } DiscussPane::~DiscussPane() { delete ui; } void DiscussPane::displayInfo(QString str) { ui->textBrowser->setTextColor(Qt::gray); ui->textBrowser->insertPlainText(str); moveToBottom(); } void DiscussPane::clearPane() { ui->textBrowser->clear(); moveToBottom(); } void DiscussPane::displayError(QString str) { ui->textBrowser->setTextColor(Qt::red); ui->textBrowser->insertPlainText(str); moveToBottom(); } void DiscussPane::displayMsg(int from, QString str) { moveToBottom(); if(LutController::getInstance()->getShowTime()) { QTime ct = QTime::currentTime(); ui->textBrowser->setFontWeight(QFont::Normal); ui->textBrowser->setTextColor(Qt::gray); ui->textBrowser->insertPlainText("("+ QString((ct.hour()<10) ? "0":"") + QString::number(ct.hour()) +":"+ ((ct.minute()<10) ? "0":"") + QString::number(ct.minute()) +":"+ ((ct.second()<10) ? "0":"") +QString::number(ct.second())+") "); } ui->textBrowser->setFontWeight(QFont::Bold); ui->textBrowser->setTextColor(Qt::darkBlue); if(from == LutController::getInstance()->myId()) ui->textBrowser->setTextColor(Qt::darkRed); ui->textBrowser->insertPlainText(LutController::getInstance()->getNameFromId(from) + ": "); ui->textBrowser->setFontWeight(QFont::Normal); str.replace(":)", "<img src=\":/img/sourire.gif\" alt='' title=\":)\" />"); str.replace(":(", "<img src=\":/img/triste.gif\" alt='' title=\":(\" />"); str.replace(":D", "<img src=\":/img/D.gif\" alt='' title=\":D\" />"); str.replace(":nerd:", "<img src=\":/img/nerd.gif\" alt='' title=\":nerd:\" />"); str.replace(";)", "<img src=\":/img/clin_oeil.gif\" alt='' title=\";)\" />"); str.replace(":p", "<img src=\":/img/p.gif\" alt='' title=\":p\" />"); str.replace(QRegExp("<(?!(img.*>))"), "&lt;"); str.replace(QRegExp("(https?://[^ ]*)"), "<a href='\\1'>\\1</a> "); str.replace("%E2%82%AC", QChar(8364)); str.replace("\n", "<br />"); ui->textBrowser->insertHtml(str); ui->textBrowser->setTextColor(Qt::black); ui->textBrowser->setFontUnderline(false); ui->textBrowser->insertPlainText("\n"); moveToBottom(); emit toRead(this); } bool DiscussPane::isPrivate() { return (guyId >= 0); } void DiscussPane::sendMsg() { moveToBottom(); if(ui->lineEdit->text().size() > 0) { if(!isPrivate()) { LutController::getInstance()->sendMsg(ui->lineEdit->text()); } else { LutController::getInstance()->sendPrivateMsg(guyId, ui->lineEdit->text()); } displayMsg(LutController::getInstance()->myId(), ui->lineEdit->text()); } ui->lineEdit->clear(); } int DiscussPane::getGuyId() { return guyId; } void DiscussPane::setGuyId(int val) { guyId = val; } void DiscussPane::moveToBottom() { ui->textBrowser->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); }
01lut
branches/test2/src/ClientQt/DiscussPane.cpp
C++
gpl3
3,190
#ifndef USER_H #define USER_H #include <QString> #include <QStringList> class User // : public QListWidgetItem { public: User(int id, QString name); User(QString data); int getId(); QString getName(); void setId(int val); void setName(QString n); private: int id; QString name; }; #endif // USER_H
01lut
branches/test2/src/ClientQt/User.h
C++
gpl3
313
#include "MainWindow.h" #include "ui_MainWindow.h" #include <QInputDialog> #include <QStringList> #include <QUrl> #include "DiscussPane.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), nickname("Anonymous"), settings("01Lut", "01Lut") { setAttribute(Qt::WA_DeleteOnClose, false); privatePanes = new QList<DiscussPane*>(); mainPane = new DiscussPane(-1, this); connect(mainPane, SIGNAL(toRead(DiscussPane*)), this, SLOT(onToRead(DiscussPane*))); icon = new QIcon(":/img/icon.png"); iconWarn = new QIcon(":/img/iconW.png"); trayIcon = new QSystemTrayIcon(*icon); this->setWindowIcon(*icon); trayIcon->show(); QDir home = QDir::home(); nickname = settings.value("nickname", home.dirName()).toString(); serverIP = settings.value("server", "127.0.0.1").toString(); serverPort = settings.value("port", 1888).toInt(); showTime = settings.value("time", true).toBool(); QString tmp = settings.value("server").toString(); if(tmp.size() < 1) { QString ipServer = QInputDialog::getText(this, "server address", "Server address :", QLineEdit::Normal, "127.0.0.1:1888"); QStringList serverInfos = ipServer.split(":"); if(serverInfos.size()>1) serverPort = serverInfos.at(1).toInt(); settings.setValue("server", serverInfos.at(0)); settings.setValue("port", serverPort); serverIP = serverInfos.at(0); } ui->setupUi(this); exitAct = new QAction("Quit", this); exitAct->setShortcut(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(onExitAct())); ui->menuTools->addAction(exitAct); menuTray= new QMenu("01Lut"); menuTray->addAction(exitAct); trayIcon->setContextMenu(menuTray); sock = new QTcpSocket(this); connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorReceived(QAbstractSocket::SocketError))); connect(sock, SIGNAL(readyRead()), this, SLOT(dataHandler())); connect(sock, SIGNAL(connected()), this, SLOT(onConnected())); QString str = "Connecting to server at "; str += serverIP + " on port " + QString::number(serverPort) + "\n"; mainPane->displayInfo(str); sock->connectToHost(serverIP, serverPort); connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabChanged(int))); connect(ui->listWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onItemDoubleClicked(QModelIndex))); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onTrayClicked(QSystemTrayIcon::ActivationReason))); notifications = settings.value("notifications", true).toBool(); ui->actionNotifications->setChecked(notifications); ui->actionShow_time->setChecked(showTime); QHBoxLayout *l = static_cast<QHBoxLayout*>(ui->mainTab->layout()); l->insertWidget(0, mainPane, 6); l->setStretch(1, 1); onTabChanged(0); } bool MainWindow::getShowTime() { return showTime; } void MainWindow::initMainWindow() { ui->listWidget->setModel(LutController::getInstance()->getUsers()); } void MainWindow::onTabChanged(int id) { if(id>0) { ui->actionClose_current_tab->setEnabled(true); } else { ui->actionClose_current_tab->setEnabled(false); } ui->tabWidget->setTabIcon(id, QIcon()); } MainWindow::~MainWindow() { delete ui; } void MainWindow::errorReceived(QAbstractSocket::SocketError socketError) { QString str; if(socketError == QAbstractSocket::ConnectionRefusedError) { str = "::Cannot connect to server... Aborting.\n"; } else { str =":: Server error\n"; } mainPane->displayError(str); for(int i=0; i<privatePanes->size(); i++) { privatePanes->at(i)->displayError(str); } this->activateWindow(); } void MainWindow::sendMsg(QString str) { if(str.size() > 0) { QByteArray data = "MSG "; str.replace(QChar(8364), "%E2%82%AC"); data.append(str); sock->write(data); } } void MainWindow::sendPrivateMsg(int to, QString str) { if(str.size() > 0) { QByteArray data = "PMSG "; data.append(QString::number(to)+" "); str.replace(QChar(8364), "%E2%82%AC"); data.append(str); sock->write(data); } } void MainWindow::dataHandler() { while(sock->bytesAvailable()>0) { char c; QByteArray data; do { sock->read(&c, 1); data.append(c); } while ( c != EOF ); data.remove(data.size()-1, 1); if(data.indexOf("MSG ") == 0) { QString str(data.remove(0, 4)); QStringList parts = str.split(" "); int pos = str.indexOf(" "); str = str.remove(0, pos+1); // TODO: displaymsg(str) mainPane->displayMsg(parts.at(0).toInt(), str); // ---------------------- // ---- Notifications --- if(!isActiveWindow()) { trayIcon->setIcon(*iconWarn); if(notifications) trayIcon->showMessage("New message from "+LutController::getInstance()->getNameFromId(parts.at(0).toInt()), str); } } else if(data.indexOf("PMSG ") == 0) { QString str(data.remove(0, 5)); QStringList parts = str.split(" "); int pos = str.indexOf(" "); str = str.remove(0, pos+1); DiscussPane *pane = findPaneById(parts.at(0).toInt()); if(!pane) { int gid = parts.at(0).toInt(); QString gname = LutController::getInstance()->getUsers()->getNameById(gid); pane = new DiscussPane(gid, this); privatePanes->append(pane); ui->tabWidget->addTab(pane, gname); connect(pane, SIGNAL(toRead(DiscussPane*)), this, SLOT(onToRead(DiscussPane*))); } pane->displayMsg(parts.at(0).toInt(), str); // ---------------------- // ---- Notifications --- if(!isActiveWindow()) { trayIcon->setIcon(*iconWarn); if(notifications) trayIcon->showMessage("New message from "+LutController::getInstance()->getNameFromId(parts.at(0).toInt()), str); } } else if(data.indexOf("NICK ") == 0) { QString str(data.remove(0, 5)); int pos = str.indexOf(" "); int userId = str.left(pos).toInt(); QString info = LutController::getInstance()->getNameFromId(userId)+" is now known as "+ str.mid(pos+1)+"\n"; DiscussPane *pane = findPaneById(userId); if(pane) pane->displayInfo(info); mainPane->displayInfo(info); sock->write("LIST"); } else if(data.indexOf("NC ") == 0) { QString str(data.remove(0, 3)); mainPane->displayInfo(str + " has join.\n"); sock->write("LIST"); } else if(data.indexOf("LEAVE ") == 0) { int idClient = data.remove(0, 6).toInt(); QString info = LutController::getInstance()->getNameFromId(idClient)+" has left.\n"; DiscussPane *pane = findPaneById(idClient); if(pane) { pane->displayInfo(info); pane->setGuyId(0); } mainPane->displayInfo(info); LutController::getInstance()->getUsers()->removeRowById(idClient); sock->write("LIST"); } else if(data.indexOf("YID ") == 0) { id = data.remove(0, 4).toInt(); } else if(data.indexOf("LIST ") == 0) { QString str = data.remove(0, 5); QStringList users = str.split(" ; "); majUserList(users); } } } DiscussPane* MainWindow::findPaneById(int id) { for(int i=0; i<privatePanes->size(); i++) { if(privatePanes->at(i)->getGuyId() == id) return privatePanes->at(i); } return 0; } void MainWindow::on_actionChange_nickname_triggered() { QString n = QInputDialog::getText(this, "Nickname", "Choose a nickname", QLineEdit::Normal, nickname); if(n.size()>0) { QByteArray data = "NICK "; data.append(n); sock->write(data); nickname = n; settings.setValue("nickname", nickname); } } void MainWindow::onConnected() { QString str = "Connected\n"; mainPane->displayInfo(str); for(int i=0; i<privatePanes->size(); i++) { privatePanes->at(i)->displayInfo(str); } QByteArray data = "NICK "; data.append(nickname); sock->write(data); } bool MainWindow::event ( QEvent *event ) { if(event->type() == QEvent::WindowActivate) trayIcon->setIcon(*icon); return QMainWindow::event(event); } void MainWindow::onItemDoubleClicked(QModelIndex index) { int gid = LutController::getInstance()->getUsers()->data(index,Qt::UserRole).toInt(); QString gname = LutController::getInstance()->getUsers()->data(index,Qt::DisplayRole).toString(); DiscussPane *p = findPaneById( gid ); if( !p ) { p = new DiscussPane(gid, this); privatePanes->append(p); int i = ui->tabWidget->addTab(p, gname); ui->tabWidget->setCurrentIndex(i); connect(p, SIGNAL(toRead(DiscussPane*)), this, SLOT(onToRead(DiscussPane*))); } else { int panePos = ui->tabWidget->indexOf(p); ui->tabWidget->setCurrentIndex(panePos); } } void MainWindow::onToRead(DiscussPane *p) { int i = ui->tabWidget->indexOf(p); i = i<0?0:i; if(i != ui->tabWidget->currentIndex()) { ui->tabWidget->setTabIcon(i, QIcon(":/img/warn.png")); } } void MainWindow::onTrayClicked(QSystemTrayIcon::ActivationReason r) { if(r == QSystemTrayIcon::Trigger) { if(isVisible()) close(); else show(); } } void MainWindow::on_actionChange_server_triggered() { serverPort = 1888; QString ipServer = QInputDialog::getText(this, "server address", "Server address :", QLineEdit::Normal, serverIP+":"+QString::number(serverPort)); QStringList serverInfos = ipServer.split(":"); if(ipServer.size()>0) { if(serverInfos.size()>1) serverPort = serverInfos.at(1).toInt(); serverIP = serverInfos.at(0); settings.setValue("server", serverIP); settings.setValue("port", serverPort); sock->disconnectFromHost(); sock->connectToHost(serverIP, serverPort); QString str = "Connecting to server at "; str += serverIP + " on port " + QString::number(serverPort) + "\n"; mainPane->displayInfo(str); privatePanes->clear(); for(int i=1; i<ui->tabWidget->count(); i++) { ui->tabWidget->removeTab(i); } LutController::getInstance()->getUsers()->clear(); } } int MainWindow::myId() { return id; } void MainWindow::majUserList(QStringList list) { for (int i=0; i<list.size(); i++) if(list.at(i) != "") majUser(list.at(i)); } void MainWindow::majUser(QString data) { QStringList infos = data.split(" "); int uid = infos.at(0).toInt(); LutController::getInstance()->getUsers()->addOrReplace(new User(data)); DiscussPane *pane = findPaneById(uid); if(pane) { int idpane = ui->tabWidget->indexOf(pane); ui->tabWidget->setTabText(idpane, LutController::getInstance()->getNameFromId(uid)); } } void MainWindow::on_actionNotifications_toggled(bool v) { notifications = v; settings.setValue("notifications", v); } void MainWindow::on_actionClose_current_tab_triggered() { DiscussPane *p = static_cast<DiscussPane*>(ui->tabWidget->currentWidget()); privatePanes->removeOne(p); ui->tabWidget->removeTab(ui->tabWidget->currentIndex()); } void MainWindow::onExitAct() { LutController::getInstance()->onQuitReq(); } void MainWindow::on_actionShow_time_triggered() { } void MainWindow::on_actionShow_time_toggled(bool v) { showTime = v; settings.setValue("time", v); } void MainWindow::on_actionClear_triggered() { DiscussPane *p; p = ui->tabWidget->currentIndex() > 0 ? static_cast<DiscussPane*>(ui->tabWidget->currentWidget()) : mainPane; p->clearPane(); }
01lut
branches/test2/src/ClientQt/MainWindow.cpp
C++
gpl3
10,968
#ifndef LUTCONTROLLER_H #define LUTCONTROLLER_H #include <QObject> #include "UserList.h" class MainWindow; class LutController : public QObject { Q_OBJECT public: static LutController* getInstance(); int myId(); QString getNameFromId(int id); void sendMsg(QString str); void sendPrivateMsg(int to, QString str); bool getShowTime(); UserList* getUsers(); void startApp(); private: explicit LutController(); MainWindow *window; UserList *users; static LutController *instance; signals: void quitMe(); public slots: void onQuitReq(); }; //extern static LutController *LutController::instance; #endif // LUTCONTROLLER_H
01lut
branches/test2/src/ClientQt/LutController.h
C++
gpl3
649
#ifndef PRIVATEPANE_H #define PRIVATEPANE_H #include <QWidget> #include "User.h" #include "MainWindow.h" namespace Ui { class DiscussPane; } class DiscussPane : public QWidget { Q_OBJECT signals: void toRead(DiscussPane*); public: explicit DiscussPane(int gid = -1, QWidget *parent = 0); ~DiscussPane(); void displayInfo(QString str); void displayError(QString str); void displayMsg(int from, QString str); void moveToBottom(); bool isPrivate(); int getGuyId(); void setGuyId(int val); void clearPane(); private: Ui::DiscussPane *ui; int guyId; private slots: void sendMsg(); }; #endif // PRIVATEPANE_H
01lut
branches/test2/src/ClientQt/DiscussPane.h
C++
gpl3
635
#include "log.hpp" Log::Log(FString path) { if((file = open(path.data(), O_WRONLY|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR))<0) { cout << "Cannot open log file" << endl; } } Log::~Log() { close(file); } void Log::logger(FString data) { FString str = dateLog(); str.erase(str.size()-1, 1); str += "\t"; str += data; str += " \n"; write(file, str.data(), str.size()); } FString Log::dateLog() { time_t t = time(NULL); char *dateLogs = asctime(localtime(&t)); return FString(dateLogs); }
01lut
branches/test2/src/log.cpp
C++
gpl3
499
#include <iostream> #include <arpa/inet.h> #include <netdb.h> #include <netinet/in.h> #include <unistd.h> #include <sys/select.h> #include <sys/types.h> #include <time.h> #include "prompt.hpp" #include "log.hpp" #include "fstring.hpp" #include "user.hpp" #define BUFFSIZE 100000 #define CMAX 990 using namespace std; /* * Cette classe représente le serveur * * Elle hérite de prompt comme vous pouvez le voir */ class Server : public Prompt { public: Server(int port = 1888, FString logDir = "/var/log/01lut/"); ~Server(); void start(); void stop(); private: char buff[BUFFSIZE]; bool activate; Log *logMsg; Log *logSvr; int lport; int sockServer; sockaddr_in serverAddress; int highestSock; fd_set socksToListen; // int clients[CMAX]; User* clients[CMAX]; int nbClients; void initList(); void runLoop(); void readSocks(); void forwardFrom(int from, FString str); void forward(FString str); void handleRequest(User *cli, char *request); void sendMsg(User *cli, FString msg); int checkSocket(int id); User* findClient(int id); void alertClients(); };
01lut
branches/test2/src/server.hpp
C++
gpl3
1,099
#include "user.hpp" User::User(int sock) { this->sock = sock; name = "Anonymous"; registered = false; } User::~User() { } int User::getSock() { return sock; } FString User::getName() { return this->name; } void User::setName(FString str) { this->name = str; } void User::registerMe() { registered = true; } bool User::isRegistered() { return registered; }
01lut
branches/test2/src/user.cpp
C++
gpl3
372
#include "prompt.hpp" /** Constructeur de Prompt */ Prompt::Prompt() : welcome(true) { } /** Destructeur de l'objet */ Prompt::~Prompt() { } /** Les méthodes qui suivent doivent être redéfinies dans les classes dérivées. Ici est simplement définit un comportement par défaut pour chacune d'entre elles, comportement qui sera redéfinit dans les classes dérivées. */ /** Cette méthode associe chaque commande à une fonction */ void Prompt::processCmd(char *cmd) { if(strcmp(cmd, "quit") == 0) { stop(); } else { cout << "Erreur: Commande inconnue : " << cmd << endl; } } /** Affichage du prompt, indiquant à l'utilisateur qu'il a la main pour entrer des commandes sur l'entrée standard */ void Prompt::showPrompt() { if(welcome) cout << "(type quit to quit)" << endl; cout << "> "; cout.flush(); welcome = false; }
01lut
branches/test2/src/prompt.cpp
C++
gpl3
862
#ifndef USER_H #define USER_H #include "fstring.hpp" class User { public: User(int sock); ~User(); FString getName(); int getSock(); void setName(FString str); bool isRegistered(); void registerMe(); private: FString name; int sock; bool registered; }; #endif
01lut
branches/test2/src/user.hpp
C++
gpl3
284
#include "person.hpp" Person::Person(int _sock) { sock = _sock; name = "Sans nom"; } Person::~Person() { } Person::setName(FString n) { name = n; }
01lut
branches/test2/src/person.cpp
C++
gpl3
156
#ifndef FRONTEND_H #define FRONTEND_H /* Cette classe fournit une interface à un backend client (voire serveur) */ #include "fstring.hpp" class Frontend { public: Frontend(){}; virtual void updateBids() = 0; virtual void serverReady() = 0; }; #endif
01lut
branches/test2/src/frontend.hpp
C++
gpl3
267
#include "fstring.hpp" // TEST class Person { public: Person(int _sock); ~Person(); void setName(FString n); private: FString name; int sock; }
01lut
branches/test2/src/person.hpp
C++
gpl3
160
#include "server.hpp" #include "fstring.hpp" #include <unistd.h> #include <stdio.h> int main(int argc, char** argv) { int port = 1888; FString logDir = "/var/log/"; char c; FString str; while( (c = getopt(argc, argv, "p:d:")) != EOF ) { switch(c) { case 'p': str = optarg; port = str.toInt(); break; case 'd': logDir = optarg; break; } } Server s(port, logDir); s.start(); return 0; }
01lut
branches/test2/src/serverCmd.cpp
C++
gpl3
433
#ifndef LOG_H #define LOG_H #include <iostream> #include "fstring.hpp" #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> using namespace std; class Log { public: Log(FString path); ~Log(); void logger(FString data); private: int file; FString dateLog(); }; #endif
01lut
branches/test2/src/log.hpp
C++
gpl3
329
#include "fstring.hpp" #include <sstream> /** Constructeur de la classe Permet de créer un objet de type FString */ FString::FString() : std::string() { } /** Constructeur de la classe Permet de créer un objet de type FString à partir d'une chaine de caractere */ FString::FString(const char *s) : std::string(s) { } /** Methode qui permet de couper une chaine de caractere dans un tableau dynamique en deux parties Le separateur de type caractere est la partie referente pour le decoupage Cette methode retourne un vector contenant les différentes partie de la chaine coupée */ std::vector<FString> FString::split(char separator) { std::vector<FString> parts; unsigned int i = 0; parts.push_back(FString()); while(i < size()) { if(data()[i] == separator) { parts.push_back(FString()); } else { parts.back().push_back(data()[i]); } i++; } return parts; } /** Cette methode permet d'isoler la premiere partie d'un message qui contient la commande à executer */ FString FString::getCmd() { return split(' ').at(0); } /** Cette methode permet de recuperer les arguments d'une requête */ FString FString::getArgs() { FString args(data()); while(args.size() && args.data()[0] != ' ') { args.erase(0, 1); } if(args.data()[0] == ' ') args.erase(0, 1); // efface espace return args; } /** [static] Cette methode permet de changer un entier en une chaine de caractère */ FString FString::fromInt(int i) { std::stringstream ss; ss << i; FString str; ss >> str; return str; } /** [static] Cette methode permet de changer un float en une chaine de caractère */ FString FString::fromFloat(float i) { std::stringstream ss; ss << i; FString str; ss >> str; return str; } /** Retourne la valeur entière représentée par la chaîne */ int FString::toInt() { std::stringstream ss(this->data()); int ret; ss >> ret; return ret; } void FString::removeChar(char c) { for(unsigned int i=0; i<size(); i++) { if(data()[i] == c) { erase(1,i); i--; } } }
01lut
branches/test2/src/fstring.cpp
C++
gpl3
2,061
#ifndef FSTRING_HPP #define FSTRING_HPP /** 01/12/2009 -- Cette classe représente une std::string sur laquelle une méthode split() peut être appelée -> Créée pour simplifier l'interprétations des requêtes Ne pas hésiter à rajouter des méthodes qui simplifient l'usage des chaînes de caractères */ #include <string> #include <vector> class FString : public std::string { public: FString(); FString(const char *s); std::vector<FString> split(char separator); FString getCmd(); FString getArgs(); int toInt(); static FString fromInt(int i); static FString fromFloat(float i); void removeChar(char c); }; #endif
01lut
branches/test2/src/fstring.hpp
C++
gpl3
651
#include <iostream> #include <netdb.h> #include <netinet/in.h> #include <unistd.h> #include "log.hpp" #include "fstring.hpp" #include "prompt.hpp" #define BUFFSIZE 512 using namespace std; /* * Cette classe représente un client * * Elle aussi hérite de prompt :) :) */ class Client : public Prompt { public: Client(const char* adresse); ~Client(); void start(); void stop(); void update(); bool isConnected(); private: bool activate; char buff[512]; int dport; int socketDesc; fd_set toListen; char* addressServer; sockaddr_in serverAddress; hostent *hostInfo; bool connected; void runLoop(); void stdinHandler(); void dataHandler(); FString sendAndWait(FString request); };
01lut
branches/test2/src/client.hpp
C++
gpl3
736
#include "client.hpp" /** Permet de lancer un client en mode Shell **/ int main(int argc, char **argv) { FString adresse = ""; if(argc > 1) adresse += argv[1]; if(adresse.compare("") == 0) { adresse = "127.0.0.1"; } Client c(adresse.data()); c.start(); return 0; }
01lut
branches/test2/src/clientCmd.cpp
C++
gpl3
281
#include <cstdio> #include "server.hpp" /** Constructeur d'un objet Serveur */ Server::Server(int port, FString logDir) { nbClients = 0; lport = port; activate = false; for(int i=0; i<CMAX; i++) clients[i] = 0; // set the address structure serverAddress.sin_family = AF_INET; serverAddress.sin_addr.s_addr = htonl(INADDR_ANY); serverAddress.sin_port = htons(lport); FString logFile = logDir; logFile += "/msg.log"; FString logFile2 = logDir; logFile2 += "/server.log"; logMsg = new Log(logFile); logSvr = new Log(logFile2); } /** Destructeur de l'objet Serveur */ Server::~Server() { } /** Methode permettant de demarrer le serveur */ void Server::start() { activate = true; // Creation du socket server // sockServer = socket(AF_INET, SOCK_STREAM, 0); sockServer = socket(AF_INET, SOCK_STREAM, 0); int somerandomint = 1; setsockopt(sockServer, SOL_SOCKET, SO_REUSEADDR, &somerandomint, sizeof(int)); if(sockServer > 0) { // bind du socket int bResult = bind(sockServer, (struct sockaddr *) &serverAddress, sizeof(serverAddress)); if(bResult < 0) { cout << "\t\t\tFail !" << endl; cout << "Connexion error" << endl; close(sockServer); } else { listen(sockServer, CMAX); cout << "Starting server..." << endl; cout << ":: Server is listening on port " << lport << endl; FString log = "Server started on port "; log += FString::fromInt(lport); logSvr->logger(log); highestSock = sockServer; runLoop(); } } else { cout << "\t\t\tFail !" << endl; cout << "can't create socket" << endl; } } /** Methode permettant d'arreter proprement le serveur */ void Server::stop() { activate = false; cout << "Stopping server...\t\t\tOK" << endl; FString log = "Server stopped"; logSvr->logger(log); } /** Crée la liste des descripteurs à écouter */ void Server::initList() { /* on commence par ajouter l'entrée standard */ FD_ZERO(&socksToListen); FD_SET(sockServer, &socksToListen); FD_SET(0, &socksToListen); /* puis on ajoute chaque socket de client */ for(int i=0; i<CMAX; i++) { if(clients[i] != 0) { FD_SET(clients[i]->getSock(), &socksToListen); if(clients[i]->getSock() > highestSock) highestSock = clients[i]->getSock(); } } } /** Lis les différents descripteurs de fichiers afin d'y récuprérer les informations présentes */ void Server::readSocks() { /* tentative de connexion */ if(FD_ISSET(sockServer, &socksToListen)) { cout << "\n::Un nouveau client essaye de se connecter..."; int connect = accept(sockServer, NULL, NULL); if(connect < 0) { cout << "\t\tEchoue!" << endl; } else { for(int i=0; i<CMAX; i++) { if(clients[i] == 0) { clients[i] = new User(connect); nbClients++; FString str("YID "); str += FString::fromInt(connect); sendMsg(clients[i], str); cout << "\t\tOK" << endl; cout << " -> assigne a " << i << endl; FString log = "New client connected on slot"; log += FString::fromInt(i); logSvr->logger(log); showPrompt(); return; } } /* si on arrive ici, c'est qu'il n'y a plus de place */ close(connect); cout << "\t\t\tEchoue!" << endl; } } /* evenements sur stdin */ if(FD_ISSET(0, &socksToListen)) { if(read(0, buff, BUFFSIZE)) { // on enlève le '\n' à la fin for(int i=0; i<BUFFSIZE; i++) { if(buff[i] == '\n') { buff[i] = '\0'; i = BUFFSIZE; // Bourrin : pour sortir :) } } if(strcmp("",buff) != 0) { processCmd(buff); } } } /* autres evenements */ for(int i=0; i<CMAX; i++) { if(clients[i] && FD_ISSET(clients[i]->getSock(), &socksToListen)) { int rec_res = recv(clients[i]->getSock(), buff, BUFFSIZE, 0); /* un client se deconnecte */ if(rec_res == 0) { FString log = "Client "; log += clients[i]->getName(); log += " has left"; logSvr->logger(log); cout << "\n::Client n°" << i << " a quitte" << endl; FString str("LEAVE "); str += FString::fromInt(clients[i]->getSock()); close(clients[i]->getSock()); delete clients[i]; clients[i] = 0; // avoid hole in tab for(int k=i; k<nbClients; k++) clients[k] = clients[k+1]; nbClients--; forward(str); } else if(rec_res > 0) { cout << "\n::Reçu: " << buff << endl; cout << " du client n°" << i << endl; FString log = "From slot"; log += FString::fromInt(i)+": "+buff; logSvr->logger(log); handleRequest(clients[i], buff); } } } showPrompt(); } /** Methode permettant d'envoyer un message à tous les clients inscrits sauf à celui qui a envoyé le message */ void Server::forwardFrom(int from, FString str) { for(int i=0; i<nbClients; i++) { if(clients[i] && from != clients[i]->getSock()) sendMsg(clients[i], str); } } /** Envoyer un message à tous les clients */ void Server::forward(FString str) { for(int i=0; i<nbClients; i++) { if(clients[i]) { sendMsg(clients[i], str); } } } void Server::sendMsg(User *cli, FString msg) { msg += EOF; send(cli->getSock(), msg.data(), msg.size(), 0); } /** Methode permettant de traiter une information envoyée par un client */ void Server::handleRequest(User *cli, char *request) { FString req(request); FString cmd = req.getCmd(); FString arg = req.getArgs(); /* traitement de la requete INFO */ if(cmd.compare("LIST") == 0) { FString str("LIST "); for(int i=0; i<nbClients; i++) { str += FString::fromInt(clients[i]->getSock()) + " "; str += clients[i]->getName()+" ; "; } sendMsg(cli, str); } /* traitement de la requete MSG */ else if(cmd.compare("MSG") == 0) { FString str; str += cmd + " " + FString::fromInt(cli->getSock()) + " " + arg; forwardFrom(cli->getSock(), str); FString log = "From "; log += cli->getName() + " : " + arg ; logMsg->logger(log); } /* privates msg */ else if(cmd.compare("PMSG") == 0) { FString msg = arg; int idUser = msg.getCmd().toInt(); cout << "--- " << msg << endl; idUser = checkSocket(idUser); if(idUser > 0) { FString str("PMSG "); str += FString::fromInt(cli->getSock())+" "+msg.getArgs(); User *to = findClient(idUser); if(to) sendMsg(to, str); } } /* traitement de la requete DETAILS */ else if(cmd.compare("NICK") == 0) { FString nick = arg.getCmd(); if(nick.compare("") != 0) { cli->setName(nick); if(cli->isRegistered()) { FString str("NICK "); str += FString::fromInt(cli->getSock()) + " " + nick; forward(str); } else { FString str("NC "); str += nick; forward(str); cli->registerMe(); } } } } /** Boucle d'exécution du serveur on y écoute les différents sockets */ void Server::runLoop() { int nbSocksToRead; struct timeval timeout; showPrompt(); while(activate) { for(int k=0; k<BUFFSIZE; k++) //Initialisation du buffer buff[k] = '\0'; initList(); timeout.tv_sec = 1; timeout.tv_usec = 0; nbSocksToRead = select(highestSock+1, &socksToListen, NULL, NULL, &timeout); if(nbSocksToRead > 0) { readSocks(); } alertClients(); } } /** Check if a socket is registered in client lists returns socket descriptor if exists, -1 if it doesn't */ int Server::checkSocket(int id) { for(int i=0; i<nbClients; i++) { if(clients[i]->getSock() == id) return id; } return -1; } User* Server::findClient(int id) { for(int i=0; i<nbClients; i++) { if(clients[i]->getSock() == id) return clients[i]; } return 0; } /** Methode qui permet d'alerter les clients que une enchere est terminée */ void Server::alertClients() { }
01lut
branches/test2/src/server.cpp
C++
gpl3
7,700
#ifndef PROMPT_H #define PROMPT_H /** Freddy Teuma - 28/11/2009 -- Cette classe permet de faire l'interface entre une commande et une action. Dériver cette classe et implémenter les méthodes abstraites. */ #include <iostream> #include <string.h> #include "fstring.hpp" using namespace std; class Prompt { public: Prompt(); ~Prompt(); virtual void start() = 0; virtual void stop() = 0; void showPrompt(); void processCmd(char *cmd); private: bool welcome; }; #endif
01lut
branches/test2/src/prompt.hpp
C++
gpl3
500
#include "client.hpp" #include <sstream> /** Constructeur de la classe */ Client::Client(const char* adresse) { dport = 1888; activate = false; connected = false; hostInfo = gethostbyname(adresse); addressServer = (char*)adresse; if(hostInfo != NULL) { serverAddress.sin_family = hostInfo->h_addrtype; memcpy((char *) &serverAddress.sin_addr.s_addr, hostInfo->h_addr_list[0], hostInfo->h_length); serverAddress.sin_port = htons(dport); } } /** Démarre le client : On se connecte au serveur puis on entre dans la boucle d'exécution si la connexion a réussi : voir runLopp(); */ void Client::start() { activate = true; cout << "::Connexion au serveur " << addressServer; socketDesc = socket(AF_INET, SOCK_STREAM, 0); if(socketDesc <= 0) { cout << "\t\t\tEchoue!" << endl; } else { if(connect(socketDesc, (sockaddr*) &serverAddress, sizeof(sockaddr)) == -1) { cout << "\t\t\tEchoue!" << endl; } else { cout << "\t\t\tOK" << endl; /* init the list to listen */ connected = true; runLoop(); } } } /** Termine l'exécution */ void Client::stop() { activate = false; } /** Traitement des données reçues sur le socket */ void Client::dataHandler() { for(int k=0; k<BUFFSIZE; k++) buff[k] = '\0'; if(FD_ISSET(socketDesc, &toListen)) { int rec_res = recv(socketDesc, buff, BUFFSIZE, 0); if(rec_res == 0) { close(socketDesc); cout << "Deconnexion: Le serveur semble ne pas etre lance" << endl; stop(); } else if(rec_res > 0) { FString req(buff); FString cmd = req.getCmd(); FString arg = req.getArgs(); if(cmd.compare("UPDATE") == 0) { if(arg.compare("ALL") == 0) { update(); } } else cout << "Recu: " << buff << endl; } } } /** Traitement des données sur l'entrée standard */ void Client::stdinHandler() { if(FD_ISSET(0, &toListen)) { int rec_res = read(0, buff, BUFFSIZE); if(rec_res > 0) { // on enlève le '\n' à la fin for(int i=0; i<BUFFSIZE; i++) { if(buff[i] == '\n') { buff[i] = '\0'; i = BUFFSIZE; } } if(strcmp("",buff) != 0) { processCmd(buff); } } } } /** Methode permettant d'envoyer un message et de se mettre en attente */ FString Client::sendAndWait(FString request) { for(int k=0; k<BUFFSIZE; k++) buff[k] = '\0'; send(socketDesc, request.data(), request.size(), 0); cout << "Attente du serveur..." << endl; recv(socketDesc, buff, BUFFSIZE, 0); return FString(buff); } /** Boucle d'exécution de l'application Client. */ void Client::runLoop() { struct timeval timeout; while(activate) { showPrompt(); for(int k=0; k<BUFFSIZE; k++) buff[k] = '\0'; FD_ZERO(&toListen); FD_SET(socketDesc, &toListen); FD_SET(0, &toListen); int descMax = max(0, socketDesc); timeout.tv_sec = 1; timeout.tv_usec = 0; int sel_res = select(descMax+1, &toListen, NULL, NULL, NULL); if(sel_res > 0) { dataHandler(); stdinHandler(); } } connected = false; } void Client::update() { FString str = sendAndWait("DETAILS ALL"); } /** Renvoie true si la connexion au serveur est active, false sinon. */ bool Client::isConnected() { return connected; } /** Destructeur */ Client::~Client() { }
01lut
branches/test2/src/client.cpp
C++
gpl3
3,245
clientCmd.o: src/clientCmd.cpp src/client.hpp src/log.hpp src/fstring.hpp \ src/prompt.hpp
01lut
branches/test2/clientCmd.d
Makefile
gpl3
92
fstring.o: src/fstring.cpp src/fstring.hpp
01lut
branches/test2/fstring.d
Makefile
gpl3
43
prompt.o: src/prompt.cpp src/prompt.hpp src/fstring.hpp
01lut
branches/test2/prompt.d
Makefile
gpl3
56
client.o: src/client.cpp src/client.hpp src/log.hpp src/fstring.hpp \ src/prompt.hpp
01lut
branches/test2/client.d
Makefile
gpl3
86
serverCmd.o: src/serverCmd.cpp src/server.hpp src/prompt.hpp \ src/fstring.hpp src/log.hpp src/user.hpp
01lut
branches/test2/serverCmd.d
Makefile
gpl3
105
server.o: src/server.cpp src/server.hpp src/prompt.hpp src/fstring.hpp \ src/log.hpp src/user.hpp
01lut
branches/test2/server.d
Makefile
gpl3
99
user.o: src/user.cpp src/user.hpp src/fstring.hpp
01lut
branches/test2/user.d
Makefile
gpl3
50
# Freddy Teuma - 30 novembre 2009 # -Modification du makefile- CXX = g++ -Wall LD = g++ SRC_PATH = src SERV_SRC = serverCmd.cpp \ server.cpp \ prompt.cpp \ fstring.cpp \ user.cpp \ log.cpp CLI_SRC = clientCmd.cpp\ client.cpp \ prompt.cpp \ fstring.cpp BIN = serverCmd clientCmd SERV_OBJ = $(SERV_SRC:.cpp=.o) CLI_OBJ = $(CLI_SRC:.cpp=.o) DEP = $(CLI_SRC:.cpp=.d) \ $(SERV_SRC:.cpp=.d) %.o: $(SRC_PATH)/%.cpp $(CXX) -g -o $@ -c $< %.d: $(SRC_PATH)/%.cpp $(CXX) $< -MM -o $@ all: $(BIN) serverCmd: $(SERV_OBJ) $(LD) -o $@ $+ clientCmd: $(CLI_OBJ) $(LD) -o $@ $+ clean: @rm *.o *.d @rm *.log # $rm $(BIN) cleanpdf: @rm *.d *.aux *.idx *.lof *.log *.toc -include $(DEP)
01lut
branches/test2/Makefile
Makefile
gpl3
726
#include "log.hpp" Log::Log(FString path) { if((file = open(path.data(), O_WRONLY|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR))<0) { cout << "Cannot open log file" << endl; } } Log::~Log() { close(file); } void Log::logger(FString data) { FString str = dateLog(); str.erase(str.size()-1, 1); str += "\t"; str += data; str += " \n"; write(file, str.data(), str.size()); } FString Log::dateLog() { time_t t = time(NULL); char *dateLogs = asctime(localtime(&t)); return FString(dateLogs); }
01lut
trunk/src/log.cpp
C++
gpl3
499
#include <iostream> #include <arpa/inet.h> #include <netdb.h> #include <netinet/in.h> #include <unistd.h> #include <sys/select.h> #include <sys/types.h> #include <time.h> #include "prompt.hpp" #include "log.hpp" #include "fstring.hpp" #include "user.hpp" #define BUFFSIZE 100000 #define CMAX 990 using namespace std; /* * Cette classe représente le serveur */ class Server : public Prompt { public: Server(int port = 1888, FString logDir = "/var/log/01lut/"); ~Server(); void start(); void stop(); private: char buff[BUFFSIZE]; bool activate; Log *logMsg; Log *logSvr; int lport; int sockServer; sockaddr_in serverAddress; int highestSock; fd_set socksToListen; // int clients[CMAX]; User* clients[CMAX]; int nbClients; void initList(); void runLoop(); void readSocks(); void forwardFrom(int from, FString str); void forward(FString str); void handleRequest(User *cli, char *request); void sendMsg(User *cli, FString msg); int checkSocket(int id); User* findClient(int id); void alertClients(); };
01lut
trunk/src/server.hpp
C++
gpl3
1,044
#include "user.hpp" User::User(int sock) { this->sock = sock; name = "Anonymous"; registered = false; } User::~User() { } int User::getSock() { return sock; } FString User::getName() { return this->name; } void User::setName(FString str) { this->name = str; } void User::registerMe() { registered = true; } bool User::isRegistered() { return registered; }
01lut
trunk/src/user.cpp
C++
gpl3
372
#include "prompt.hpp" /** Constructeur de Prompt */ Prompt::Prompt() : welcome(true) { } /** Destructeur de l'objet */ Prompt::~Prompt() { } /** Les méthodes qui suivent doivent être redéfinies dans les classes dérivées. Ici est simplement définit un comportement par défaut pour chacune d'entre elles, comportement qui sera redéfinit dans les classes dérivées. */ /** Cette méthode associe chaque commande à une fonction */ void Prompt::processCmd(char *cmd) { if(strcmp(cmd, "quit") == 0) { stop(); } else { cout << "Erreur: Commande inconnue : " << cmd << endl; } } /** Affichage du prompt, indiquant à l'utilisateur qu'il a la main pour entrer des commandes sur l'entrée standard */ void Prompt::showPrompt() { if(welcome) cout << "(type quit to quit)" << endl; cout << "> "; cout.flush(); welcome = false; }
01lut
trunk/src/prompt.cpp
C++
gpl3
862
#ifndef USER_H #define USER_H #include "fstring.hpp" class User { public: User(int sock); ~User(); FString getName(); int getSock(); void setName(FString str); bool isRegistered(); void registerMe(); private: FString name; int sock; bool registered; }; #endif
01lut
trunk/src/user.hpp
C++
gpl3
284
#include "person.hpp" Person::Person(int _sock) { sock = _sock; name = "Sans nom"; } Person::~Person() { } Person::setName(FString n) { name = n; }
01lut
trunk/src/person.cpp
C++
gpl3
156
#ifndef FRONTEND_H #define FRONTEND_H /* Cette classe fournit une interface à un backend client (voire serveur) */ #include "fstring.hpp" class Frontend { public: Frontend(){}; virtual void updateBids() = 0; virtual void serverReady() = 0; }; #endif
01lut
trunk/src/frontend.hpp
C++
gpl3
267
#include "fstring.hpp" // TEST class Person { public: Person(int _sock); ~Person(); void setName(FString n); private: FString name; int sock; }
01lut
trunk/src/person.hpp
C++
gpl3
160
#include "server.hpp" #include "fstring.hpp" #include <unistd.h> #include <stdio.h> int main(int argc, char** argv) { int port = 1888; FString logDir = "/var/log/"; char c; FString str; while( (c = getopt(argc, argv, "p:d:")) != EOF ) { switch(c) { case 'p': str = optarg; port = str.toInt(); break; case 'd': logDir = optarg; break; } } Server s(port, logDir); s.start(); return 0; }
01lut
trunk/src/serverCmd.cpp
C++
gpl3
433
#ifndef LOG_H #define LOG_H #include <iostream> #include "fstring.hpp" #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> using namespace std; class Log { public: Log(FString path); ~Log(); void logger(FString data); private: int file; FString dateLog(); }; #endif
01lut
trunk/src/log.hpp
C++
gpl3
329
#include "fstring.hpp" #include <sstream> /** Constructeur de la classe Permet de créer un objet de type FString */ FString::FString() : std::string() { } /** Constructeur de la classe Permet de créer un objet de type FString à partir d'une chaine de caractere */ FString::FString(const char *s) : std::string(s) { } /** Methode qui permet de couper une chaine de caractere dans un tableau dynamique en deux parties Le separateur de type caractere est la partie referente pour le decoupage Cette methode retourne un vector contenant les différentes partie de la chaine coupée */ std::vector<FString> FString::split(char separator) { std::vector<FString> parts; unsigned int i = 0; parts.push_back(FString()); while(i < size()) { if(data()[i] == separator) { parts.push_back(FString()); } else { parts.back().push_back(data()[i]); } i++; } return parts; } /** Cette methode permet d'isoler la premiere partie d'un message qui contient la commande à executer */ FString FString::getCmd() { return split(' ').at(0); } /** Cette methode permet de recuperer les arguments d'une requête */ FString FString::getArgs() { FString args(data()); while(args.size() && args.data()[0] != ' ') { args.erase(0, 1); } if(args.data()[0] == ' ') args.erase(0, 1); // efface espace return args; } /** [static] Cette methode permet de changer un entier en une chaine de caractère */ FString FString::fromInt(int i) { std::stringstream ss; ss << i; FString str; ss >> str; return str; } /** [static] Cette methode permet de changer un float en une chaine de caractère */ FString FString::fromFloat(float i) { std::stringstream ss; ss << i; FString str; ss >> str; return str; } /** Retourne la valeur entière représentée par la chaîne */ int FString::toInt() { std::stringstream ss(this->data()); int ret; ss >> ret; return ret; } void FString::removeChar(char c) { for(unsigned int i=0; i<size(); i++) { if(data()[i] == c) { erase(1,i); i--; } } }
01lut
trunk/src/fstring.cpp
C++
gpl3
2,061
#ifndef FSTRING_HPP #define FSTRING_HPP /** 01/12/2009 -- Cette classe représente une std::string sur laquelle une méthode split() peut être appelée -> Créée pour simplifier l'interprétations des requêtes Ne pas hésiter à rajouter des méthodes qui simplifient l'usage des chaînes de caractères */ #include <string> #include <vector> class FString : public std::string { public: FString(); FString(const char *s); std::vector<FString> split(char separator); FString getCmd(); FString getArgs(); int toInt(); static FString fromInt(int i); static FString fromFloat(float i); void removeChar(char c); }; #endif
01lut
trunk/src/fstring.hpp
C++
gpl3
651
#include <iostream> #include <netdb.h> #include <netinet/in.h> #include <unistd.h> #include "log.hpp" #include "fstring.hpp" #include "prompt.hpp" #define BUFFSIZE 512 using namespace std; class Client : public Prompt { public: Client(const char* adresse); ~Client(); void start(); void stop(); void update(); bool isConnected(); private: bool activate; char buff[512]; int dport; int socketDesc; fd_set toListen; char* addressServer; sockaddr_in serverAddress; hostent *hostInfo; bool connected; void runLoop(); void stdinHandler(); void dataHandler(); FString sendAndWait(FString request); };
01lut
trunk/src/client.hpp
C++
gpl3
651
#include "client.hpp" /** Permet de lancer un client en mode Shell **/ int main(int argc, char **argv) { FString adresse = ""; if(argc > 1) adresse += argv[1]; if(adresse.compare("") == 0) { adresse = "127.0.0.1"; } Client c(adresse.data()); c.start(); return 0; }
01lut
trunk/src/clientCmd.cpp
C++
gpl3
281
#include <cstdio> #include "server.hpp" /** Constructeur d'un objet Serveur */ Server::Server(int port, FString logDir) { nbClients = 0; lport = port; activate = false; for(int i=0; i<CMAX; i++) clients[i] = 0; // set the address structure serverAddress.sin_family = AF_INET; serverAddress.sin_addr.s_addr = htonl(INADDR_ANY); serverAddress.sin_port = htons(lport); FString logFile = logDir; logFile += "/msg.log"; FString logFile2 = logDir; logFile2 += "/server.log"; logMsg = new Log(logFile); logSvr = new Log(logFile2); } /** Destructeur de l'objet Serveur */ Server::~Server() { } /** Methode permettant de demarrer le serveur */ void Server::start() { activate = true; // Creation du socket server // sockServer = socket(AF_INET, SOCK_STREAM, 0); sockServer = socket(AF_INET, SOCK_STREAM, 0); int somerandomint = 1; setsockopt(sockServer, SOL_SOCKET, SO_REUSEADDR, &somerandomint, sizeof(int)); if(sockServer > 0) { // bind du socket int bResult = bind(sockServer, (struct sockaddr *) &serverAddress, sizeof(serverAddress)); if(bResult < 0) { cout << "\t\t\tFail !" << endl; cout << "Connexion error" << endl; close(sockServer); } else { listen(sockServer, CMAX); cout << "Starting server..." << endl; cout << ":: Server is listening on port " << lport << endl; FString log = "Server started on port "; log += FString::fromInt(lport); logSvr->logger(log); highestSock = sockServer; runLoop(); } } else { cout << "\t\t\tFail !" << endl; cout << "can't create socket" << endl; } } /** Methode permettant d'arreter proprement le serveur */ void Server::stop() { activate = false; cout << "Stopping server...\t\t\tOK" << endl; FString log = "Server stopped"; logSvr->logger(log); } /** Crée la liste des descripteurs à écouter */ void Server::initList() { /* on commence par ajouter l'entrée standard */ FD_ZERO(&socksToListen); FD_SET(sockServer, &socksToListen); FD_SET(0, &socksToListen); /* puis on ajoute chaque socket de client */ for(int i=0; i<CMAX; i++) { if(clients[i] != 0) { FD_SET(clients[i]->getSock(), &socksToListen); if(clients[i]->getSock() > highestSock) highestSock = clients[i]->getSock(); } } } /** Lis les différents descripteurs de fichiers afin d'y récuprérer les informations présentes */ void Server::readSocks() { /* tentative de connexion */ if(FD_ISSET(sockServer, &socksToListen)) { cout << "\n::Un nouveau client essaye de se connecter..."; int connect = accept(sockServer, NULL, NULL); if(connect < 0) { cout << "\t\tEchoue!" << endl; } else { for(int i=0; i<CMAX; i++) { if(clients[i] == 0) { clients[i] = new User(connect); nbClients++; FString str("YID "); str += FString::fromInt(connect); sendMsg(clients[i], str); cout << "\t\tOK" << endl; cout << " -> assigne a " << i << endl; FString log = "New client connected on slot"; log += FString::fromInt(i); logSvr->logger(log); showPrompt(); return; } } /* si on arrive ici, c'est qu'il n'y a plus de place */ close(connect); cout << "\t\t\tEchoue!" << endl; } } /* evenements sur stdin */ if(FD_ISSET(0, &socksToListen)) { if(read(0, buff, BUFFSIZE)) { // on enlève le '\n' à la fin for(int i=0; i<BUFFSIZE; i++) { if(buff[i] == '\n') { buff[i] = '\0'; i = BUFFSIZE; // Bourrin : pour sortir :) } } if(strcmp("",buff) != 0) { processCmd(buff); } } } /* autres evenements */ for(int i=0; i<CMAX; i++) { if(clients[i] && FD_ISSET(clients[i]->getSock(), &socksToListen)) { int rec_res = recv(clients[i]->getSock(), buff, BUFFSIZE, 0); /* un client se deconnecte */ if(rec_res == 0) { FString log = "Client "; log += clients[i]->getName(); log += " has left"; logSvr->logger(log); cout << "\n::Client n°" << i << " a quitte" << endl; FString str("LEAVE "); str += FString::fromInt(clients[i]->getSock()); close(clients[i]->getSock()); delete clients[i]; clients[i] = 0; // avoid hole in tab for(int k=i; k<nbClients; k++) clients[k] = clients[k+1]; nbClients--; forward(str); } else if(rec_res > 0) { cout << "\n::Reçu: " << buff << endl; cout << " du client n°" << i << endl; FString log = "From slot"; log += FString::fromInt(i)+": "+buff; logSvr->logger(log); handleRequest(clients[i], buff); } } } showPrompt(); } /** Methode permettant d'envoyer un message à tous les clients inscrits sauf à celui qui a envoyé le message */ void Server::forwardFrom(int from, FString str) { for(int i=0; i<nbClients; i++) { if(clients[i] && from != clients[i]->getSock()) sendMsg(clients[i], str); } } /** Envoyer un message à tous les clients */ void Server::forward(FString str) { for(int i=0; i<nbClients; i++) { if(clients[i]) { sendMsg(clients[i], str); } } } void Server::sendMsg(User *cli, FString msg) { msg += EOF; send(cli->getSock(), msg.data(), msg.size(), 0); } /** Methode permettant de traiter une information envoyée par un client */ void Server::handleRequest(User *cli, char *request) { FString req(request); FString cmd = req.getCmd(); FString arg = req.getArgs(); /* traitement de la requete INFO */ if(cmd.compare("LIST") == 0) { FString str("LIST "); for(int i=0; i<nbClients; i++) { str += FString::fromInt(clients[i]->getSock()) + " "; str += clients[i]->getName()+" ; "; } sendMsg(cli, str); } /* traitement de la requete MSG */ else if(cmd.compare("MSG") == 0) { FString str; str += cmd + " " + FString::fromInt(cli->getSock()) + " " + arg; forwardFrom(cli->getSock(), str); FString log = "From "; log += cli->getName() + " : " + arg ; logMsg->logger(log); } /* privates msg */ else if(cmd.compare("PMSG") == 0) { FString msg = arg; int idUser = msg.getCmd().toInt(); cout << "--- " << msg << endl; idUser = checkSocket(idUser); if(idUser > 0) { FString str("PMSG "); str += FString::fromInt(cli->getSock())+" "+msg.getArgs(); User *to = findClient(idUser); if(to) sendMsg(to, str); } } /* traitement de la requete DETAILS */ else if(cmd.compare("NICK") == 0) { FString nick = arg.getCmd(); if(nick.compare("") != 0) { cli->setName(nick); if(cli->isRegistered()) { FString str("NICK "); str += FString::fromInt(cli->getSock()) + " " + nick; forward(str); } else { FString str("NC "); str += nick; forward(str); cli->registerMe(); } } } } /** Boucle d'exécution du serveur on y écoute les différents sockets */ void Server::runLoop() { int nbSocksToRead; struct timeval timeout; showPrompt(); while(activate) { for(int k=0; k<BUFFSIZE; k++) //Initialisation du buffer buff[k] = '\0'; initList(); timeout.tv_sec = 1; timeout.tv_usec = 0; nbSocksToRead = select(highestSock+1, &socksToListen, NULL, NULL, &timeout); if(nbSocksToRead > 0) { readSocks(); } alertClients(); } } /** Check if a socket is registered in client lists returns socket descriptor if exists, -1 if it doesn't */ int Server::checkSocket(int id) { for(int i=0; i<nbClients; i++) { if(clients[i]->getSock() == id) return id; } return -1; } User* Server::findClient(int id) { for(int i=0; i<nbClients; i++) { if(clients[i]->getSock() == id) return clients[i]; } return 0; } /** Methode qui permet d'alerter les clients que une enchere est terminée */ void Server::alertClients() { }
01lut
trunk/src/server.cpp
C++
gpl3
7,700
#ifndef PROMPT_H #define PROMPT_H /** Freddy Teuma - 28/11/2009 -- Cette classe permet de faire l'interface entre une commande et une action. Dériver cette classe et implémenter les méthodes abstraites. */ #include <iostream> #include <string.h> #include "fstring.hpp" using namespace std; class Prompt { public: Prompt(); ~Prompt(); virtual void start() = 0; virtual void stop() = 0; void showPrompt(); void processCmd(char *cmd); private: bool welcome; }; #endif
01lut
trunk/src/prompt.hpp
C++
gpl3
500
#include "client.hpp" #include <sstream> /** Constructeur de la classe */ Client::Client(const char* adresse) { dport = 1888; activate = false; connected = false; hostInfo = gethostbyname(adresse); addressServer = (char*)adresse; if(hostInfo != NULL) { serverAddress.sin_family = hostInfo->h_addrtype; memcpy((char *) &serverAddress.sin_addr.s_addr, hostInfo->h_addr_list[0], hostInfo->h_length); serverAddress.sin_port = htons(dport); } } /** Démarre le client : On se connecte au serveur puis on entre dans la boucle d'exécution si la connexion a réussi : voir runLopp(); */ void Client::start() { activate = true; cout << "::Connexion au serveur " << addressServer; socketDesc = socket(AF_INET, SOCK_STREAM, 0); if(socketDesc <= 0) { cout << "\t\t\tEchoue!" << endl; } else { if(connect(socketDesc, (sockaddr*) &serverAddress, sizeof(sockaddr)) == -1) { cout << "\t\t\tEchoue!" << endl; } else { cout << "\t\t\tOK" << endl; /* init the list to listen */ connected = true; runLoop(); } } } /** Termine l'exécution */ void Client::stop() { activate = false; } /** Traitement des données reçues sur le socket */ void Client::dataHandler() { for(int k=0; k<BUFFSIZE; k++) buff[k] = '\0'; if(FD_ISSET(socketDesc, &toListen)) { int rec_res = recv(socketDesc, buff, BUFFSIZE, 0); if(rec_res == 0) { close(socketDesc); cout << "Deconnexion: Le serveur semble ne pas etre lance" << endl; stop(); } else if(rec_res > 0) { FString req(buff); FString cmd = req.getCmd(); FString arg = req.getArgs(); if(cmd.compare("UPDATE") == 0) { if(arg.compare("ALL") == 0) { update(); } } else cout << "Recu: " << buff << endl; } } } /** Traitement des données sur l'entrée standard */ void Client::stdinHandler() { if(FD_ISSET(0, &toListen)) { int rec_res = read(0, buff, BUFFSIZE); if(rec_res > 0) { // on enlève le '\n' à la fin for(int i=0; i<BUFFSIZE; i++) { if(buff[i] == '\n') { buff[i] = '\0'; i = BUFFSIZE; } } if(strcmp("",buff) != 0) { processCmd(buff); } } } } /** Methode permettant d'envoyer un message et de se mettre en attente */ FString Client::sendAndWait(FString request) { for(int k=0; k<BUFFSIZE; k++) buff[k] = '\0'; send(socketDesc, request.data(), request.size(), 0); cout << "Attente du serveur..." << endl; recv(socketDesc, buff, BUFFSIZE, 0); return FString(buff); } /** Boucle d'exécution de l'application Client. */ void Client::runLoop() { struct timeval timeout; while(activate) { showPrompt(); for(int k=0; k<BUFFSIZE; k++) buff[k] = '\0'; FD_ZERO(&toListen); FD_SET(socketDesc, &toListen); FD_SET(0, &toListen); int descMax = max(0, socketDesc); timeout.tv_sec = 1; timeout.tv_usec = 0; int sel_res = select(descMax+1, &toListen, NULL, NULL, NULL); if(sel_res > 0) { dataHandler(); stdinHandler(); } } connected = false; } void Client::update() { FString str = sendAndWait("DETAILS ALL"); } /** Renvoie true si la connexion au serveur est active, false sinon. */ bool Client::isConnected() { return connected; } /** Destructeur */ Client::~Client() { }
01lut
trunk/src/client.cpp
C++
gpl3
3,245
clientCmd.o: src/clientCmd.cpp src/client.hpp src/log.hpp src/fstring.hpp \ src/prompt.hpp
01lut
trunk/clientCmd.d
Makefile
gpl3
92
#include "LutController.h" #include "MainWindow.h" #include <QtDebug> LutController *LutController::instance = 0; LutController::LutController() { users = new UserList(this); window = new MainWindow(); } LutController* LutController::getInstance() { if(!instance) instance = new LutController(); ; return instance; } void LutController::startApp() { window->initMainWindow(); window->show(); } bool LutController::getShowTime() { return window->getShowTime(); } int LutController::myId() { return window->myId(); } QString LutController::getNameFromId(int id) { return users->getNameById(id); } void LutController::sendMsg(QString str) { window->sendMsg(str); } void LutController::sendPrivateMsg(int to, QString str) { window->sendPrivateMsg(to, str); } void LutController::onQuitReq() { emit quitMe(); } UserList* LutController::getUsers() { return users; }
01lut
trunk/ClientQt/LutController.cpp
C++
gpl3
886
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtNetwork> #include <QSystemTrayIcon> #include <QSettings> #include <QListWidgetItem> #include "LutController.h" #include "User.h" class DiscussPane; namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void sendMsg(QString str); void sendPrivateMsg(int to, QString str); int myId(); void initMainWindow(); bool getShowTime(); private: Ui::MainWindow *ui; QTcpSocket *sock; QString nickname; int id; QSystemTrayIcon *trayIcon; QIcon *icon; QIcon *iconWarn; bool event ( QEvent * event ); DiscussPane *findPaneById(int id); void majUserList(QStringList list); void majUser(QString data); bool notifications; bool showTime; QSettings settings; DiscussPane *mainPane; QList<DiscussPane*> *privatePanes; QString serverIP; int serverPort; QAction *exitAct; QMenu *menuTray; private slots: void on_actionClear_triggered(); void on_actionShow_time_toggled(bool v); void on_actionShow_time_triggered(); void on_actionClose_current_tab_triggered(); void on_actionNotifications_toggled(bool v); void on_actionChange_server_triggered(); void on_actionChange_nickname_triggered(); void onExitAct(); void onTrayClicked(QSystemTrayIcon::ActivationReason r); void errorReceived(QAbstractSocket::SocketError socketError); void onConnected(); void dataHandler(); void onItemDoubleClicked(QModelIndex index); void onTabChanged(int id); void onToRead(DiscussPane *p); }; #endif // MAINWINDOW_H
01lut
trunk/ClientQt/MainWindow.h
C++
gpl3
1,620
#ifndef USERLIST_H #define USERLIST_H #include <QAbstractListModel> #include "User.h" class UserList : public QAbstractListModel { Q_OBJECT public: explicit UserList(QObject *parent = 0); QVariant data(const QModelIndex &index, int role) const; int rowCount(const QModelIndex &parent) const; Qt::ItemFlags flags(const QModelIndex &index) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); bool insertRow(int row, const QModelIndex &parent); bool removeRow(int row, const QModelIndex &parent); // usermade :) void addOrReplace(User *u); QString getNameById(int id); void removeRowById(int id); void clear(); private: QList<User *> *users; signals: public slots: }; #endif // USERLIST_H
01lut
trunk/ClientQt/UserList.h
C++
gpl3
766
#------------------------------------------------- # # Project created by QtCreator 2010-11-17T19:24:13 # #------------------------------------------------- QT += core gui network TARGET = ClientQt TEMPLATE = app SOURCES += main.cpp\ MainWindow.cpp \ User.cpp \ DiscussPane.cpp \ LutController.cpp \ UserList.cpp HEADERS += MainWindow.h \ User.h \ DiscussPane.h \ LutController.h \ UserList.h FORMS += MainWindow.ui \ DiscussPane.ui RESOURCES += \ resources.qrc
01lut
trunk/ClientQt/ClientQt.pro
QMake
gpl3
518
#include "User.h" User::User(int id, QString name) : id(id), name(name) { } User::User(QString data) { QStringList infos = data.split(" "); id = infos.at(0).toInt(); name = infos.at(1); } int User::getId() { return id; } QString User::getName() { return name; } void User::setId(int val) { id = val; } void User::setName(QString n) { this->name = n; }
01lut
trunk/ClientQt/User.cpp
C++
gpl3
369
#include <QtGui/QApplication> #include "LutController.h" int main(int argc, char *argv[]) { QApplication *a = new QApplication(argc, argv); a->setQuitOnLastWindowClosed(false); LutController *ctrl = LutController::getInstance(); QApplication::connect(ctrl, SIGNAL(quitMe()), a, SLOT(quit())); ctrl->startApp(); return a->exec(); }
01lut
trunk/ClientQt/main.cpp
C++
gpl3
344
#include "UserList.h" #include "LutController.h" UserList::UserList(QObject *parent) : QAbstractListModel(parent) { users = new QList<User*>(); } QVariant UserList::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.row() >= users->size()) return QVariant(); if (role == Qt::DisplayRole || role == Qt::EditRole) return users->at(index.row())->getName(); if (role == Qt::UserRole) return users->at(index.row())->getId(); if (role == Qt::ForegroundRole) { if(LutController::getInstance()->myId() == users->at(index.row())->getId()) return Qt::darkRed; return Qt::darkBlue; } else return QVariant(); } int UserList::rowCount(const QModelIndex &) const { return users->size(); } Qt::ItemFlags UserList::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::ItemIsEnabled; return QAbstractListModel::flags(index); } bool UserList::insertRow(int row, const QModelIndex &parent) { beginInsertRows(parent, row, row); users->insert(row, new User(-1, "")); endInsertRows(); return true; } bool UserList::removeRow(int row, const QModelIndex &parent) { beginRemoveRows(parent, row, row); users->removeAt(row); endRemoveRows(); return true; } bool UserList::setData(const QModelIndex &index, const QVariant &value, int role) { if(index.isValid() && role == Qt::EditRole) { users->at(index.row())->setName(value.toString()); emit dataChanged(index, index); return true; } else if(index.isValid() && role == Qt::UserRole) { users->at(index.row())->setId(value.toInt()); emit dataChanged(index, index); return true; } else return false; } void UserList::addOrReplace(User *u) { User *existing = 0; int i = 0; while(i<users->size() && !existing) { if(users->at(i)->getId() == u->getId()) { existing = users->at(i); existing->setName(u->getName()); emit dataChanged(index(0, 0), index(users->size()-1, 0)); } i++; } if(!existing) { insertRow(users->size(), QModelIndex()); setData(index(users->size()-1, 0), u->getId(), Qt::UserRole); setData(index(users->size()-1, 0), u->getName(), Qt::EditRole); } } void UserList::clear() { users->clear(); emit dataChanged(index(0, 0), index(users->size()-1, 0)); } void UserList::removeRowById(int id) { int i = 0; while(i<users->size()) { if(users->at(i)->getId() == id) { users->removeAt(i); emit dataChanged(index(0, 0), index(users->size()-1, 0)); } i++; } } QString UserList::getNameById(int id) { int i = 0; while(i<users->size()) { if(users->at(i)->getId() == id) return users->at(i)->getName(); i++; } return ""; }
01lut
trunk/ClientQt/UserList.cpp
C++
gpl3
2,654
#include "DiscussPane.h" #include "ui_DiscussPane.h" #include "LutController.h" DiscussPane::DiscussPane(int gid, QWidget *parent) : QWidget(parent), ui(new Ui::DiscussPane), guyId(gid) { ui->setupUi(this); ui->textBrowser->setOpenExternalLinks(true); connect(ui->lineEdit, SIGNAL(returnPressed()), ui->pushButton, SIGNAL(clicked())); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(sendMsg())); } DiscussPane::~DiscussPane() { delete ui; } void DiscussPane::displayInfo(QString str) { ui->textBrowser->setTextColor(Qt::gray); ui->textBrowser->insertPlainText(str); moveToBottom(); } void DiscussPane::clearPane() { ui->textBrowser->clear(); moveToBottom(); } void DiscussPane::displayError(QString str) { ui->textBrowser->setTextColor(Qt::red); ui->textBrowser->insertPlainText(str); moveToBottom(); } void DiscussPane::displayMsg(int from, QString str) { moveToBottom(); if(LutController::getInstance()->getShowTime()) { QTime ct = QTime::currentTime(); ui->textBrowser->setFontWeight(QFont::Normal); ui->textBrowser->setTextColor(Qt::gray); ui->textBrowser->insertPlainText("("+ QString((ct.hour()<10) ? "0":"") + QString::number(ct.hour()) +":"+ ((ct.minute()<10) ? "0":"") + QString::number(ct.minute()) +":"+ ((ct.second()<10) ? "0":"") +QString::number(ct.second())+") "); } ui->textBrowser->setFontWeight(QFont::Bold); ui->textBrowser->setTextColor(Qt::darkBlue); if(from == LutController::getInstance()->myId()) ui->textBrowser->setTextColor(Qt::darkRed); ui->textBrowser->insertPlainText(LutController::getInstance()->getNameFromId(from) + ": "); ui->textBrowser->setFontWeight(QFont::Normal); str.replace(":)", "<img src=\":/img/sourire.gif\" alt='' title=\":)\" />"); str.replace(":(", "<img src=\":/img/triste.gif\" alt='' title=\":(\" />"); str.replace(":D", "<img src=\":/img/D.gif\" alt='' title=\":D\" />"); str.replace(":nerd:", "<img src=\":/img/nerd.gif\" alt='' title=\":nerd:\" />"); str.replace(";)", "<img src=\":/img/clin_oeil.gif\" alt='' title=\";)\" />"); str.replace(":p", "<img src=\":/img/p.gif\" alt='' title=\":p\" />"); str.replace(QRegExp("<(?!(img.*>))"), "&lt;"); str.replace(QRegExp("(https?://[^ ]*)"), "<a href='\\1'>\\1</a> "); str.replace("%E2%82%AC", QChar(8364)); str.replace("\n", "<br />"); ui->textBrowser->insertHtml(str); ui->textBrowser->setTextColor(Qt::black); ui->textBrowser->setFontUnderline(false); ui->textBrowser->insertPlainText("\n"); moveToBottom(); emit toRead(this); } bool DiscussPane::isPrivate() { return (guyId >= 0); } void DiscussPane::sendMsg() { moveToBottom(); if(ui->lineEdit->text().size() > 0) { if(!isPrivate()) { LutController::getInstance()->sendMsg(ui->lineEdit->text()); } else { LutController::getInstance()->sendPrivateMsg(guyId, ui->lineEdit->text()); } displayMsg(LutController::getInstance()->myId(), ui->lineEdit->text()); } ui->lineEdit->clear(); } int DiscussPane::getGuyId() { return guyId; } void DiscussPane::setGuyId(int val) { guyId = val; } void DiscussPane::moveToBottom() { ui->textBrowser->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); }
01lut
trunk/ClientQt/DiscussPane.cpp
C++
gpl3
3,190
#ifndef USER_H #define USER_H #include <QString> #include <QStringList> class User // : public QListWidgetItem { public: User(int id, QString name); User(QString data); int getId(); QString getName(); void setId(int val); void setName(QString n); private: int id; QString name; }; #endif // USER_H
01lut
trunk/ClientQt/User.h
C++
gpl3
313
#include "MainWindow.h" #include "ui_MainWindow.h" #include <QInputDialog> #include <QStringList> #include <QUrl> #include "DiscussPane.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), nickname("Anonymous"), settings("01Lut", "01Lut") { setAttribute(Qt::WA_DeleteOnClose, false); privatePanes = new QList<DiscussPane*>(); mainPane = new DiscussPane(-1, this); connect(mainPane, SIGNAL(toRead(DiscussPane*)), this, SLOT(onToRead(DiscussPane*))); icon = new QIcon(":/img/icon.png"); iconWarn = new QIcon(":/img/iconW.png"); trayIcon = new QSystemTrayIcon(*icon); this->setWindowIcon(*icon); trayIcon->show(); QDir home = QDir::home(); nickname = settings.value("nickname", home.dirName()).toString(); serverIP = settings.value("server", "127.0.0.1").toString(); serverPort = settings.value("port", 1888).toInt(); showTime = settings.value("time", true).toBool(); QString tmp = settings.value("server").toString(); if(tmp.size() < 1) { QString ipServer = QInputDialog::getText(this, "server address", "Server address :", QLineEdit::Normal, "127.0.0.1:1888"); QStringList serverInfos = ipServer.split(":"); if(serverInfos.size()>1) serverPort = serverInfos.at(1).toInt(); settings.setValue("server", serverInfos.at(0)); settings.setValue("port", serverPort); serverIP = serverInfos.at(0); } ui->setupUi(this); exitAct = new QAction("Quit", this); exitAct->setShortcut(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(onExitAct())); ui->menuTools->addAction(exitAct); menuTray= new QMenu("01Lut"); menuTray->addAction(exitAct); trayIcon->setContextMenu(menuTray); sock = new QTcpSocket(this); connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorReceived(QAbstractSocket::SocketError))); connect(sock, SIGNAL(readyRead()), this, SLOT(dataHandler())); connect(sock, SIGNAL(connected()), this, SLOT(onConnected())); QString str = "Connecting to server at "; str += serverIP + " on port " + QString::number(serverPort) + "\n"; mainPane->displayInfo(str); sock->connectToHost(serverIP, serverPort); connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabChanged(int))); connect(ui->listWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onItemDoubleClicked(QModelIndex))); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onTrayClicked(QSystemTrayIcon::ActivationReason))); notifications = settings.value("notifications", true).toBool(); ui->actionNotifications->setChecked(notifications); ui->actionShow_time->setChecked(showTime); QHBoxLayout *l = static_cast<QHBoxLayout*>(ui->mainTab->layout()); l->insertWidget(0, mainPane, 6); l->setStretch(1, 1); onTabChanged(0); } bool MainWindow::getShowTime() { return showTime; } void MainWindow::initMainWindow() { ui->listWidget->setModel(LutController::getInstance()->getUsers()); } void MainWindow::onTabChanged(int id) { if(id>0) { ui->actionClose_current_tab->setEnabled(true); } else { ui->actionClose_current_tab->setEnabled(false); } ui->tabWidget->setTabIcon(id, QIcon()); } MainWindow::~MainWindow() { delete ui; } void MainWindow::errorReceived(QAbstractSocket::SocketError socketError) { QString str; if(socketError == QAbstractSocket::ConnectionRefusedError) { str = "::Cannot connect to server... Aborting.\n"; } else { str =":: Server error\n"; } mainPane->displayError(str); for(int i=0; i<privatePanes->size(); i++) { privatePanes->at(i)->displayError(str); } this->activateWindow(); } void MainWindow::sendMsg(QString str) { if(str.size() > 0) { QByteArray data = "MSG "; str.replace(QChar(8364), "%E2%82%AC"); data.append(str); sock->write(data); } } void MainWindow::sendPrivateMsg(int to, QString str) { if(str.size() > 0) { QByteArray data = "PMSG "; data.append(QString::number(to)+" "); str.replace(QChar(8364), "%E2%82%AC"); data.append(str); sock->write(data); } } void MainWindow::dataHandler() { while(sock->bytesAvailable()>0) { char c; QByteArray data; do { sock->read(&c, 1); data.append(c); } while ( c != EOF ); data.remove(data.size()-1, 1); if(data.indexOf("MSG ") == 0) { QString str(data.remove(0, 4)); QStringList parts = str.split(" "); int pos = str.indexOf(" "); str = str.remove(0, pos+1); // TODO: displaymsg(str) mainPane->displayMsg(parts.at(0).toInt(), str); // ---------------------- // ---- Notifications --- if(!isActiveWindow()) { trayIcon->setIcon(*iconWarn); if(notifications) trayIcon->showMessage("New message from "+LutController::getInstance()->getNameFromId(parts.at(0).toInt()), str); } } else if(data.indexOf("PMSG ") == 0) { QString str(data.remove(0, 5)); QStringList parts = str.split(" "); int pos = str.indexOf(" "); str = str.remove(0, pos+1); DiscussPane *pane = findPaneById(parts.at(0).toInt()); if(!pane) { int gid = parts.at(0).toInt(); QString gname = LutController::getInstance()->getUsers()->getNameById(gid); pane = new DiscussPane(gid, this); privatePanes->append(pane); ui->tabWidget->addTab(pane, gname); connect(pane, SIGNAL(toRead(DiscussPane*)), this, SLOT(onToRead(DiscussPane*))); } pane->displayMsg(parts.at(0).toInt(), str); // ---------------------- // ---- Notifications --- if(!isActiveWindow()) { trayIcon->setIcon(*iconWarn); if(notifications) trayIcon->showMessage("New message from "+LutController::getInstance()->getNameFromId(parts.at(0).toInt()), str); } } else if(data.indexOf("NICK ") == 0) { QString str(data.remove(0, 5)); int pos = str.indexOf(" "); int userId = str.left(pos).toInt(); QString info = LutController::getInstance()->getNameFromId(userId)+" is now known as "+ str.mid(pos+1)+"\n"; DiscussPane *pane = findPaneById(userId); if(pane) pane->displayInfo(info); mainPane->displayInfo(info); sock->write("LIST"); } else if(data.indexOf("NC ") == 0) { QString str(data.remove(0, 3)); mainPane->displayInfo(str + " has join.\n"); sock->write("LIST"); } else if(data.indexOf("LEAVE ") == 0) { int idClient = data.remove(0, 6).toInt(); QString info = LutController::getInstance()->getNameFromId(idClient)+" has left.\n"; DiscussPane *pane = findPaneById(idClient); if(pane) { pane->displayInfo(info); pane->setGuyId(0); } mainPane->displayInfo(info); LutController::getInstance()->getUsers()->removeRowById(idClient); sock->write("LIST"); } else if(data.indexOf("YID ") == 0) { id = data.remove(0, 4).toInt(); } else if(data.indexOf("LIST ") == 0) { QString str = data.remove(0, 5); QStringList users = str.split(" ; "); majUserList(users); } } } DiscussPane* MainWindow::findPaneById(int id) { for(int i=0; i<privatePanes->size(); i++) { if(privatePanes->at(i)->getGuyId() == id) return privatePanes->at(i); } return 0; } void MainWindow::on_actionChange_nickname_triggered() { QString n = QInputDialog::getText(this, "Nickname", "Choose a nickname", QLineEdit::Normal, nickname); if(n.size()>0) { QByteArray data = "NICK "; data.append(n); sock->write(data); nickname = n; settings.setValue("nickname", nickname); } } void MainWindow::onConnected() { QString str = "Connected\n"; mainPane->displayInfo(str); for(int i=0; i<privatePanes->size(); i++) { privatePanes->at(i)->displayInfo(str); } QByteArray data = "NICK "; data.append(nickname); sock->write(data); } bool MainWindow::event ( QEvent *event ) { if(event->type() == QEvent::WindowActivate) trayIcon->setIcon(*icon); return QMainWindow::event(event); } void MainWindow::onItemDoubleClicked(QModelIndex index) { int gid = LutController::getInstance()->getUsers()->data(index,Qt::UserRole).toInt(); QString gname = LutController::getInstance()->getUsers()->data(index,Qt::DisplayRole).toString(); DiscussPane *p = findPaneById( gid ); if( !p ) { p = new DiscussPane(gid, this); privatePanes->append(p); int i = ui->tabWidget->addTab(p, gname); ui->tabWidget->setCurrentIndex(i); connect(p, SIGNAL(toRead(DiscussPane*)), this, SLOT(onToRead(DiscussPane*))); } else { int panePos = ui->tabWidget->indexOf(p); ui->tabWidget->setCurrentIndex(panePos); } } void MainWindow::onToRead(DiscussPane *p) { int i = ui->tabWidget->indexOf(p); i = i<0?0:i; if(i != ui->tabWidget->currentIndex()) { ui->tabWidget->setTabIcon(i, QIcon(":/img/warn.png")); } } void MainWindow::onTrayClicked(QSystemTrayIcon::ActivationReason r) { if(r == QSystemTrayIcon::Trigger) { if(isVisible()) close(); else show(); } } void MainWindow::on_actionChange_server_triggered() { serverPort = 1888; QString ipServer = QInputDialog::getText(this, "server address", "Server address :", QLineEdit::Normal, serverIP+":"+QString::number(serverPort)); QStringList serverInfos = ipServer.split(":"); if(ipServer.size()>0) { if(serverInfos.size()>1) serverPort = serverInfos.at(1).toInt(); serverIP = serverInfos.at(0); settings.setValue("server", serverIP); settings.setValue("port", serverPort); sock->disconnectFromHost(); sock->connectToHost(serverIP, serverPort); QString str = "Connecting to server at "; str += serverIP + " on port " + QString::number(serverPort) + "\n"; mainPane->displayInfo(str); privatePanes->clear(); for(int i=1; i<ui->tabWidget->count(); i++) { ui->tabWidget->removeTab(i); } LutController::getInstance()->getUsers()->clear(); } } int MainWindow::myId() { return id; } void MainWindow::majUserList(QStringList list) { for (int i=0; i<list.size(); i++) if(list.at(i) != "") majUser(list.at(i)); } void MainWindow::majUser(QString data) { QStringList infos = data.split(" "); int uid = infos.at(0).toInt(); LutController::getInstance()->getUsers()->addOrReplace(new User(data)); DiscussPane *pane = findPaneById(uid); if(pane) { int idpane = ui->tabWidget->indexOf(pane); ui->tabWidget->setTabText(idpane, LutController::getInstance()->getNameFromId(uid)); } } void MainWindow::on_actionNotifications_toggled(bool v) { notifications = v; settings.setValue("notifications", v); } void MainWindow::on_actionClose_current_tab_triggered() { DiscussPane *p = static_cast<DiscussPane*>(ui->tabWidget->currentWidget()); privatePanes->removeOne(p); ui->tabWidget->removeTab(ui->tabWidget->currentIndex()); } void MainWindow::onExitAct() { LutController::getInstance()->onQuitReq(); } void MainWindow::on_actionShow_time_triggered() { } void MainWindow::on_actionShow_time_toggled(bool v) { showTime = v; settings.setValue("time", v); } void MainWindow::on_actionClear_triggered() { DiscussPane *p; p = ui->tabWidget->currentIndex() > 0 ? static_cast<DiscussPane*>(ui->tabWidget->currentWidget()) : mainPane; p->clearPane(); }
01lut
trunk/ClientQt/MainWindow.cpp
C++
gpl3
10,968
#ifndef LUTCONTROLLER_H #define LUTCONTROLLER_H #include <QObject> #include "UserList.h" class MainWindow; class LutController : public QObject { Q_OBJECT public: static LutController* getInstance(); int myId(); QString getNameFromId(int id); void sendMsg(QString str); void sendPrivateMsg(int to, QString str); bool getShowTime(); UserList* getUsers(); void startApp(); private: explicit LutController(); MainWindow *window; UserList *users; static LutController *instance; signals: void quitMe(); public slots: void onQuitReq(); }; //extern static LutController *LutController::instance; #endif // LUTCONTROLLER_H
01lut
trunk/ClientQt/LutController.h
C++
gpl3
649
#ifndef PRIVATEPANE_H #define PRIVATEPANE_H #include <QWidget> #include "User.h" #include "MainWindow.h" namespace Ui { class DiscussPane; } class DiscussPane : public QWidget { Q_OBJECT signals: void toRead(DiscussPane*); public: explicit DiscussPane(int gid = -1, QWidget *parent = 0); ~DiscussPane(); void displayInfo(QString str); void displayError(QString str); void displayMsg(int from, QString str); void moveToBottom(); bool isPrivate(); int getGuyId(); void setGuyId(int val); void clearPane(); private: Ui::DiscussPane *ui; int guyId; private slots: void sendMsg(); }; #endif // PRIVATEPANE_H
01lut
trunk/ClientQt/DiscussPane.h
C++
gpl3
635
fstring.o: src/fstring.cpp src/fstring.hpp
01lut
trunk/fstring.d
Makefile
gpl3
43
prompt.o: src/prompt.cpp src/prompt.hpp src/fstring.hpp
01lut
trunk/prompt.d
Makefile
gpl3
56
client.o: src/client.cpp src/client.hpp src/log.hpp src/fstring.hpp \ src/prompt.hpp
01lut
trunk/client.d
Makefile
gpl3
86
serverCmd.o: src/serverCmd.cpp src/server.hpp src/prompt.hpp \ src/fstring.hpp src/log.hpp src/user.hpp
01lut
trunk/serverCmd.d
Makefile
gpl3
105
server.o: src/server.cpp src/server.hpp src/prompt.hpp src/fstring.hpp \ src/log.hpp src/user.hpp
01lut
trunk/server.d
Makefile
gpl3
99
user.o: src/user.cpp src/user.hpp src/fstring.hpp
01lut
trunk/user.d
Makefile
gpl3
50
# Freddy Teuma - 30 novembre 2009 # -Modification du makefile- CXX = g++ -Wall LD = g++ SRC_PATH = src SERV_SRC = serverCmd.cpp \ server.cpp \ prompt.cpp \ fstring.cpp \ user.cpp \ log.cpp CLI_SRC = clientCmd.cpp\ client.cpp \ prompt.cpp \ fstring.cpp BIN = serverCmd clientCmd SERV_OBJ = $(SERV_SRC:.cpp=.o) CLI_OBJ = $(CLI_SRC:.cpp=.o) DEP = $(CLI_SRC:.cpp=.d) \ $(SERV_SRC:.cpp=.d) %.o: $(SRC_PATH)/%.cpp $(CXX) -g -o $@ -c $< %.d: $(SRC_PATH)/%.cpp $(CXX) $< -MM -o $@ all: $(BIN) serverCmd: $(SERV_OBJ) $(LD) -o $@ $+ clientCmd: $(CLI_OBJ) $(LD) -o $@ $+ clean: @rm *.o *.d @rm *.log # $rm $(BIN) cleanpdf: @rm *.d *.aux *.idx *.lof *.log *.toc -include $(DEP) # j'ajoute ma petite signature en bas du fichier
01lut
trunk/Makefile
Makefile
gpl3
776
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class BangLuong_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/BangLuong_BUS.cs
C#
asf20
170
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class NhanVien_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/NhanVien_BUS.cs
C#
asf20
169
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using DAO; using DTO; namespace BUS { public partial class Ca_BUS { public DataTable LayDanhSachCa() { Ca_DAO cd = new Ca_DAO(); return cd.LayDanhSachCa(); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/Ca_BUS.cs
C#
asf20
356
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; using System.Data; namespace BUS { public partial class LoaiVe_BUS { LoaiVe_DAO LoaiVe_dao; public bool ThemLoaiVe(LoaiVe LoaiVe_dto) { LoaiVe_dao = new LoaiVe_DAO(); return LoaiVe_dao.ThemLoaiVe(LoaiVe_dto); } public bool SuaLoaiVe(LoaiVe LoaiVe_dto) { LoaiVe_dao = new LoaiVe_DAO(); return LoaiVe_dao.SuaLoaiVe(LoaiVe_dto); } public bool XoaLoaiVe(string MaLoaiVe) { LoaiVe_dao = new LoaiVe_DAO(); return LoaiVe_dao.XoaLoaiVe(MaLoaiVe); } public DataTable DanhSachLoaiVe() { LoaiVe_dao = new LoaiVe_DAO(); DataTable dt = new DataTable(); dt = LoaiVe_dao.DanhSachLoaiVe(); return dt; } public DataTable DanhSachLoaiVe_Ma(string ma) { LoaiVe_dao = new LoaiVe_DAO(); DataTable dt = new DataTable(); dt = LoaiVe_dao.DanhSachLoaiVe_Ma(ma); return dt; } public DataTable getGiaVeNguoiLon(string strBuoi, string strNgay) { LoaiVe_dao = new LoaiVe_DAO(); DataTable dt = new DataTable(); dt = LoaiVe_dao.getGiaVeNguoiLon(strBuoi, strNgay); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/LoaiVe_BUS.cs
C#
asf20
1,499
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using DAO; using DTO; namespace BUS { public partial class KhachHang_BUS { KhachHang_DAO khachhang_dao; public bool insertKhachHang(KhachHang khachhang_dto) { khachhang_dao = new KhachHang_DAO(); return khachhang_dao.insertKhachHang(khachhang_dto); } public bool updateKhachHang(KhachHang khachhang_dto) { khachhang_dao = new KhachHang_DAO(); return khachhang_dao.updateKhachHang(khachhang_dto); } public DataTable getDanhSachKhachHang() { khachhang_dao = new KhachHang_DAO(); DataTable dt = new DataTable(); dt = khachhang_dao.getDanhSachKhachHang(); return dt; } public DataTable getDanhSachKhachHangSearch(string cmnd) { khachhang_dao = new KhachHang_DAO(); DataTable dt = new DataTable(); dt = khachhang_dao.getDanhSachKhachHangSearch(cmnd); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/KhachHang_BUS.cs
C#
asf20
1,233
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; using System.Data; namespace BUS { public partial class NguyenVatLieu_BUS { NguyenVatLieu_DAO nvl_dao; public bool ThemNVL(NguyenVatLieu nvl_dto) { nvl_dao = new NguyenVatLieu_DAO(); return nvl_dao.ThemNVL(nvl_dto); } public bool CapNhatNVL(NguyenVatLieu nvl_dto) { nvl_dao = new NguyenVatLieu_DAO(); return nvl_dao.CapNhatNVL(nvl_dto); } public bool XoaNVL(NguyenVatLieu nvl_dto) { nvl_dao = new NguyenVatLieu_DAO(); return nvl_dao.XoaNVL(nvl_dto); } public DataTable DanhSachNVL() { nvl_dao = new NguyenVatLieu_DAO(); DataTable dt = new DataTable(); dt = nvl_dao.DanhSachNVL(); return dt; } public DataTable DanhSachNVL_Ma(string strMa) { nvl_dao = new NguyenVatLieu_DAO(); DataTable dt = new DataTable(); dt = nvl_dao.DanhSachNVL_Ma(strMa); return dt; } public DataTable DanhSachNVL_MaLoaiNVL(string strMa) { nvl_dao = new NguyenVatLieu_DAO(); DataTable dt = new DataTable(); dt = nvl_dao.DanhSachNVL_MaLoaiNVL(strMa); return dt; } public string MaNVLTang() { nvl_dao = new NguyenVatLieu_DAO(); return nvl_dao.MaNVLTang(); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/NguyenVatLieu_BUS.cs
C#
asf20
1,626
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public partial class PhieuNhap_BUS { PhieuNhap_DAO pn_dao; public bool ThemPhieuNhap(PhieuNhap pn_dto) { pn_dao = new PhieuNhap_DAO(); return pn_dao.ThemPhieuNhap(pn_dto); } public string MaPNTang() { pn_dao = new PhieuNhap_DAO(); return pn_dao.MaPNTang(); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/PhieuNhap_BUS.cs
C#
asf20
529
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; using System.Data; namespace BUS { public partial class ChucVu_BUS { public DataTable LoadDanhSachChucVu() { DataTable dt = new DataTable(); ChucVu_DAO cvd = new ChucVu_DAO(); dt = cvd.LoadDanhSachChucVu(); return dt; } public bool ThemMoiChucVu(string TenChucVu) { ChucVu_DAO cvd = new ChucVu_DAO(); bool kq; kq = cvd.ThemMoiChucVu(TenChucVu); return kq; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/Duy_ChucVu_BUS.cs
C#
asf20
660
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public class Class1 { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/Class1.cs
C#
asf20
155
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public partial class CTPhieuNhap_BUS { CTPhieuNhap_DAO ctpn_dao; public bool ThemCTPhieuNhap(CTPhieuNhap ctpn_dto) { ctpn_dao = new CTPhieuNhap_DAO(); return ctpn_dao.ThemCTPhieuNhap(ctpn_dto); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/CTPhieuNhap_BUS.cs
C#
asf20
413
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; using System.Data; namespace BUS { public partial class MonAn_BUS { MonAn_DAO monan_dao; public bool ThemMonAn(MonAn monan_dto) { monan_dao = new MonAn_DAO(); return monan_dao.ThemMonAn(monan_dto); } public bool ThemMonAn_NVL(MonAn_NVL MonAnNVL_dto) { monan_dao = new MonAn_DAO(); return monan_dao.ThemMonAn_NVL(MonAnNVL_dto); } public string MaNVLTang() { monan_dao = new MonAn_DAO(); return monan_dao.MaMonTang(); } public DataTable DanhSachMonAn() { monan_dao = new MonAn_DAO(); return monan_dao.DanhSachMonAn(); } public DataTable DanhSachMonAn_Ma(string ma) { monan_dao = new MonAn_DAO(); return monan_dao.DanhSachMon_Ma(ma); } public bool XoaMon(string MaMon) { monan_dao = new MonAn_DAO(); return monan_dao.XoaMon(MaMon); } public bool SuaMonAn(MonAn monan_dto) { monan_dao = new MonAn_DAO(); return monan_dao.SuaMonAn(monan_dto); } public bool XoaMonAn_NVL(string MaNVL) { monan_dao = new MonAn_DAO(); return monan_dao.XoaMonAn_NVL(MaNVL); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/MonAn_BUS.cs
C#
asf20
1,549
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public partial class PhieuXuat_BUS { PhieuXuat_Dao px_dao; public bool ThemPhieuXuat(PhieuXuat px_dto) { px_dao = new PhieuXuat_Dao(); return px_dao.ThemPhieuXuat(px_dto); } public string MaPXTang() { px_dao = new PhieuXuat_Dao(); return px_dao.MaPXTang(); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/PhieuXuat_BUS.cs
C#
asf20
529
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class ChucVu_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/ChucVu_BUS.cs
C#
asf20
167
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using DAO; using DTO; namespace BUS { public partial class Ve_HoaDon_BUS { public bool insertThanhToanVeBuffet(Ve_HoaDon vehoadon) { Ve_HoaDon_DAO vhdd = new Ve_HoaDon_DAO(); return vhdd.insertThanhToanVeBuffet(vehoadon); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/Ve_HoaDon_BUS.cs
C#
asf20
470
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class ThucDon_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/ThucDon_BUS.cs
C#
asf20
168
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; using System.Data; namespace BUS { public partial class LaoiNVL_BUS { //du LoaiNVL_DAO loainvl_dao; public DataTable DanhSachLoaiNVL( ) { loainvl_dao = new LoaiNVL_DAO(); DataTable dt = new DataTable(); dt = loainvl_dao.DanhSachLoaiNVL(); return dt; } public DataTable DanhSachLoaiNVL_Ma(string strMa) { loainvl_dao = new LoaiNVL_DAO(); DataTable dt = new DataTable(); dt = loainvl_dao.DanhSachLoaiNVL_Ma(strMa); return dt; } public string MaLoaiNVLTang() { loainvl_dao = new LoaiNVL_DAO(); return loainvl_dao.MaLoaiNVLTang(); } public bool ThemLoaiNVL(LoaiNVL loainvl_dto) { loainvl_dao = new LoaiNVL_DAO(); return loainvl_dao.ThemLoaiNVL(loainvl_dto); } public bool CapNhatLoaiNVL(LoaiNVL loainvl_dto) { loainvl_dao = new LoaiNVL_DAO(); return loainvl_dao.CapNhatLoaiNVL(loainvl_dto); } public bool XoaLoaiNVL(LoaiNVL loainvl_dto) { loainvl_dao = new LoaiNVL_DAO(); return loainvl_dao.XoaLoaiNVL(loainvl_dto); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/LaoiNVL_BUS.cs
C#
asf20
1,442
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; using System.Data; namespace BUS { public partial class NhanVien_BUS { /// <summary> /// Hàm đăng nhập của nhân viên /// </summary> /// <param name="username"></param> /// <returns></returns> public DataTable DangNhap(string TenDangNhap) { NhanVien_DAO nvd = new NhanVien_DAO(); DataTable dt = new DataTable(); dt = nvd.DangNhap(TenDangNhap); return dt; } /// <summary> /// Thêm mới nhân viên /// </summary> /// <param name="nhanvien"></param> /// <returns></returns> public bool ThemMoiNhanVien(NhanVien nhanvien) { NhanVien_DAO nvd = new NhanVien_DAO(); return nvd.ThemMoiNhanVien(nhanvien); } /// <summary> /// Lấy danh sách nhân viên /// </summary> /// <returns></returns> public DataTable LoadDanhSachNhanVien() { NhanVien_DAO nvd = new NhanVien_DAO(); DataTable dt = new DataTable(); dt = nvd.LayDanhSachNhanVien(); return dt; } /// <summary> /// thông tin chi tiết nhân viên /// </summary> /// <returns></returns> public DataTable XemChiTietNhanVien(string MaNhanVien) { NhanVien_DAO nvd = new NhanVien_DAO(); DataTable dt = new DataTable(); dt = nvd.XemChiTietNhanVien(MaNhanVien); return dt; } /// <summary> /// Cập nhật mật khẩu /// </summary> /// <param name="MaNhanVien"></param> /// <returns></returns> public bool CapNhatMatKhau(string MaNhanVien,string MatKhau) { NhanVien_DAO nvd = new NhanVien_DAO(); return nvd.CapNhatMatKhau(MaNhanVien,MatKhau); } /// <summary> /// Cập nhật thông tin cá nhân /// </summary> /// <param name="NhanVien"></param> /// <returns></returns> public bool CapNhatThongTinNhaVien(NhanVien NhanVien) { NhanVien_DAO nvd = new NhanVien_DAO(); return nvd.CapNhatThongTinNhaVien(NhanVien); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/Duy_NhanVien_BUS.cs
C#
asf20
2,482
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using DAO; namespace BUS { public partial class Ban_BUS { Ban_DAO ban_dao; public DataTable getKiemTraTinhTrangBan(string maban) { ban_dao = new Ban_DAO(); DataTable dt = new DataTable(); dt = ban_dao.getKiemTraTinhTrangBan(maban); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/Ban_BUS.cs
C#
asf20
525
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using DAO; namespace BUS { public partial class DiemCong_BUS { DiemCong_DAO dcd; public DataTable getDanhSachDiemCong() { DataTable dt = new DataTable(); DiemCong_DAO dcd = new DiemCong_DAO(); dt = dcd.getDanhSachDiemCong(); return dt; } public DataTable getDiemCongTheoHoadon(float giatriphaitra) { dcd = new DiemCong_DAO(); DataTable dt = new DataTable(); dt = dcd.getDiemCongTheoHoadon(giatriphaitra); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/DiemCong_BUS.cs
C#
asf20
777
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using DAO; namespace BUS { public class ThucDonDichVuKhach_BUS { //GiamGia_DAO ggd; //public DataTable getDanhSachTiLeGiam() //{ // DataTable dt = new DataTable(); // ggd = new GiamGia_DAO(); // dt = ggd.getDanhSachTiLeGiam(); // return dt; //} ThucDonDichVuKhach_DAO thucdon; public DataTable getDanhSachDichVuKhac() { DataTable dt = new DataTable(); thucdon = new ThucDonDichVuKhach_DAO(); dt = thucdon.getDanhSachDichVuKhac(); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/ThucDonDichVuKhach_BUS.cs
C#
asf20
807
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class CTHDDVu_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/CTHDDVu_BUS.cs
C#
asf20
168
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; using System.Data; namespace BUS { public partial class NCC_BUS { NCC_DAO ncc_dao; public bool ThemNCC(NCC ncc_dto) { ncc_dao = new NCC_DAO(); return ncc_dao.ThemNCC(ncc_dto); } public bool CapNhatNCC(NCC ncc_dto) { ncc_dao = new NCC_DAO(); return ncc_dao.CapNhatNCC(ncc_dto); } public DataTable DanhSachNCC() { ncc_dao = new NCC_DAO(); DataTable dt = new DataTable(); dt = ncc_dao.DanhSachNCC(); return dt; } public DataTable DanhSachNCC_Ma(string strMa) { ncc_dao = new NCC_DAO(); DataTable dt = new DataTable(); dt = ncc_dao.DanhSachNCC_Ma(strMa); return dt; } public DataTable DanhSachNCC_MaNVL(string strMa) { ncc_dao = new NCC_DAO(); DataTable dt = new DataTable(); dt = ncc_dao.DanhSachNCC_MaNVL(strMa); return dt; } public string MaNCCTang() { ncc_dao = new NCC_DAO(); return ncc_dao.MaNCCTang(); } public bool XoaNCC(NCC ncc_dto) { ncc_dao = new NCC_DAO(); return ncc_dao.XoaNCC(ncc_dto); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/NCC_BUS.cs
C#
asf20
1,498
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("BUS")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BUS")] [assembly: AssemblyCopyright("Copyright © 2014")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("06efd7c8-41ff-49b9-9f59-8915f3dc127a")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/Properties/AssemblyInfo.cs
C#
asf20
1,418
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class DonXinNghi_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/DonXinNghi_BUS.cs
C#
asf20
171
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using DAO; namespace BUS { public partial class GiamGia_BUS { GiamGia_DAO ggd; public DataTable getDanhSachTiLeGiam() { DataTable dt = new DataTable(); ggd = new GiamGia_DAO(); dt = ggd.getDanhSachTiLeGiam(); return dt; } public DataTable getPhanTramGiamGia(float diemtichluy) { ggd = new GiamGia_DAO(); DataTable dt = new DataTable(); dt = ggd.getPhanTramGiamGia(diemtichluy); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/GiamGia_BUS.cs
C#
asf20
752
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public partial class CTPhieuXuat_BUS { CTPhieuXuat_DAO ctpx_dao; public bool ThemCTPhieuXuat(CTPhieuXuat ctpx_dto) { ctpx_dao = new CTPhieuXuat_DAO(); return ctpx_dao.ThemCTPhieuXuat(ctpx_dto); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/CTPhieuXuat_BUS.cs
C#
asf20
415
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; namespace BUS { public partial class CTNCC_BUS { CTNCC_DAO ctncc_dao; public bool ThemCTNCC(CTNCC ctncc_dto) { ctncc_dao = new CTNCC_DAO(); return ctncc_dao.ThemCTNCC(ctncc_dto); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/CTNCC_BUS.cs
C#
asf20
382
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class HoaDonDichVu_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/HoaDonDichVu_BUS.cs
C#
asf20
173
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public partial class CTPhanCong_BUS { public bool ThemMoiPhanCong(CTPhanCong ctpc) { CTPhanCong_DAO ctpcd = new CTPhanCong_DAO(); return ctpcd.ThemMoiPhanCong(ctpc); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/CTPhanCong_BUS.cs
C#
asf20
378
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; using System.Data; namespace BUS { public partial class PhanCong_BUS { public DataTable LayDanhSachPhanCong() { PhanCong_DAO pcd = new PhanCong_DAO(); DataTable dt = new DataTable(); dt = pcd.LayDanhSachPhanCong(); return dt; } public DataTable ThemMoiPhanCong(PhanCong PhanCong) { PhanCong_DAO pcd = new PhanCong_DAO(); DataTable dt = new DataTable(); dt = pcd.ThemMoiPhanCong(PhanCong); return dt; } public DataTable ChiTietPhanCong(string MaPhanCong, string MaNhanVien) { PhanCong_DAO pcd = new PhanCong_DAO(); DataTable dt = new DataTable(); dt = pcd.ChiTietPhanCong(MaPhanCong, MaNhanVien); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/PhanCong_BUS.cs
C#
asf20
993
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; using System.Data; namespace BUS { public partial class LoaiMonAn_BUS { LoaiMonAn_DAO LoaiMon_dao; public bool ThemLoaiMon(LoaiMonAn LoaiMon_dto) { LoaiMon_dao = new LoaiMonAn_DAO(); return LoaiMon_dao.ThemLoaiMon(LoaiMon_dto); } public bool SuaLoaiMon(LoaiMonAn LoaiMon_dto) { LoaiMon_dao = new LoaiMonAn_DAO(); return LoaiMon_dao.SuaLoaiMon(LoaiMon_dto); } public bool XoaLoaiMon(string MaLoaiMon) { LoaiMon_dao = new LoaiMonAn_DAO(); return LoaiMon_dao.XoaLoaiMon(MaLoaiMon); } public DataTable DanhSachLoaiMon() { LoaiMon_dao = new LoaiMonAn_DAO(); DataTable dt = new DataTable(); dt = LoaiMon_dao.DanhSachLoaiMon(); return dt; } public DataTable DanhSachLoaiMon_Ma(string ma) { LoaiMon_dao = new LoaiMonAn_DAO(); DataTable dt = new DataTable(); dt = LoaiMon_dao.DanhSachLoaiMon_Ma(ma); return dt; } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/LoaiMonAn_BUS.cs
C#
asf20
1,276
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public partial class CTThucDon_BUS { } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/BUS/CTThucDon_BUS.cs
C#
asf20
170
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using System.Data; using System.Data.SqlClient; namespace DAO { public partial class ChucVu_DAO { public DataTable LoadDanhSachChucVu() { DataProvider dp = new DataProvider(); DataTable dt = new DataTable(); dt = dp.ExecuteQuery("LoadDanhSachChucVu"); return dt; } public bool ThemMoiChucVu(string TenChucVu) { DataProvider dp = new DataProvider(); SqlParameter[] Parameter = new SqlParameter[1]; Parameter[0] = new SqlParameter("@TenChucVu", TenChucVu); return dp.ExecutenonQuery("ThemMoiChucVu", Parameter); } } }
12hcb-nhom16-pttkhttt
trunk/Sources/Nhom16_PTTKHTTT_12HCB/DAO/Duy_ChucVu_DAO.cs
C#
asf20
803