first chatcleaner steps (simple badword and textflood check works on port 7777)
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
# -------------------------------------------------
|
||||||
|
# Project created by QtCreator 2009-07-17T21:51:00
|
||||||
|
# -------------------------------------------------
|
||||||
|
CODECFORSRC = UTF-8
|
||||||
|
QT += network
|
||||||
|
QT -= gui
|
||||||
|
TARGET = chatcleaner
|
||||||
|
CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
MOC_DIR = mocs
|
||||||
|
OBJECTS_DIR = obj
|
||||||
|
TEMPLATE = app
|
||||||
|
INCLUDEPATH += src/ src/chatcleaner/
|
||||||
|
DEPENDPATH += src/ src/chatcleaner/
|
||||||
|
SOURCES += chatcleaner.cpp \
|
||||||
|
cleanerserver.cpp \
|
||||||
|
messagefilter.cpp \
|
||||||
|
badwordcheck.cpp \
|
||||||
|
textfloodcheck.cpp
|
||||||
|
HEADERS += cleanerserver.h \
|
||||||
|
messagefilter.h \
|
||||||
|
badwordcheck.h \
|
||||||
|
textfloodcheck.h
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include "badwordcheck.h"
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
|
||||||
|
BadWordCheck::BadWordCheck()
|
||||||
|
{
|
||||||
|
badWords << "arsch" << "asshole" << "bastard" << "bitch" << "cunt" << " dick " << "drecksau" << " fag " << "fagget" << "fotze" << "fuker"
|
||||||
|
<< "fuck" << " fuk " << "gay" << "horny" << "hure" << "mistgeburt" << "missgeburt" << "motherfucker" << "nazi" << "nigga"
|
||||||
|
<< "nigger" << "nutte" << "ommak" << "penis" << "pussy" << "schlampe" << "schwanz" << "sex" << "shit" << "sieg heil" << "slut"
|
||||||
|
<< "suck" << "whore";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BadWordCheck::run(QString msg)
|
||||||
|
{
|
||||||
|
QStringListIterator it(badWords);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
if(msg.toLower().contains(it.next()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef BADWORDCHECK_H
|
||||||
|
#define BADWORDCHECK_H
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
|
||||||
|
class BadWordCheck: public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
BadWordCheck();
|
||||||
|
|
||||||
|
bool run(QString);
|
||||||
|
private:
|
||||||
|
|
||||||
|
QStringList badWords;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BADWORDCHECK_H
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include "cleanerserver.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
CleanerServer server;
|
||||||
|
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#include "cleanerserver.h"
|
||||||
|
|
||||||
|
#include <QtNetwork>
|
||||||
|
#include <QtCore>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "messagefilter.h"
|
||||||
|
|
||||||
|
CleanerServer::CleanerServer()
|
||||||
|
{
|
||||||
|
myMessageFilter = new MessageFilter;
|
||||||
|
tcpServer = new QTcpServer();
|
||||||
|
if (!tcpServer->listen(QHostAddress("127.0.0.1"), 7777) ) {
|
||||||
|
qDebug() << QString("Unable to start the server: %1.").arg(tcpServer->errorString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << QString("The server is running on port %1.").arg(tcpServer->serverPort());
|
||||||
|
|
||||||
|
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newCon()));
|
||||||
|
}
|
||||||
|
|
||||||
|
CleanerServer::~CleanerServer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CleanerServer::newCon()
|
||||||
|
{
|
||||||
|
tcpSocket = tcpServer->nextPendingConnection();
|
||||||
|
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(onRead()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CleanerServer::onRead()
|
||||||
|
{
|
||||||
|
char buf[20000];
|
||||||
|
tcpSocket->readLine(buf, sizeof(buf));
|
||||||
|
QString message = QString::fromUtf8("%1").arg(buf);
|
||||||
|
QString checkMessage = myMessageFilter->check(message);
|
||||||
|
tcpSocket->write(checkMessage.toAscii().data(), checkMessage.length());
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef CLEANERSERVER_H
|
||||||
|
#define CLEANERSERVER_H
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
#include <QtNetwork>
|
||||||
|
|
||||||
|
class MessageFilter;
|
||||||
|
|
||||||
|
class CleanerServer: public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CleanerServer();
|
||||||
|
~CleanerServer();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void newCon();
|
||||||
|
void onRead();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTcpServer *tcpServer;
|
||||||
|
QTcpSocket *tcpSocket;
|
||||||
|
MessageFilter *myMessageFilter;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLEANERSERVER_H
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#include "messagefilter.h"
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
#include "badwordcheck.h"
|
||||||
|
#include "textfloodcheck.h"
|
||||||
|
|
||||||
|
enum OffenceType {
|
||||||
|
BAD_WORD,
|
||||||
|
TEXT_FLOOD_LINES };
|
||||||
|
|
||||||
|
MessageFilter::MessageFilter()
|
||||||
|
{
|
||||||
|
myBadWordCheck = new BadWordCheck;
|
||||||
|
myTextFloodCheck = new TextFloodCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MessageFilter::check(QString msg)
|
||||||
|
{
|
||||||
|
if(myBadWordCheck->run(msg)) {
|
||||||
|
return QString("<PokerTHCleaner> Der Blitz soll dich beim Scheißen erschlagen du Spammer\n");
|
||||||
|
}
|
||||||
|
if(myTextFloodCheck->run(1)) {
|
||||||
|
return QString("<PokerTHCleaner> Bitte langsamer schreiben!!!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString("");
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef MESSAGEFILTER_H
|
||||||
|
#define MESSAGEFILTER_H
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
class BadWordCheck;
|
||||||
|
class TextFloodCheck;
|
||||||
|
|
||||||
|
class MessageFilter: public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MessageFilter();
|
||||||
|
|
||||||
|
QString check(QString);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BadWordCheck *myBadWordCheck;
|
||||||
|
TextFloodCheck *myTextFloodCheck;
|
||||||
|
|
||||||
|
struct ClientWarnInfos {
|
||||||
|
QString nick;
|
||||||
|
int lastWarnType;
|
||||||
|
int warnLevel;
|
||||||
|
};
|
||||||
|
|
||||||
|
QMap<unsigned, ClientWarnInfos> clientWarnLevelList;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MESSAGEFILTER_H
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#include "textfloodcheck.h"
|
||||||
|
|
||||||
|
TextFloodCheck::TextFloodCheck()
|
||||||
|
{
|
||||||
|
timer.reset();
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextFloodCheck::run(unsigned playerId) {
|
||||||
|
|
||||||
|
QMapIterator<unsigned, TextFloodInfos> it(msgTimesList);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
qDebug() << msgTimesList.count() << it.key() << ": " << it.value().floodLevel << it.value().timeStamp << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<unsigned, TextFloodInfos>::const_iterator i = msgTimesList.find(playerId);
|
||||||
|
|
||||||
|
if(i == msgTimesList.end()) {
|
||||||
|
myTextFloodInfos.floodLevel = 0;
|
||||||
|
myTextFloodInfos.timeStamp = timer.elapsed().total_seconds();
|
||||||
|
msgTimesList.insert(playerId, myTextFloodInfos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(timer.elapsed().total_seconds()-i.value().timeStamp <= 1) {
|
||||||
|
if(i.value().floodLevel == 2)
|
||||||
|
return true;
|
||||||
|
else if(i.value().floodLevel == 1)
|
||||||
|
myTextFloodInfos.floodLevel = 2;
|
||||||
|
else
|
||||||
|
myTextFloodInfos.floodLevel = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
myTextFloodInfos.timeStamp = timer.elapsed().total_seconds();
|
||||||
|
msgTimesList.insert(playerId, myTextFloodInfos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextFloodCheck::cleanMsgTimesList() {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef TEXTFLOODCHECK_H
|
||||||
|
#define TEXTFLOODCHECK_H
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
#include <third_party/boost/timers.hpp>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
class TextFloodCheck
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextFloodCheck();
|
||||||
|
bool run(unsigned);
|
||||||
|
void cleanMsgTimesList();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer cleanTimer;
|
||||||
|
boost::timers::portable::second_timer timer;
|
||||||
|
struct TextFloodInfos {
|
||||||
|
int floodLevel;
|
||||||
|
size_t timeStamp;
|
||||||
|
};
|
||||||
|
TextFloodInfos myTextFloodInfos;
|
||||||
|
QMap<unsigned, TextFloodInfos> msgTimesList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TEXTFLOODCHECK_H
|
||||||
Reference in New Issue
Block a user