add kick counter list to chatcleaner to kickban disturbing players after multiple kicks for chat offence

This commit is contained in:
doitux
2010-07-13 13:50:43 +00:00
parent a70ae9ddfb
commit a78a9e80ea
3 changed files with 193 additions and 133 deletions
+4 -1
View File
@@ -43,7 +43,7 @@ using namespace std;
CleanerConfig::CleanerConfig()
{
// !!!! Revisionsnummer der Configdefaults !!!!!
configRev = 7;
configRev = 8;
// Pfad und Dateinamen setzen
#ifdef _WIN32
@@ -122,6 +122,9 @@ CleanerConfig::CleanerConfig()
configList.push_back(ConfigInfo("CapsFloodCapsNumberToTrigger", CONFIG_TYPE_INT, "10"));
configList.push_back(ConfigInfo("LetterRepeatingNumberToTrigger", CONFIG_TYPE_INT, "10"));
configList.push_back(ConfigInfo("KickNumberToBan", CONFIG_TYPE_INT, "2"));
configList.push_back(ConfigInfo("SecondsToForgetAboutKick", CONFIG_TYPE_INT, "1800"));
list<string> badWordsList;
badWordsList.push_back("arsch");
badWordsList.push_back("asshole");
+51 -6
View File
@@ -12,7 +12,9 @@
enum ActionType {
NOTHING,
WARN,
KICK };
KICK,
KICKBAN
};
enum OffenceType {
NONE,
@@ -30,6 +32,10 @@ MessageFilter::MessageFilter(CleanerConfig *c): config(c)
myCapsFloodCheck = new CapsFloodCheck;
myLetterRepeatingCheck = new LetterRepeatingCheck;
myUrlCheck = new UrlCheck;
cleanTimer = new QTimer();
connect(cleanTimer, SIGNAL(timeout()), this, SLOT(cleanKickCounterList()));
cleanTimer->start(30000);
}
MessageFilter::~MessageFilter() {
@@ -39,6 +45,7 @@ MessageFilter::~MessageFilter() {
delete myCapsFloodCheck;
delete myLetterRepeatingCheck;
delete myUrlCheck;
delete cleanTimer;
}
QStringList MessageFilter::check(unsigned playerId, QString nick, QString msg)
@@ -70,11 +77,32 @@ QStringList MessageFilter::check(unsigned playerId, QString nick, QString msg)
}
else {
if(i.value().warnLevel == warnLevelToKick || i.value().lastWarnType == offence) {
// Kick Command
// Kick Command
action = KICK;
//remove playerId from all lists and as LAST from myClientWarnLevelList
myTextFloodCheck->removeNickFromList(i.key());
myClientWarnLevelList.remove(i.key());
//check if player is already on kickCounterList
QMap<QString, ClientKickInfos>::const_iterator j = myClientKickCounterList.find(nick);
if(j == myClientKickCounterList.end()) {
//if player is NOT on this list put the playerId on it to ban after multiple offence
ClientKickInfos tmpInfos;
tmpInfos.kickNumber = 1;
tmpInfos.lastKickTimestamp = timer.elapsed().total_seconds();
myClientKickCounterList.insert(nick, tmpInfos);
}
else {
//please is already on the list: either raise kickNumber or kickban when kickNumerToBan is reached
if(j.value().kickNumber == kickNumberToBan) {
action = KICKBAN;
}
else {
ClientKickInfos tmpInfos;
tmpInfos.kickNumber = j.value().kickNumber+1;
tmpInfos.lastKickTimestamp = timer.elapsed().total_seconds();
myClientKickCounterList.insert(nick, tmpInfos);
}
}
}
else {
ClientWarnInfos tmpInfos;
@@ -86,10 +114,6 @@ QStringList MessageFilter::check(unsigned playerId, QString nick, QString msg)
}
}
if(action == KICK) {
returnMessage = QString("Kick: %1\n").arg(nick);
returnAction = QString("kick");
}
if(action == WARN) {
switch(offence) {
@@ -117,6 +141,14 @@ QStringList MessageFilter::check(unsigned playerId, QString nick, QString msg)
}
returnAction = QString("warn");
}
else if(action == KICK) {
returnMessage = QString("%1 kicked! Please respect: http://chatrules.pokerth.net\n").arg(nick);
returnAction = QString("kick");
}
else if(action == KICKBAN) {
returnMessage = QString("%1 kicked and banned! Please respect: http://chatrules.pokerth.net\n").arg(nick);
returnAction = QString("kickban");
}
}
else {
returnAction = QString("");
@@ -131,6 +163,7 @@ void MessageFilter::refreshConfig() {
// global settings
warnLevelToKick = config->readConfigInt("WarnLevelToKick");
kickNumberToBan = config->readConfigInt("KickNumberToBan");
// special check settings
//Bad Words
@@ -163,3 +196,15 @@ void MessageFilter::refreshConfig() {
myLetterRepeatingCheck->setLetterNumberToTrigger(config->readConfigInt("LetterRepeatingNumberToTrigger"));
}
void MessageFilter::cleanKickCounterList()
{
QMapIterator<QString, ClientKickInfos> it(myClientKickCounterList);
while (it.hasNext()) {
it.next();
if(timer.elapsed().total_seconds()-it.value().lastKickTimestamp > config->readConfigInt("SecondsToForgetAboutKick")) {
qDebug() << it.key() << "removed from kick counter list" << endl;
myClientKickCounterList.remove(it.key());
}
}
}
+12
View File
@@ -3,6 +3,7 @@
#include <QtCore>
#include <stdlib.h>
#include <third_party/boost/timers.hpp>
class BadWordCheck;
class TextFloodCheck;
@@ -19,6 +20,7 @@ public:
QStringList check(unsigned, QString, QString);
void refreshConfig();
void cleanKickCounterList();
private:
BadWordCheck *myBadWordCheck;
@@ -33,11 +35,21 @@ private:
int warnLevel;
};
struct ClientKickInfos {
size_t lastKickTimestamp;
int kickNumber;
};
QMap<unsigned, ClientWarnInfos> myClientWarnLevelList;
QMap<QString, ClientKickInfos> myClientKickCounterList;
int warnLevelToKick;
int kickNumberToBan;
CleanerConfig *config;
boost::timers::portable::second_timer timer;
QTimer *cleanTimer;
};
#endif // MESSAGEFILTER_H