initial capsfloodcheck support
This commit is contained in:
+6
-4
@@ -5,7 +5,8 @@ CODECFORSRC = UTF-8
|
|||||||
QT += network
|
QT += network
|
||||||
QT -= gui
|
QT -= gui
|
||||||
TARGET = chatcleaner
|
TARGET = chatcleaner
|
||||||
CONFIG += console debug
|
CONFIG += console \
|
||||||
|
debug
|
||||||
CONFIG -= app_bundle
|
CONFIG -= app_bundle
|
||||||
MOC_DIR = mocs
|
MOC_DIR = mocs
|
||||||
OBJECTS_DIR = obj
|
OBJECTS_DIR = obj
|
||||||
@@ -25,12 +26,13 @@ SOURCES += chatcleaner.cpp \
|
|||||||
tinystr.cpp \
|
tinystr.cpp \
|
||||||
tinyxml.cpp \
|
tinyxml.cpp \
|
||||||
tinyxmlerror.cpp \
|
tinyxmlerror.cpp \
|
||||||
tinyxmlparser.cpp
|
tinyxmlparser.cpp \
|
||||||
|
capsfloodcheck.cpp
|
||||||
HEADERS += cleanerserver.h \
|
HEADERS += cleanerserver.h \
|
||||||
messagefilter.h \
|
messagefilter.h \
|
||||||
badwordcheck.h \
|
badwordcheck.h \
|
||||||
textfloodcheck.h \
|
textfloodcheck.h \
|
||||||
cleanerconfig.h \
|
cleanerconfig.h \
|
||||||
tinyxml.h \
|
tinyxml.h \
|
||||||
tinystr.h
|
tinystr.h \
|
||||||
|
capsfloodcheck.h
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -43,7 +43,7 @@ using namespace std;
|
|||||||
CleanerConfig::CleanerConfig()
|
CleanerConfig::CleanerConfig()
|
||||||
{
|
{
|
||||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||||
configRev = 2;
|
configRev = 3;
|
||||||
|
|
||||||
// Pfad und Dateinamen setzen
|
// Pfad und Dateinamen setzen
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -116,6 +116,7 @@ CleanerConfig::CleanerConfig()
|
|||||||
configList.push_back(ConfigInfo("DefaultListenPort", CONFIG_TYPE_STRING, "4327"));
|
configList.push_back(ConfigInfo("DefaultListenPort", CONFIG_TYPE_STRING, "4327"));
|
||||||
configList.push_back(ConfigInfo("WarnLevelToKick", CONFIG_TYPE_INT, "2"));
|
configList.push_back(ConfigInfo("WarnLevelToKick", CONFIG_TYPE_INT, "2"));
|
||||||
configList.push_back(ConfigInfo("TextFloodLevelToTrigger", CONFIG_TYPE_INT, "3"));
|
configList.push_back(ConfigInfo("TextFloodLevelToTrigger", CONFIG_TYPE_INT, "3"));
|
||||||
|
configList.push_back(ConfigInfo("CapsFloodCapsNumberToTrigger", CONFIG_TYPE_INT, "10"));
|
||||||
|
|
||||||
list<string> badWordsList;
|
list<string> badWordsList;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "badwordcheck.h"
|
#include "badwordcheck.h"
|
||||||
#include "textfloodcheck.h"
|
#include "textfloodcheck.h"
|
||||||
#include "cleanerconfig.h"
|
#include "cleanerconfig.h"
|
||||||
|
#include "capsfloodcheck.h"
|
||||||
|
|
||||||
enum ActionType {
|
enum ActionType {
|
||||||
NOTHING,
|
NOTHING,
|
||||||
@@ -13,12 +14,15 @@ enum ActionType {
|
|||||||
enum OffenceType {
|
enum OffenceType {
|
||||||
NONE,
|
NONE,
|
||||||
BAD_WORD,
|
BAD_WORD,
|
||||||
TEXT_FLOOD_LINES };
|
TEXT_FLOOD_LINES,
|
||||||
|
CAPS_FLOOD
|
||||||
|
};
|
||||||
|
|
||||||
MessageFilter::MessageFilter(CleanerConfig *c): config(c)
|
MessageFilter::MessageFilter(CleanerConfig *c): config(c)
|
||||||
{
|
{
|
||||||
myBadWordCheck = new BadWordCheck;
|
myBadWordCheck = new BadWordCheck;
|
||||||
myTextFloodCheck = new TextFloodCheck;
|
myTextFloodCheck = new TextFloodCheck;
|
||||||
|
myCapsFloodCheck = new CapsFloodCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessageFilter::check(unsigned playerId, QString nick, QString msg)
|
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;
|
ActionType action = NOTHING;
|
||||||
|
|
||||||
if(myBadWordCheck->run(msg)) offence = BAD_WORD;
|
if(myBadWordCheck->run(msg)) offence = BAD_WORD;
|
||||||
|
if(myCapsFloodCheck->run(msg)) offence = CAPS_FLOOD;
|
||||||
if(myTextFloodCheck->run(playerId)) offence = TEXT_FLOOD_LINES;
|
if(myTextFloodCheck->run(playerId)) offence = TEXT_FLOOD_LINES;
|
||||||
|
|
||||||
if(offence){
|
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);
|
returnMessage = QString ("<PokerTHCleaner> %1: Warning! You've triggered text flood (lines) protection, slow down your typing!\n").arg(nick);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CAPS_FLOOD: {
|
||||||
|
returnMessage = QString ("<PokerTHCleaner> %1: Warning: You've triggered caps flood protection, release your caps!\n").arg(nick);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,4 +108,5 @@ void MessageFilter::refreshConfig() {
|
|||||||
myBadWordCheck->setBadWords(bwList);
|
myBadWordCheck->setBadWords(bwList);
|
||||||
|
|
||||||
myTextFloodCheck->setTextFloodLevelToTrigger(config->readConfigInt("TextFloodLevelToTrigger"));
|
myTextFloodCheck->setTextFloodLevelToTrigger(config->readConfigInt("TextFloodLevelToTrigger"));
|
||||||
|
myCapsFloodCheck->setCapsNumberToTrigger(config->readConfigInt("CapsFloodCapsNumberToTrigger"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
class BadWordCheck;
|
class BadWordCheck;
|
||||||
class TextFloodCheck;
|
class TextFloodCheck;
|
||||||
class CleanerConfig;
|
class CleanerConfig;
|
||||||
|
class CapsFloodCheck;
|
||||||
|
|
||||||
class MessageFilter: public QObject {
|
class MessageFilter: public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -19,6 +20,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
BadWordCheck *myBadWordCheck;
|
BadWordCheck *myBadWordCheck;
|
||||||
TextFloodCheck *myTextFloodCheck;
|
TextFloodCheck *myTextFloodCheck;
|
||||||
|
CapsFloodCheck *myCapsFloodCheck;
|
||||||
|
|
||||||
struct ClientWarnInfos {
|
struct ClientWarnInfos {
|
||||||
QString nick;
|
QString nick;
|
||||||
|
|||||||
Reference in New Issue
Block a user