chatcleaner: inital url spam check. configurable url string list and
exceptions list for urls like pokerth.net ;-)
This commit is contained in:
@@ -43,7 +43,7 @@ using namespace std;
|
||||
CleanerConfig::CleanerConfig()
|
||||
{
|
||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||
configRev = 4;
|
||||
configRev = 5;
|
||||
|
||||
// Pfad und Dateinamen setzen
|
||||
#ifdef _WIN32
|
||||
@@ -120,7 +120,6 @@ CleanerConfig::CleanerConfig()
|
||||
configList.push_back(ConfigInfo("LetterRepeatingNumberToTrigger", CONFIG_TYPE_INT, "10"));
|
||||
|
||||
list<string> badWordsList;
|
||||
|
||||
badWordsList.push_back("arsch");
|
||||
badWordsList.push_back("asshole");
|
||||
badWordsList.push_back("bastard");
|
||||
@@ -155,9 +154,22 @@ CleanerConfig::CleanerConfig()
|
||||
badWordsList.push_back("slut");
|
||||
badWordsList.push_back("suck");
|
||||
badWordsList.push_back("whore");
|
||||
|
||||
configList.push_back(ConfigInfo("BadWordsList", CONFIG_TYPE_STRING_LIST, "BadWords", badWordsList));
|
||||
|
||||
list<string> urlStringsList;
|
||||
urlStringsList.push_back("http://");
|
||||
urlStringsList.push_back(".com");
|
||||
urlStringsList.push_back(".net");
|
||||
urlStringsList.push_back(".org");
|
||||
urlStringsList.push_back(".de");
|
||||
configList.push_back(ConfigInfo("UrlStringsList", CONFIG_TYPE_STRING_LIST, "UrlStrings", urlStringsList));
|
||||
|
||||
list<string> urlExceptionStringsList;
|
||||
urlExceptionStringsList.push_back("http://www.esl.");
|
||||
urlExceptionStringsList.push_back("http://www.pokerth.net");
|
||||
urlExceptionStringsList.push_back("pokerth.net");
|
||||
configList.push_back(ConfigInfo("UrlExceptionStringsList", CONFIG_TYPE_STRING_LIST, "UrlExceptionStrings", urlExceptionStringsList));
|
||||
|
||||
//fill tempList firstTime
|
||||
configBufferList = configList;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "cleanerconfig.h"
|
||||
#include "capsfloodcheck.h"
|
||||
#include "letterrepeatingcheck.h"
|
||||
#include "urlcheck.h"
|
||||
|
||||
enum ActionType {
|
||||
NOTHING,
|
||||
@@ -17,7 +18,8 @@ enum OffenceType {
|
||||
BAD_WORD,
|
||||
TEXT_FLOOD_LINES,
|
||||
CAPS_FLOOD,
|
||||
LETTER_REPEATING
|
||||
LETTER_REPEATING,
|
||||
URL
|
||||
};
|
||||
|
||||
MessageFilter::MessageFilter(CleanerConfig *c): config(c)
|
||||
@@ -26,6 +28,7 @@ MessageFilter::MessageFilter(CleanerConfig *c): config(c)
|
||||
myTextFloodCheck = new TextFloodCheck;
|
||||
myCapsFloodCheck = new CapsFloodCheck;
|
||||
myLetterRepeatingCheck = new LetterRepeatingCheck;
|
||||
myUrlCheck = new UrlCheck;
|
||||
}
|
||||
|
||||
QString MessageFilter::check(unsigned playerId, QString nick, QString msg)
|
||||
@@ -38,6 +41,7 @@ QString MessageFilter::check(unsigned playerId, QString nick, QString msg)
|
||||
if(myBadWordCheck->run(msg)) offence = BAD_WORD;
|
||||
if(myCapsFloodCheck->run(msg)) offence = CAPS_FLOOD;
|
||||
if(myLetterRepeatingCheck->run(msg)) offence = LETTER_REPEATING;
|
||||
if(myUrlCheck->run(msg)) offence = URL;
|
||||
if(myTextFloodCheck->run(playerId)) offence = TEXT_FLOOD_LINES;
|
||||
|
||||
if(offence){
|
||||
@@ -90,6 +94,10 @@ QString MessageFilter::check(unsigned playerId, QString nick, QString msg)
|
||||
returnMessage = QString ("<PokerTHCleaner> %1: Warning: You've triggered letter repeating protection, stop repeating!\n").arg(nick);
|
||||
}
|
||||
break;
|
||||
case URL: {
|
||||
returnMessage = QString ("<PokerTHCleaner> %1: Warning: You've triggered url spam protection, stop posting urls!\n").arg(nick);
|
||||
}
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
@@ -115,6 +123,22 @@ void MessageFilter::refreshConfig() {
|
||||
}
|
||||
myBadWordCheck->setBadWords(bwList);
|
||||
|
||||
std::list<std::string> urlStringsList = config->readConfigStringList("UrlStringsList");
|
||||
std::list<std::string>::iterator it2;
|
||||
QStringList urlList;
|
||||
for(it2= urlStringsList.begin(); it2 != urlStringsList.end(); it2++) {
|
||||
urlList << QString::fromUtf8(it2->c_str());
|
||||
}
|
||||
myUrlCheck->setUrlStrings(urlList);
|
||||
|
||||
std::list<std::string> urlExceptionStringsList = config->readConfigStringList("UrlExceptionStringsList");
|
||||
std::list<std::string>::iterator it3;
|
||||
QStringList urlExceptionList;
|
||||
for(it3= urlExceptionStringsList.begin(); it3 != urlExceptionStringsList.end(); it3++) {
|
||||
urlExceptionList << QString::fromUtf8(it3->c_str());
|
||||
}
|
||||
myUrlCheck->setUrlExceptionStrings(urlExceptionList);
|
||||
|
||||
myTextFloodCheck->setTextFloodLevelToTrigger(config->readConfigInt("TextFloodLevelToTrigger"));
|
||||
myCapsFloodCheck->setCapsNumberToTrigger(config->readConfigInt("CapsFloodCapsNumberToTrigger"));
|
||||
myLetterRepeatingCheck->setLetterNumberToTrigger(config->readConfigInt("LetterRepeatingNumberToTrigger"));
|
||||
|
||||
@@ -9,6 +9,7 @@ class TextFloodCheck;
|
||||
class CleanerConfig;
|
||||
class CapsFloodCheck;
|
||||
class LetterRepeatingCheck;
|
||||
class UrlCheck;
|
||||
|
||||
class MessageFilter: public QObject {
|
||||
Q_OBJECT
|
||||
@@ -23,6 +24,7 @@ private:
|
||||
TextFloodCheck *myTextFloodCheck;
|
||||
CapsFloodCheck *myCapsFloodCheck;
|
||||
LetterRepeatingCheck *myLetterRepeatingCheck;
|
||||
UrlCheck *myUrlCheck;
|
||||
|
||||
struct ClientWarnInfos {
|
||||
QString nick;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "urlcheck.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
UrlCheck::UrlCheck()
|
||||
{
|
||||
}
|
||||
|
||||
bool UrlCheck::run(QString msg)
|
||||
{
|
||||
msg = msg.toLower();
|
||||
|
||||
QStringListIterator it1(urlStrings);
|
||||
|
||||
while (it1.hasNext()) {
|
||||
if(msg.contains(it1.next())) {
|
||||
QStringListIterator it2(urlExceptionStrings);
|
||||
bool exception = false;
|
||||
while (it2.hasNext()) {
|
||||
if(msg.contains(it2.next())) {
|
||||
exception = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!exception) { return true; }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef URLCHECK_H
|
||||
#define URLCHECK_H
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class UrlCheck: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
UrlCheck();
|
||||
|
||||
void setUrlStrings(QStringList us) { urlStrings = us; }
|
||||
void setUrlExceptionStrings(QStringList ues) { urlExceptionStrings = ues; }
|
||||
bool run(QString);
|
||||
|
||||
private:
|
||||
|
||||
QStringList urlStrings;
|
||||
QStringList urlExceptionStrings;
|
||||
};
|
||||
|
||||
#endif // URLCHECK_H
|
||||
Reference in New Issue
Block a user