initial capsfloodcheck support

This commit is contained in:
doitux
2009-07-29 23:27:27 +00:00
parent a612cff91f
commit 0356d21e0f
6 changed files with 69 additions and 12 deletions
+12 -10
View File
@@ -5,16 +5,17 @@ CODECFORSRC = UTF-8
QT += network
QT -= gui
TARGET = chatcleaner
CONFIG += console debug
CONFIG += console \
debug
CONFIG -= app_bundle
MOC_DIR = mocs
OBJECTS_DIR = obj
TEMPLATE = app
INCLUDEPATH += src/ \
src/third_party/tinyxml \
src/third_party/tinyxml \
src/chatcleaner/
DEPENDPATH += src/ \
src/third_party/tinyxml \
src/third_party/tinyxml \
src/chatcleaner/
SOURCES += chatcleaner.cpp \
cleanerserver.cpp \
@@ -22,15 +23,16 @@ SOURCES += chatcleaner.cpp \
badwordcheck.cpp \
textfloodcheck.cpp \
cleanerconfig.cpp \
tinystr.cpp \
tinyxml.cpp \
tinyxmlerror.cpp \
tinyxmlparser.cpp
tinystr.cpp \
tinyxml.cpp \
tinyxmlerror.cpp \
tinyxmlparser.cpp \
capsfloodcheck.cpp
HEADERS += cleanerserver.h \
messagefilter.h \
badwordcheck.h \
textfloodcheck.h \
cleanerconfig.h \
tinyxml.h \
tinystr.h
tinyxml.h \
tinystr.h \
capsfloodcheck.h
+23
View File
@@ -0,0 +1,23 @@
#include "capsfloodcheck.h"
#include <QtCore>
CapsFloodCheck::CapsFloodCheck()
{
}
bool CapsFloodCheck::run(QString msg)
{
msg = msg.simplified().remove(" ");
QRegExp e(QString("[A-Z]{%1,}").arg(capsNumberToTrigger));
if(e.isValid()) {
e.setCaseSensitivity(Qt::CaseSensitive);
e.indexIn(msg);
if(e.matchedLength() != -1 ) return true;
else return false;
}
else {
qDebug() << "The current Caps Flood RegExp is invalid" << endl;
return false;
}
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef CAPSFLOODCHECK_H
#define CAPSFLOODCHECK_H
#include <QtCore>
class CapsFloodCheck: public QObject {
Q_OBJECT
public:
CapsFloodCheck();
void setCapsNumberToTrigger(int n) { capsNumberToTrigger = n; }
bool run(QString);
private:
int capsNumberToTrigger;
};
#endif // CAPSFLOODCHECK_H
+2 -1
View File
@@ -43,7 +43,7 @@ using namespace std;
CleanerConfig::CleanerConfig()
{
// !!!! Revisionsnummer der Configdefaults !!!!!
configRev = 2;
configRev = 3;
// Pfad und Dateinamen setzen
#ifdef _WIN32
@@ -116,6 +116,7 @@ CleanerConfig::CleanerConfig()
configList.push_back(ConfigInfo("DefaultListenPort", CONFIG_TYPE_STRING, "4327"));
configList.push_back(ConfigInfo("WarnLevelToKick", CONFIG_TYPE_INT, "2"));
configList.push_back(ConfigInfo("TextFloodLevelToTrigger", CONFIG_TYPE_INT, "3"));
configList.push_back(ConfigInfo("CapsFloodCapsNumberToTrigger", CONFIG_TYPE_INT, "10"));
list<string> badWordsList;
+11 -1
View File
@@ -4,6 +4,7 @@
#include "badwordcheck.h"
#include "textfloodcheck.h"
#include "cleanerconfig.h"
#include "capsfloodcheck.h"
enum ActionType {
NOTHING,
@@ -13,12 +14,15 @@ enum ActionType {
enum OffenceType {
NONE,
BAD_WORD,
TEXT_FLOOD_LINES };
TEXT_FLOOD_LINES,
CAPS_FLOOD
};
MessageFilter::MessageFilter(CleanerConfig *c): config(c)
{
myBadWordCheck = new BadWordCheck;
myTextFloodCheck = new TextFloodCheck;
myCapsFloodCheck = new CapsFloodCheck;
}
QString MessageFilter::check(unsigned playerId, QString nick, QString msg)
@@ -29,6 +33,7 @@ QString MessageFilter::check(unsigned playerId, QString nick, QString msg)
ActionType action = NOTHING;
if(myBadWordCheck->run(msg)) offence = BAD_WORD;
if(myCapsFloodCheck->run(msg)) offence = CAPS_FLOOD;
if(myTextFloodCheck->run(playerId)) offence = TEXT_FLOOD_LINES;
if(offence){
@@ -73,6 +78,10 @@ QString MessageFilter::check(unsigned playerId, QString nick, QString msg)
returnMessage = QString ("<PokerTHCleaner> %1: Warning! You've triggered text flood (lines) protection, slow down your typing!\n").arg(nick);
}
break;
case CAPS_FLOOD: {
returnMessage = QString ("<PokerTHCleaner> %1: Warning: You've triggered caps flood protection, release your caps!\n").arg(nick);
}
break;
default:;
}
}
@@ -99,4 +108,5 @@ void MessageFilter::refreshConfig() {
myBadWordCheck->setBadWords(bwList);
myTextFloodCheck->setTextFloodLevelToTrigger(config->readConfigInt("TextFloodLevelToTrigger"));
myCapsFloodCheck->setCapsNumberToTrigger(config->readConfigInt("CapsFloodCapsNumberToTrigger"));
}
+2
View File
@@ -7,6 +7,7 @@
class BadWordCheck;
class TextFloodCheck;
class CleanerConfig;
class CapsFloodCheck;
class MessageFilter: public QObject {
Q_OBJECT
@@ -19,6 +20,7 @@ public:
private:
BadWordCheck *myBadWordCheck;
TextFloodCheck *myTextFloodCheck;
CapsFloodCheck *myCapsFloodCheck;
struct ClientWarnInfos {
QString nick;