#include "messagefilter.h" #include #include "badwordcheck.h" #include "textfloodcheck.h" #include "cleanerconfig.h" #include "capsfloodcheck.h" enum ActionType { NOTHING, WARN, KICK }; enum OffenceType { NONE, BAD_WORD, 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) { QString returnMessage; OffenceType offence = NONE; 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){ QMap::const_iterator i = myClientWarnLevelList.find(playerId); if(i == myClientWarnLevelList.end()) { myClientWarnInfos.warnLevel = 1; myClientWarnInfos.lastWarnType = offence; myClientWarnInfos.nick = nick; myClientWarnLevelList.insert(playerId, myClientWarnInfos); action = WARN; } else { if(i.value().warnLevel == warnLevelToKick || i.value().lastWarnType == offence) { // Kick Command action = KICK; //remove playerId from all lists and as LAST from myClientWarnLevelList myTextFloodCheck->removeNickFromList(i.key()); myClientWarnLevelList.remove(i.key()); } else { myClientWarnInfos.warnLevel++; myClientWarnInfos.lastWarnType = offence; myClientWarnInfos.nick = nick; myClientWarnLevelList.insert(playerId, myClientWarnInfos); action = WARN; } } if(action == KICK) { returnMessage = QString("Kick: %1\n").arg(nick); } if(action == WARN) { switch(offence) { case BAD_WORD: { returnMessage = QString (" %1: Warning! No racial, religious, or sexually inflammatory language!\n").arg(nick); } break; case TEXT_FLOOD_LINES: { returnMessage = QString (" %1: Warning! You've triggered text flood (lines) protection, slow down your typing!\n").arg(nick); } break; case CAPS_FLOOD: { returnMessage = QString (" %1: Warning: You've triggered caps flood protection, release your caps!\n").arg(nick); } break; default:; } } } else { returnMessage = QString(""); } return returnMessage; } void MessageFilter::refreshConfig() { // global settings warnLevelToKick = config->readConfigInt("WarnLevelToKick"); // special check settings //Bad Words std::list badWordsList = config->readConfigStringList("BadWordsList"); std::list::iterator it1; QStringList bwList; for(it1= badWordsList.begin(); it1 != badWordsList.end(); it1++) { bwList << QString::fromUtf8(it1->c_str()); } myBadWordCheck->setBadWords(bwList); myTextFloodCheck->setTextFloodLevelToTrigger(config->readConfigInt("TextFloodLevelToTrigger")); myCapsFloodCheck->setCapsNumberToTrigger(config->readConfigInt("CapsFloodCapsNumberToTrigger")); }