Reformatting code using Kernighan & Ritchie style, tabs, tab width=4.
Command line: astyle --style=kr --indent=force-tab=4 --lineend=linux -n -r <file names>
This commit is contained in:
@@ -6,10 +6,10 @@ BadWordCheck::BadWordCheck()
|
||||
{
|
||||
}
|
||||
|
||||
bool BadWordCheck::run(QString msg)
|
||||
bool BadWordCheck::run(QString msg)
|
||||
{
|
||||
msg = msg.toLower();
|
||||
|
||||
|
||||
QStringListIterator it(badWords);
|
||||
while (it.hasNext()) {
|
||||
if(msg.contains(it.next()))
|
||||
|
||||
@@ -3,17 +3,20 @@
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class BadWordCheck: public QObject {
|
||||
Q_OBJECT
|
||||
class BadWordCheck: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BadWordCheck();
|
||||
|
||||
void setBadWords(QStringList bw) { badWords = bw; }
|
||||
|
||||
BadWordCheck();
|
||||
|
||||
void setBadWords(QStringList bw) {
|
||||
badWords = bw;
|
||||
}
|
||||
|
||||
bool run(QString);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
QStringList badWords;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include <QtCore>
|
||||
|
||||
CapsFloodCheck::CapsFloodCheck()
|
||||
: capsNumberToTrigger(0)
|
||||
: capsNumberToTrigger(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool CapsFloodCheck::run(QString msg)
|
||||
bool CapsFloodCheck::run(QString msg)
|
||||
{
|
||||
msg = msg.simplified().remove(" ");
|
||||
QRegExp e(QString("[A-Z]{%1,}").arg(capsNumberToTrigger));
|
||||
@@ -16,8 +16,7 @@ bool CapsFloodCheck::run(QString msg)
|
||||
e.indexIn(msg);
|
||||
if(e.matchedLength() != -1 ) return true;
|
||||
else return false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// qDebug() << "The current Caps Flood RegExp is invalid" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class CapsFloodCheck: public QObject {
|
||||
Q_OBJECT
|
||||
class CapsFloodCheck: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CapsFloodCheck();
|
||||
|
||||
void setCapsNumberToTrigger(int n) { capsNumberToTrigger = n; }
|
||||
CapsFloodCheck();
|
||||
|
||||
void setCapsNumberToTrigger(int n) {
|
||||
capsNumberToTrigger = n;
|
||||
}
|
||||
bool run(QString);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int capsNumberToTrigger;
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
#include "cleanerserver.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <process.h>
|
||||
#include <process.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#ifndef daemon
|
||||
int daemon(int, int);
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#ifndef daemon
|
||||
int daemon(int, int);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
QCoreApplication a(argc, argv);
|
||||
CleanerServer server;
|
||||
#ifndef _WIN32
|
||||
if (daemon(0, 0) != 0)
|
||||
return -1;
|
||||
#endif
|
||||
return a.exec();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
+158
-148
@@ -43,15 +43,14 @@ using namespace std;
|
||||
CleanerConfig::CleanerConfig()
|
||||
{
|
||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||
configRev = 8;
|
||||
|
||||
configRev = 8;
|
||||
|
||||
// Pfad und Dateinamen setzen
|
||||
#ifdef _WIN32
|
||||
const char *appDataPath = getenv("AppData");
|
||||
if (appDataPath && appDataPath[0] != 0) {
|
||||
configFileName = appDataPath;
|
||||
}
|
||||
else {
|
||||
configFileName = appDataPath;
|
||||
} else {
|
||||
const int MaxPathSize = 1024;
|
||||
char curDir[MaxPathSize + 1];
|
||||
curDir[0] = 0;
|
||||
@@ -67,8 +66,7 @@ CleanerConfig::CleanerConfig()
|
||||
// Datei wieder loeschen.
|
||||
tmpFile.close();
|
||||
remove((configFileName + "\\" + tmpFileName).c_str());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Fehlgeschlagen, Verzeichnis nicht beschreibbar
|
||||
curDir[0] = 0;
|
||||
GetTempPathA(MaxPathSize, curDir);
|
||||
@@ -81,12 +79,12 @@ CleanerConfig::CleanerConfig()
|
||||
////define log-dir
|
||||
// logDir = configFileName;
|
||||
// logDir += "log-files\\";
|
||||
|
||||
|
||||
//create directories on first start of app
|
||||
mkdir(configFileName.c_str());
|
||||
// mkdir(logDir.c_str());
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
//define app-dir
|
||||
const char *homePath = getenv("HOME");
|
||||
@@ -99,9 +97,9 @@ CleanerConfig::CleanerConfig()
|
||||
//create directories on first start of app
|
||||
mkdir(configFileName.c_str(), MODUS) ;
|
||||
// mkdir(logDir.c_str(), MODUS);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
string userDir = configFileName.c_str();
|
||||
@@ -116,15 +114,15 @@ CleanerConfig::CleanerConfig()
|
||||
configList.push_back(ConfigInfo("DefaultListenPort", CONFIG_TYPE_STRING, "4327"));
|
||||
configList.push_back(ConfigInfo("ClientAuthString", CONFIG_TYPE_STRING, ""));
|
||||
configList.push_back(ConfigInfo("ServerAuthString", CONFIG_TYPE_STRING, ""));
|
||||
|
||||
|
||||
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"));
|
||||
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"));
|
||||
|
||||
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");
|
||||
@@ -169,38 +167,39 @@ CleanerConfig::CleanerConfig()
|
||||
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;
|
||||
|
||||
configFileName += "cleanerconfig.xml";
|
||||
|
||||
//Prüfen ob Configfile existiert --> sonst anlegen
|
||||
TiXmlDocument doc(configFileName);
|
||||
if(!doc.LoadFile()){
|
||||
myConfigState = NONEXISTING;
|
||||
updateConfig(myConfigState);
|
||||
}
|
||||
else {
|
||||
//Check if config revision is ok. Otherwise --> update()
|
||||
int tempRevision = 0;
|
||||
|
||||
TiXmlHandle docHandle( &doc );
|
||||
TiXmlElement* confRevision = docHandle.FirstChild( "PokerTHCleaner" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement();
|
||||
if ( confRevision ) { confRevision->QueryIntAttribute("value", &tempRevision ); }
|
||||
|
||||
if (tempRevision < configRev ) { /*löschen()*/
|
||||
//Prüfen ob Configfile existiert --> sonst anlegen
|
||||
TiXmlDocument doc(configFileName);
|
||||
if(!doc.LoadFile()) {
|
||||
myConfigState = NONEXISTING;
|
||||
updateConfig(myConfigState);
|
||||
} else {
|
||||
//Check if config revision is ok. Otherwise --> update()
|
||||
int tempRevision = 0;
|
||||
|
||||
TiXmlHandle docHandle( &doc );
|
||||
TiXmlElement* confRevision = docHandle.FirstChild( "PokerTHCleaner" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement();
|
||||
if ( confRevision ) {
|
||||
confRevision->QueryIntAttribute("value", &tempRevision );
|
||||
}
|
||||
|
||||
if (tempRevision < configRev ) { /*löschen()*/
|
||||
myConfigState = OLD;
|
||||
updateConfig(myConfigState) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fillBuffer();
|
||||
}
|
||||
@@ -211,20 +210,21 @@ CleanerConfig::~CleanerConfig()
|
||||
}
|
||||
|
||||
|
||||
void CleanerConfig::fillBuffer() {
|
||||
void CleanerConfig::fillBuffer()
|
||||
{
|
||||
|
||||
string tempString1("");
|
||||
string tempString2("");
|
||||
|
||||
TiXmlDocument doc(configFileName);
|
||||
|
||||
TiXmlDocument doc(configFileName);
|
||||
|
||||
if(doc.LoadFile()) {
|
||||
TiXmlHandle docHandle( &doc );
|
||||
TiXmlHandle docHandle( &doc );
|
||||
|
||||
for (size_t i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
|
||||
TiXmlElement* conf = docHandle.FirstChild( "PokerTHCleaner" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement();
|
||||
|
||||
|
||||
if ( conf ) {
|
||||
|
||||
const char *tmpStr1 = conf->Attribute("value");
|
||||
@@ -233,38 +233,40 @@ void CleanerConfig::fillBuffer() {
|
||||
|
||||
const char *tmpStr2 = conf->Attribute("type");
|
||||
if (tmpStr2) {
|
||||
tempString2 = tmpStr2;
|
||||
tempString2 = tmpStr2;
|
||||
if(tempString2 == "list") {
|
||||
|
||||
|
||||
list<string> tempStringList2;
|
||||
|
||||
TiXmlElement* confList = docHandle.FirstChild( "PokerTHCleaner" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).FirstChild().ToElement();
|
||||
|
||||
|
||||
for( ; confList; confList=confList->NextSiblingElement()) {
|
||||
tempStringList2.push_back(confList->Attribute("value"));
|
||||
}
|
||||
|
||||
|
||||
configBufferList[i].defaultListValue = tempStringList2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { qDebug("Could not find the root element in the config file!"); }
|
||||
} else {
|
||||
qDebug("Could not find the root element in the config file!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CleanerConfig::writeBuffer() const {
|
||||
void CleanerConfig::writeBuffer() const
|
||||
{
|
||||
|
||||
TiXmlDocument doc;
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
||||
doc.LinkEndChild( decl );
|
||||
|
||||
TiXmlElement * root = new TiXmlElement( "PokerTHCleaner" );
|
||||
doc.LinkEndChild( root );
|
||||
|
||||
TiXmlDocument doc;
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
||||
doc.LinkEndChild( decl );
|
||||
|
||||
TiXmlElement * root = new TiXmlElement( "PokerTHCleaner" );
|
||||
doc.LinkEndChild( root );
|
||||
|
||||
TiXmlElement * config;
|
||||
config = new TiXmlElement( "Configuration" );
|
||||
root->LinkEndChild( config );
|
||||
config = new TiXmlElement( "Configuration" );
|
||||
root->LinkEndChild( config );
|
||||
|
||||
size_t i;
|
||||
|
||||
@@ -272,42 +274,43 @@ void CleanerConfig::writeBuffer() const {
|
||||
TiXmlElement *tmpElement = new TiXmlElement(configBufferList[i].name);
|
||||
config->LinkEndChild( tmpElement );
|
||||
tmpElement->SetAttribute("value", configBufferList[i].defaultValue);
|
||||
|
||||
|
||||
if(configBufferList[i].type == CONFIG_TYPE_INT_LIST || configBufferList[i].type == CONFIG_TYPE_STRING_LIST) {
|
||||
|
||||
tmpElement->SetAttribute("type", "list");
|
||||
list<string> tempList = configBufferList[i].defaultListValue;
|
||||
list<string>::iterator it;
|
||||
for(it = tempList.begin(); it != tempList.end(); ++it) {
|
||||
|
||||
|
||||
TiXmlElement *tmpSubElement = new TiXmlElement(configBufferList[i].defaultValue);
|
||||
tmpElement->LinkEndChild( tmpSubElement );
|
||||
tmpSubElement->SetAttribute("value", *it);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
doc.SaveFile( configFileName );
|
||||
|
||||
}
|
||||
|
||||
void CleanerConfig::updateConfig(ConfigState myConfigState) {
|
||||
void CleanerConfig::updateConfig(ConfigState myConfigState)
|
||||
{
|
||||
|
||||
size_t i;
|
||||
|
||||
|
||||
if(myConfigState == NONEXISTING) {
|
||||
|
||||
|
||||
//Create a new ConfigFile!
|
||||
TiXmlDocument doc;
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
||||
doc.LinkEndChild( decl );
|
||||
|
||||
TiXmlElement * root = new TiXmlElement( "PokerTHCleaner" );
|
||||
doc.LinkEndChild( root );
|
||||
|
||||
TiXmlDocument doc;
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
||||
doc.LinkEndChild( decl );
|
||||
|
||||
TiXmlElement * root = new TiXmlElement( "PokerTHCleaner" );
|
||||
doc.LinkEndChild( root );
|
||||
|
||||
TiXmlElement * config;
|
||||
config = new TiXmlElement( "Configuration" );
|
||||
root->LinkEndChild( config );
|
||||
config = new TiXmlElement( "Configuration" );
|
||||
root->LinkEndChild( config );
|
||||
|
||||
for (i=0; i<configList.size(); i++) {
|
||||
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
|
||||
@@ -320,7 +323,7 @@ void CleanerConfig::updateConfig(ConfigState myConfigState) {
|
||||
list<string> tempList = configList[i].defaultListValue;
|
||||
list<string>::iterator it;
|
||||
for(it = tempList.begin(); it != tempList.end(); ++it) {
|
||||
|
||||
|
||||
TiXmlElement *tmpSubElement = new TiXmlElement(configList[i].defaultValue);
|
||||
tmpElement->LinkEndChild( tmpSubElement );
|
||||
tmpSubElement->SetAttribute("value", *it);
|
||||
@@ -328,77 +331,77 @@ void CleanerConfig::updateConfig(ConfigState myConfigState) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
doc.SaveFile( configFileName );
|
||||
}
|
||||
|
||||
|
||||
if(myConfigState == OLD) {
|
||||
|
||||
TiXmlDocument oldDoc(configFileName);
|
||||
|
||||
|
||||
TiXmlDocument oldDoc(configFileName);
|
||||
|
||||
//load the old one
|
||||
if(oldDoc.LoadFile()) {
|
||||
|
||||
string tempString1("");
|
||||
string tempString2("");
|
||||
|
||||
TiXmlDocument newDoc;
|
||||
|
||||
//Create the new one
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
||||
newDoc.LinkEndChild( decl );
|
||||
|
||||
TiXmlElement * root = new TiXmlElement( "PokerTHCleaner" );
|
||||
newDoc.LinkEndChild( root );
|
||||
|
||||
TiXmlElement * config;
|
||||
config = new TiXmlElement( "Configuration" );
|
||||
root->LinkEndChild( config );
|
||||
|
||||
//change configRev and AppDataPath
|
||||
TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" );
|
||||
string tempString1("");
|
||||
string tempString2("");
|
||||
|
||||
TiXmlDocument newDoc;
|
||||
|
||||
//Create the new one
|
||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
||||
newDoc.LinkEndChild( decl );
|
||||
|
||||
TiXmlElement * root = new TiXmlElement( "PokerTHCleaner" );
|
||||
newDoc.LinkEndChild( root );
|
||||
|
||||
TiXmlElement * config;
|
||||
config = new TiXmlElement( "Configuration" );
|
||||
root->LinkEndChild( config );
|
||||
|
||||
//change configRev and AppDataPath
|
||||
TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" );
|
||||
config->LinkEndChild( confElement0 );
|
||||
confElement0->SetAttribute("value", configRev);
|
||||
|
||||
TiXmlHandle oldDocHandle( &oldDoc );
|
||||
TiXmlHandle oldDocHandle( &oldDoc );
|
||||
|
||||
for (i=0; i<configList.size(); i++) {
|
||||
for (i=0; i<configList.size(); i++) {
|
||||
|
||||
TiXmlElement* oldConf = oldDocHandle.FirstChild( "PokerTHCleaner" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement();
|
||||
|
||||
|
||||
if ( oldConf ) {
|
||||
// if element is already there --> take over the saved values
|
||||
|
||||
// if element is already there --> take over the saved values
|
||||
|
||||
if(configList[i].name != "ConfigRevision") {
|
||||
// dont update ConfigRevision because it was already set ^
|
||||
|
||||
// dont update ConfigRevision because it was already set ^
|
||||
|
||||
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
|
||||
config->LinkEndChild( tmpElement );
|
||||
|
||||
|
||||
const char *tmpStr1 = oldConf->Attribute("value");
|
||||
if (tmpStr1) tempString1 = tmpStr1;
|
||||
tmpElement->SetAttribute("value", tempString1);
|
||||
|
||||
|
||||
//for lists copy elements
|
||||
const char *tmpStr2 = oldConf->Attribute("type");
|
||||
if (tmpStr2) {
|
||||
tempString2 = tmpStr2;
|
||||
tempString2 = tmpStr2;
|
||||
if(tempString2 == "list") {
|
||||
|
||||
|
||||
list<string> tempStringList2;
|
||||
|
||||
|
||||
TiXmlElement* oldConfList = oldDocHandle.FirstChild( "PokerTHCleaner" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).FirstChild().ToElement();
|
||||
|
||||
|
||||
for( ; oldConfList; oldConfList=oldConfList->NextSiblingElement()) {
|
||||
tempStringList2.push_back(oldConfList->Attribute("value"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tmpElement->SetAttribute("type", "list");
|
||||
list<string> tempList = tempStringList2;
|
||||
list<string>::iterator it;
|
||||
for(it = tempList.begin(); it != tempList.end(); ++it) {
|
||||
|
||||
|
||||
TiXmlElement *tmpSubElement = new TiXmlElement(tempString1);
|
||||
tmpElement->LinkEndChild( tmpSubElement );
|
||||
tmpSubElement->SetAttribute("value", *it);
|
||||
@@ -406,32 +409,32 @@ void CleanerConfig::updateConfig(ConfigState myConfigState) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// if element is not there --> set it with defaultValue
|
||||
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
|
||||
config->LinkEndChild( tmpElement );
|
||||
tmpElement->SetAttribute("value", stringToUtf8(configList[i].defaultValue));
|
||||
|
||||
|
||||
if(configList[i].type == CONFIG_TYPE_INT_LIST || configList[i].type == CONFIG_TYPE_STRING_LIST) {
|
||||
|
||||
|
||||
tmpElement->SetAttribute("type", "list");
|
||||
list<string> tempList = configList[i].defaultListValue;
|
||||
list<string>::iterator it;
|
||||
for(it = tempList.begin(); it != tempList.end(); ++it) {
|
||||
|
||||
|
||||
TiXmlElement *tmpSubElement = new TiXmlElement(configList[i].defaultValue);
|
||||
tmpElement->LinkEndChild( tmpSubElement );
|
||||
tmpSubElement->SetAttribute("value", *it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
newDoc.SaveFile( configFileName );
|
||||
} else {
|
||||
qDebug("Cannot update config file: Unable to load configuration.");
|
||||
}
|
||||
else { qDebug("Cannot update config file: Unable to load configuration."); }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,15 +444,15 @@ string CleanerConfig::readConfigString(string varName) const
|
||||
size_t i;
|
||||
string tempString("");
|
||||
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
if (configBufferList[i].name == varName) {
|
||||
tempString = configBufferList[i].defaultValue;
|
||||
tempString = configBufferList[i].defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return tempString;
|
||||
}
|
||||
}
|
||||
|
||||
int CleanerConfig::readConfigInt(string varName) const
|
||||
{
|
||||
@@ -458,35 +461,35 @@ int CleanerConfig::readConfigInt(string varName) const
|
||||
string tempString("");
|
||||
int tempInt=0;
|
||||
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
if (configBufferList[i].name == varName) {
|
||||
tempString = configBufferList[i].defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
istringstream isst;
|
||||
isst.str (tempString);
|
||||
isst >> tempInt;
|
||||
|
||||
|
||||
return tempInt;
|
||||
}
|
||||
|
||||
list<string> CleanerConfig::readConfigStringList(string varName) const
|
||||
{
|
||||
|
||||
size_t i;
|
||||
size_t i;
|
||||
list<string> tempStringList;
|
||||
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
if (configBufferList[i].name == varName) {
|
||||
tempStringList = configBufferList[i].defaultListValue;
|
||||
tempStringList = configBufferList[i].defaultListValue;
|
||||
}
|
||||
}
|
||||
|
||||
return tempStringList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
list<int> CleanerConfig::readConfigIntList(string varName) const
|
||||
@@ -496,19 +499,19 @@ list<int> CleanerConfig::readConfigIntList(string varName) const
|
||||
list<string> tempStringList;
|
||||
list<int> tempIntList;
|
||||
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
if (configBufferList[i].name == varName) {
|
||||
tempStringList = configBufferList[i].defaultListValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
istringstream isst;
|
||||
string tempString;
|
||||
int tempInt;
|
||||
list<string>::iterator it;
|
||||
for(it = tempStringList.begin(); it != tempStringList.end(); ++it) {
|
||||
|
||||
|
||||
isst.str(*it);
|
||||
isst >> tempInt;
|
||||
tempIntList.push_back(tempInt);
|
||||
@@ -527,11 +530,11 @@ void CleanerConfig::writeConfigInt(string varName, int varCont)
|
||||
string tempString;
|
||||
ostringstream intToString;
|
||||
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
if (configBufferList[i].name == varName) {
|
||||
intToString << varCont;
|
||||
configBufferList[i].defaultValue = intToString.str();
|
||||
configBufferList[i].defaultValue = intToString.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -544,20 +547,20 @@ void CleanerConfig::writeConfigIntList(string varName, list<int> varCont)
|
||||
ostringstream intToString;
|
||||
list<string> stringList;
|
||||
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
if (configBufferList[i].name == varName) {
|
||||
string tempString;
|
||||
list<int>::iterator it;
|
||||
for(it = varCont.begin(); it != varCont.end(); ++it) {
|
||||
|
||||
intToString << (*it);
|
||||
|
||||
intToString << (*it);
|
||||
stringList.push_back(intToString.str());
|
||||
intToString.str("");
|
||||
intToString.clear();
|
||||
}
|
||||
|
||||
configBufferList[i].defaultListValue = stringList;
|
||||
|
||||
configBufferList[i].defaultListValue = stringList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -568,11 +571,11 @@ void CleanerConfig::writeConfigStringList(string varName, list<string> varCont)
|
||||
size_t i;
|
||||
list<string> stringList;
|
||||
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
|
||||
if (configBufferList[i].name == varName) {
|
||||
|
||||
configBufferList[i].defaultListValue = varCont;
|
||||
|
||||
configBufferList[i].defaultListValue = varCont;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -581,23 +584,30 @@ void CleanerConfig::writeConfigString(string varName, string varCont)
|
||||
{
|
||||
|
||||
size_t i;
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
if (configBufferList[i].name == varName) { configBufferList[i].defaultValue = varCont; }
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
if (configBufferList[i].name == varName) {
|
||||
configBufferList[i].defaultValue = varCont;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
std::string CleanerConfig::stringToUtf8(const std::string &myString) {
|
||||
std::string CleanerConfig::stringToUtf8(const std::string &myString)
|
||||
{
|
||||
|
||||
QString tmpString = QString::fromStdString(myString);
|
||||
std::string myUtf8String = tmpString.toUtf8().constData();
|
||||
|
||||
|
||||
return myUtf8String;
|
||||
}
|
||||
|
||||
std::string CleanerConfig::stringFromUtf8(const std::string &myString) {
|
||||
std::string CleanerConfig::stringFromUtf8(const std::string &myString)
|
||||
{
|
||||
QString tmpString = QString::fromUtf8(myString.c_str());
|
||||
|
||||
|
||||
return tmpString.toStdString();
|
||||
}
|
||||
|
||||
std::string CleanerConfig::getDefaultLanguage() { return QLocale::system().name().toStdString(); }
|
||||
std::string CleanerConfig::getDefaultLanguage()
|
||||
{
|
||||
return QLocale::system().name().toStdString();
|
||||
}
|
||||
|
||||
@@ -28,14 +28,17 @@ enum ConfigState { NONEXISTING, OLD };
|
||||
enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING, CONFIG_TYPE_INT_LIST, CONFIG_TYPE_STRING_LIST };
|
||||
|
||||
|
||||
class CleanerConfig{
|
||||
class CleanerConfig
|
||||
{
|
||||
public:
|
||||
CleanerConfig();
|
||||
|
||||
~CleanerConfig();
|
||||
|
||||
std::string getConfigFileName() const { return configFileName; }
|
||||
|
||||
|
||||
std::string getConfigFileName() const {
|
||||
return configFileName;
|
||||
}
|
||||
|
||||
void fillBuffer();
|
||||
void writeBuffer() const;
|
||||
|
||||
@@ -45,7 +48,7 @@ public:
|
||||
std::string readConfigString(std::string varName) const;
|
||||
std::list<int> readConfigIntList(std::string varName) const;
|
||||
std::list<std::string> readConfigStringList(std::string varName) const;
|
||||
|
||||
|
||||
void writeConfigInt(std::string varName, int varCont);
|
||||
void writeConfigString(std::string varName, std::string varCont);
|
||||
void writeConfigIntList(std::string varName, std::list<int> varCont);
|
||||
@@ -57,16 +60,15 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
struct ConfigInfo
|
||||
{
|
||||
struct ConfigInfo {
|
||||
ConfigInfo(const std::string &n, ConfigType t, const std::string &d, const std::list<std::string> &l =std::list<std::string>()) : name(n), type(t), defaultValue(d), defaultListValue(l) {}
|
||||
std::string name;
|
||||
ConfigType type;
|
||||
std::string defaultValue;
|
||||
std::list<std::string> defaultListValue;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
std::vector<ConfigInfo> configList;
|
||||
std::vector<ConfigInfo> configBufferList;
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ CleanerServer::CleanerServer(): config(0), blockConnection(false), m_recvBufUsed
|
||||
configRefreshTimer->start(10000);
|
||||
}
|
||||
|
||||
CleanerServer::~CleanerServer()
|
||||
CleanerServer::~CleanerServer()
|
||||
{
|
||||
delete config;
|
||||
delete myMessageFilter;
|
||||
@@ -59,24 +59,19 @@ void CleanerServer::onRead()
|
||||
{
|
||||
qint64 bytesRead = tcpSocket->read((char *)m_recvBuf + m_recvBufUsed, sizeof(m_recvBuf) - m_recvBufUsed);
|
||||
bool error = bytesRead < 1;
|
||||
if (!error)
|
||||
{
|
||||
if (!error) {
|
||||
m_recvBufUsed += bytesRead;
|
||||
|
||||
asn_dec_rval_t retVal;
|
||||
do
|
||||
{
|
||||
do {
|
||||
// Try to decode the packets.
|
||||
InternalChatCleanerPacket recvMsg;
|
||||
retVal = ber_decode(0, &asn_DEF_ChatCleanerMessage, (void **)recvMsg.GetMsgPtr(), m_recvBuf, m_recvBufUsed);
|
||||
if(retVal.code == RC_OK)
|
||||
{
|
||||
if (retVal.consumed < m_recvBufUsed)
|
||||
{
|
||||
if(retVal.code == RC_OK) {
|
||||
if (retVal.consumed < m_recvBufUsed) {
|
||||
m_recvBufUsed -= retVal.consumed;
|
||||
memmove(m_recvBuf, m_recvBuf + retVal.consumed, m_recvBufUsed);
|
||||
}
|
||||
else
|
||||
} else
|
||||
m_recvBufUsed = 0;
|
||||
|
||||
// Handle the packets.
|
||||
@@ -85,8 +80,7 @@ void CleanerServer::onRead()
|
||||
} while (!error && retVal.code == RC_OK);
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error) {
|
||||
qDebug() << "Error handling packets from client.";
|
||||
tcpSocket->close();
|
||||
}
|
||||
@@ -104,16 +98,14 @@ void CleanerServer::onRead()
|
||||
tcpSocket->write(checkMessage.toAscii().data(), checkMessage.length());*/
|
||||
}
|
||||
|
||||
bool CleanerServer::handleMessage(InternalChatCleanerPacket &msg) {
|
||||
bool CleanerServer::handleMessage(InternalChatCleanerPacket &msg)
|
||||
{
|
||||
bool error = true;
|
||||
if (msg.GetMsg()->present == ChatCleanerMessage_PR_cleanerInitMessage)
|
||||
{
|
||||
if (msg.GetMsg()->present == ChatCleanerMessage_PR_cleanerInitMessage) {
|
||||
CleanerInitMessage_t *netInit = &msg.GetMsg()->choice.cleanerInitMessage;
|
||||
if (netInit->requestedVersion == CLEANER_PROTOCOL_VERSION)
|
||||
{
|
||||
if (netInit->requestedVersion == CLEANER_PROTOCOL_VERSION) {
|
||||
string tmpClientSecret((const char *)netInit->clientSecret.buf, netInit->clientSecret.size);
|
||||
if (clientSecret == QString::fromStdString(tmpClientSecret))
|
||||
{
|
||||
if (clientSecret == QString::fromStdString(tmpClientSecret)) {
|
||||
error = false;
|
||||
|
||||
InternalChatCleanerPacket tmpAck;
|
||||
@@ -125,28 +117,23 @@ bool CleanerServer::handleMessage(InternalChatCleanerPacket &msg) {
|
||||
tmpServerSecret.c_str(),
|
||||
tmpServerSecret.length());
|
||||
sendMessageToClient(tmpAck);
|
||||
}
|
||||
else
|
||||
} else
|
||||
qDebug() << "Invalid client secret.";
|
||||
}
|
||||
else
|
||||
} else
|
||||
qDebug() << "Invalid client version: " << netInit->requestedVersion;
|
||||
}
|
||||
else if (msg.GetMsg()->present == ChatCleanerMessage_PR_cleanerChatRequestMessage)
|
||||
{
|
||||
} else if (msg.GetMsg()->present == ChatCleanerMessage_PR_cleanerChatRequestMessage) {
|
||||
error = false;
|
||||
CleanerChatRequestMessage_t *netRequest = &msg.GetMsg()->choice.cleanerChatRequestMessage;
|
||||
unsigned playerId = netRequest->playerId;
|
||||
QString nick(QString::fromUtf8(
|
||||
string((const char *)netRequest->playerName.buf, netRequest->playerName.size).c_str()));
|
||||
string((const char *)netRequest->playerName.buf, netRequest->playerName.size).c_str()));
|
||||
QString message(QString::fromUtf8(
|
||||
string((const char *)netRequest->chatMessage.buf, netRequest->chatMessage.size).c_str()));
|
||||
string((const char *)netRequest->chatMessage.buf, netRequest->chatMessage.size).c_str()));
|
||||
QStringList checkreturn = myMessageFilter->check(playerId, nick, message);
|
||||
QString checkAction = checkreturn.at(0);
|
||||
QString checkMessage = checkreturn.at(1);
|
||||
|
||||
if (!checkAction.isEmpty())
|
||||
{
|
||||
if (!checkAction.isEmpty()) {
|
||||
InternalChatCleanerPacket tmpReply;
|
||||
tmpReply.GetMsg()->present = ChatCleanerMessage_PR_cleanerChatReplyMessage;
|
||||
CleanerChatReplyMessage_t *netReply = &tmpReply.GetMsg()->choice.cleanerChatReplyMessage;
|
||||
@@ -156,33 +143,33 @@ bool CleanerServer::handleMessage(InternalChatCleanerPacket &msg) {
|
||||
|
||||
if(checkAction == "warn") {
|
||||
netReply->cleanerActionType = cleanerActionType_cleanerActionWarning;
|
||||
}
|
||||
else if(checkAction == "kick") {
|
||||
} else if(checkAction == "kick") {
|
||||
netReply->cleanerActionType = cleanerActionType_cleanerActionKick;
|
||||
}
|
||||
else if(checkAction == "kickban") {
|
||||
} else if(checkAction == "kickban") {
|
||||
netReply->cleanerActionType = cleanerActionType_cleanerActionBan;
|
||||
}
|
||||
|
||||
string tmpCheck(checkMessage.toUtf8());
|
||||
netReply->cleanerText =
|
||||
OCTET_STRING_new_fromBuf(
|
||||
&asn_DEF_OCTET_STRING,
|
||||
(const char *)tmpCheck.c_str(),
|
||||
tmpCheck.length());
|
||||
OCTET_STRING_new_fromBuf(
|
||||
&asn_DEF_OCTET_STRING,
|
||||
(const char *)tmpCheck.c_str(),
|
||||
tmpCheck.length());
|
||||
sendMessageToClient(tmpReply);
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
void CleanerServer::socketStateChanged(QAbstractSocket::SocketState state) {
|
||||
void CleanerServer::socketStateChanged(QAbstractSocket::SocketState state)
|
||||
{
|
||||
|
||||
qDebug() << "Socket state changed to: " << QAbstractSocket::UnconnectedState;
|
||||
if(state == QAbstractSocket::UnconnectedState) blockConnection = false;
|
||||
}
|
||||
|
||||
void CleanerServer::refreshConfig() {
|
||||
void CleanerServer::refreshConfig()
|
||||
{
|
||||
|
||||
QFileInfo configFileInfo(QString::fromUtf8(config->getConfigFileName().c_str()));
|
||||
|
||||
|
||||
@@ -8,36 +8,37 @@
|
||||
class MessageFilter;
|
||||
class CleanerConfig;
|
||||
|
||||
class CleanerServer: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
class CleanerServer: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CleanerServer();
|
||||
CleanerServer();
|
||||
~CleanerServer();
|
||||
|
||||
|
||||
private slots:
|
||||
void newCon();
|
||||
void onRead();
|
||||
bool handleMessage(InternalChatCleanerPacket &msg);
|
||||
void socketStateChanged(QAbstractSocket::SocketState);
|
||||
void refreshConfig();
|
||||
void sendMessageToClient(InternalChatCleanerPacket &msg);
|
||||
void newCon();
|
||||
void onRead();
|
||||
bool handleMessage(InternalChatCleanerPacket &msg);
|
||||
void socketStateChanged(QAbstractSocket::SocketState);
|
||||
void refreshConfig();
|
||||
void sendMessageToClient(InternalChatCleanerPacket &msg);
|
||||
|
||||
private:
|
||||
QTcpServer *tcpServer;
|
||||
QTcpSocket *tcpSocket;
|
||||
QTimer *configRefreshTimer;
|
||||
MessageFilter *myMessageFilter;
|
||||
|
||||
CleanerConfig *config;
|
||||
bool blockConnection;
|
||||
QString clientSecret;
|
||||
QString serverSecret;
|
||||
|
||||
unsigned char m_recvBuf[2*MAX_CLEANER_PACKET_SIZE];
|
||||
unsigned m_recvBufUsed;
|
||||
|
||||
int secondsSinceLastConfigChange;
|
||||
QTcpServer *tcpServer;
|
||||
QTcpSocket *tcpSocket;
|
||||
QTimer *configRefreshTimer;
|
||||
MessageFilter *myMessageFilter;
|
||||
|
||||
CleanerConfig *config;
|
||||
bool blockConnection;
|
||||
QString clientSecret;
|
||||
QString serverSecret;
|
||||
|
||||
unsigned char m_recvBuf[2*MAX_CLEANER_PACKET_SIZE];
|
||||
unsigned m_recvBufUsed;
|
||||
|
||||
int secondsSinceLastConfigChange;
|
||||
};
|
||||
|
||||
#endif // CLEANERSERVER_H
|
||||
|
||||
@@ -3,23 +3,21 @@
|
||||
#include <QtCore>
|
||||
|
||||
LetterRepeatingCheck::LetterRepeatingCheck()
|
||||
: letterNumberToTrigger(0)
|
||||
: letterNumberToTrigger(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool LetterRepeatingCheck::run(QString msg)
|
||||
bool LetterRepeatingCheck::run(QString msg)
|
||||
{
|
||||
msg = msg.simplified().remove(" ");
|
||||
QRegExp e(QString(".*(.)\\1{%1,}.*").arg(letterNumberToTrigger-1));
|
||||
if(e.isValid()) {
|
||||
if(e.exactMatch(msg)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if(e.exactMatch(msg)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// qDebug() << "The current Letter Repeating RegExp is invalid" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class LetterRepeatingCheck: public QObject {
|
||||
Q_OBJECT
|
||||
class LetterRepeatingCheck: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LetterRepeatingCheck();
|
||||
|
||||
void setLetterNumberToTrigger(int n) { letterNumberToTrigger = n; }
|
||||
LetterRepeatingCheck();
|
||||
|
||||
void setLetterNumberToTrigger(int n) {
|
||||
letterNumberToTrigger = n;
|
||||
}
|
||||
bool run(QString);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int letterNumberToTrigger;
|
||||
|
||||
+155
-159
@@ -10,203 +10,199 @@
|
||||
#include "urlcheck.h"
|
||||
|
||||
enum ActionType {
|
||||
NOTHING,
|
||||
WARN,
|
||||
KICK,
|
||||
KICKBAN
|
||||
NOTHING,
|
||||
WARN,
|
||||
KICK,
|
||||
KICKBAN
|
||||
};
|
||||
|
||||
enum OffenceType {
|
||||
NONE,
|
||||
BAD_WORD,
|
||||
TEXT_FLOOD_LINES,
|
||||
CAPS_FLOOD,
|
||||
LETTER_REPEATING,
|
||||
URL
|
||||
NONE,
|
||||
BAD_WORD,
|
||||
TEXT_FLOOD_LINES,
|
||||
CAPS_FLOOD,
|
||||
LETTER_REPEATING,
|
||||
URL
|
||||
};
|
||||
|
||||
MessageFilter::MessageFilter(CleanerConfig *c): config(c)
|
||||
{
|
||||
myBadWordCheck = new BadWordCheck;
|
||||
myTextFloodCheck = new TextFloodCheck;
|
||||
myCapsFloodCheck = new CapsFloodCheck;
|
||||
myLetterRepeatingCheck = new LetterRepeatingCheck;
|
||||
myUrlCheck = new UrlCheck;
|
||||
myBadWordCheck = new BadWordCheck;
|
||||
myTextFloodCheck = new TextFloodCheck;
|
||||
myCapsFloodCheck = new CapsFloodCheck;
|
||||
myLetterRepeatingCheck = new LetterRepeatingCheck;
|
||||
myUrlCheck = new UrlCheck;
|
||||
|
||||
cleanTimer = new QTimer();
|
||||
connect(cleanTimer, SIGNAL(timeout()), this, SLOT(cleanKickCounterList()));
|
||||
cleanTimer->start(30000);
|
||||
cleanTimer = new QTimer();
|
||||
connect(cleanTimer, SIGNAL(timeout()), this, SLOT(cleanKickCounterList()));
|
||||
cleanTimer->start(30000);
|
||||
}
|
||||
|
||||
MessageFilter::~MessageFilter() {
|
||||
MessageFilter::~MessageFilter()
|
||||
{
|
||||
|
||||
delete myBadWordCheck;
|
||||
delete myTextFloodCheck;
|
||||
delete myCapsFloodCheck;
|
||||
delete myLetterRepeatingCheck;
|
||||
delete myUrlCheck;
|
||||
delete cleanTimer;
|
||||
delete myBadWordCheck;
|
||||
delete myTextFloodCheck;
|
||||
delete myCapsFloodCheck;
|
||||
delete myLetterRepeatingCheck;
|
||||
delete myUrlCheck;
|
||||
delete cleanTimer;
|
||||
}
|
||||
|
||||
QStringList MessageFilter::check(unsigned playerId, QString nick, QString msg)
|
||||
{
|
||||
QStringList returnList;
|
||||
QString returnMessage;
|
||||
QString returnAction;
|
||||
QStringList returnList;
|
||||
QString returnMessage;
|
||||
QString returnAction;
|
||||
|
||||
OffenceType offence = NONE;
|
||||
OffenceType offence = NONE;
|
||||
|
||||
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(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) {
|
||||
|
||||
if(offence){
|
||||
|
||||
ActionType action = NOTHING;
|
||||
QMap<unsigned, ClientWarnInfos>::const_iterator i = myClientWarnLevelList.find(playerId);
|
||||
|
||||
if(i == myClientWarnLevelList.end()) {
|
||||
ClientWarnInfos tmpInfos;
|
||||
tmpInfos.warnLevel = 1;
|
||||
tmpInfos.lastWarnType = offence;
|
||||
tmpInfos.nick = nick;
|
||||
myClientWarnLevelList.insert(playerId, tmpInfos);
|
||||
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());
|
||||
//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 {
|
||||
//pleayer is already on the list: either raise kickNumber or kickban when kickNumerToBan is reached
|
||||
if(j.value().kickNumber == kickNumberToBan) {
|
||||
action = KICKBAN;
|
||||
//remove player from kickCounterList
|
||||
myClientKickCounterList.remove(j.key());
|
||||
}
|
||||
else {
|
||||
ClientKickInfos tmpInfos;
|
||||
tmpInfos.kickNumber = j.value().kickNumber+1;
|
||||
tmpInfos.lastKickTimestamp = timer.elapsed().total_seconds();
|
||||
myClientKickCounterList.insert(nick, tmpInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ClientWarnInfos tmpInfos;
|
||||
tmpInfos.warnLevel = i.value().warnLevel+1;
|
||||
tmpInfos.lastWarnType = offence;
|
||||
tmpInfos.nick = nick;
|
||||
myClientWarnLevelList.insert(playerId, tmpInfos);
|
||||
action = WARN;
|
||||
}
|
||||
}
|
||||
if(i == myClientWarnLevelList.end()) {
|
||||
ClientWarnInfos tmpInfos;
|
||||
tmpInfos.warnLevel = 1;
|
||||
tmpInfos.lastWarnType = offence;
|
||||
tmpInfos.nick = nick;
|
||||
myClientWarnLevelList.insert(playerId, tmpInfos);
|
||||
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());
|
||||
//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 {
|
||||
//pleayer is already on the list: either raise kickNumber or kickban when kickNumerToBan is reached
|
||||
if(j.value().kickNumber == kickNumberToBan) {
|
||||
action = KICKBAN;
|
||||
//remove player from kickCounterList
|
||||
myClientKickCounterList.remove(j.key());
|
||||
} else {
|
||||
ClientKickInfos tmpInfos;
|
||||
tmpInfos.kickNumber = j.value().kickNumber+1;
|
||||
tmpInfos.lastKickTimestamp = timer.elapsed().total_seconds();
|
||||
myClientKickCounterList.insert(nick, tmpInfos);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ClientWarnInfos tmpInfos;
|
||||
tmpInfos.warnLevel = i.value().warnLevel+1;
|
||||
tmpInfos.lastWarnType = offence;
|
||||
tmpInfos.nick = nick;
|
||||
myClientWarnLevelList.insert(playerId, tmpInfos);
|
||||
action = WARN;
|
||||
}
|
||||
}
|
||||
|
||||
if(action == WARN) {
|
||||
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;
|
||||
case LETTER_REPEATING: {
|
||||
returnMessage = QString ("%1: Warning: You've triggered letter repeating protection, stop repeating!\n").arg(nick);
|
||||
}
|
||||
break;
|
||||
case URL: {
|
||||
returnMessage = QString ("%1: Warning: You've triggered url spam protection, stop posting urls!\n").arg(nick);
|
||||
}
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
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("");
|
||||
returnMessage = QString("");
|
||||
}
|
||||
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;
|
||||
case LETTER_REPEATING: {
|
||||
returnMessage = QString ("%1: Warning: You've triggered letter repeating protection, stop repeating!\n").arg(nick);
|
||||
}
|
||||
break;
|
||||
case URL: {
|
||||
returnMessage = QString ("%1: Warning: You've triggered url spam protection, stop posting urls!\n").arg(nick);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
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("");
|
||||
returnMessage = QString("");
|
||||
}
|
||||
|
||||
returnList << returnAction << returnMessage;
|
||||
return returnList;
|
||||
returnList << returnAction << returnMessage;
|
||||
return returnList;
|
||||
}
|
||||
|
||||
void MessageFilter::refreshConfig() {
|
||||
void MessageFilter::refreshConfig()
|
||||
{
|
||||
|
||||
// global settings
|
||||
warnLevelToKick = config->readConfigInt("WarnLevelToKick");
|
||||
kickNumberToBan = config->readConfigInt("KickNumberToBan");
|
||||
// global settings
|
||||
warnLevelToKick = config->readConfigInt("WarnLevelToKick");
|
||||
kickNumberToBan = config->readConfigInt("KickNumberToBan");
|
||||
|
||||
// special check settings
|
||||
//Bad Words
|
||||
std::list<std::string> badWordsList = config->readConfigStringList("BadWordsList");
|
||||
std::list<std::string>::iterator it1;
|
||||
QStringList bwList;
|
||||
// special check settings
|
||||
//Bad Words
|
||||
std::list<std::string> badWordsList = config->readConfigStringList("BadWordsList");
|
||||
std::list<std::string>::iterator it1;
|
||||
QStringList bwList;
|
||||
for(it1= badWordsList.begin(); it1 != badWordsList.end(); ++it1) {
|
||||
bwList << QString::fromUtf8(it1->c_str());
|
||||
}
|
||||
myBadWordCheck->setBadWords(bwList);
|
||||
bwList << QString::fromUtf8(it1->c_str());
|
||||
}
|
||||
myBadWordCheck->setBadWords(bwList);
|
||||
|
||||
std::list<std::string> urlStringsList = config->readConfigStringList("UrlStringsList");
|
||||
std::list<std::string>::iterator it2;
|
||||
QStringList urlList;
|
||||
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);
|
||||
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;
|
||||
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);
|
||||
urlExceptionList << QString::fromUtf8(it3->c_str());
|
||||
}
|
||||
myUrlCheck->setUrlExceptionStrings(urlExceptionList);
|
||||
|
||||
myTextFloodCheck->setTextFloodLevelToTrigger(config->readConfigInt("TextFloodLevelToTrigger"));
|
||||
myCapsFloodCheck->setCapsNumberToTrigger(config->readConfigInt("CapsFloodCapsNumberToTrigger"));
|
||||
myLetterRepeatingCheck->setLetterNumberToTrigger(config->readConfigInt("LetterRepeatingNumberToTrigger"));
|
||||
myTextFloodCheck->setTextFloodLevelToTrigger(config->readConfigInt("TextFloodLevelToTrigger"));
|
||||
myCapsFloodCheck->setCapsNumberToTrigger(config->readConfigInt("CapsFloodCapsNumberToTrigger"));
|
||||
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 > static_cast<unsigned>(config->readConfigInt("SecondsToForgetAboutKick"))) {
|
||||
QMapIterator<QString, ClientKickInfos> it(myClientKickCounterList);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if(timer.elapsed().total_seconds()-it.value().lastKickTimestamp > static_cast<unsigned>(config->readConfigInt("SecondsToForgetAboutKick"))) {
|
||||
// qDebug() << it.key() << "removed from kick counter list" << endl;
|
||||
myClientKickCounterList.remove(it.key());
|
||||
}
|
||||
}
|
||||
myClientKickCounterList.remove(it.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,46 +12,47 @@ class CapsFloodCheck;
|
||||
class LetterRepeatingCheck;
|
||||
class UrlCheck;
|
||||
|
||||
class MessageFilter: public QObject {
|
||||
Q_OBJECT
|
||||
class MessageFilter: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MessageFilter(CleanerConfig*);
|
||||
~MessageFilter();
|
||||
MessageFilter(CleanerConfig*);
|
||||
~MessageFilter();
|
||||
|
||||
QStringList check(unsigned, QString, QString);
|
||||
void refreshConfig();
|
||||
QStringList check(unsigned, QString, QString);
|
||||
void refreshConfig();
|
||||
|
||||
public slots:
|
||||
void cleanKickCounterList();
|
||||
void cleanKickCounterList();
|
||||
|
||||
private:
|
||||
BadWordCheck *myBadWordCheck;
|
||||
TextFloodCheck *myTextFloodCheck;
|
||||
CapsFloodCheck *myCapsFloodCheck;
|
||||
LetterRepeatingCheck *myLetterRepeatingCheck;
|
||||
UrlCheck *myUrlCheck;
|
||||
private:
|
||||
BadWordCheck *myBadWordCheck;
|
||||
TextFloodCheck *myTextFloodCheck;
|
||||
CapsFloodCheck *myCapsFloodCheck;
|
||||
LetterRepeatingCheck *myLetterRepeatingCheck;
|
||||
UrlCheck *myUrlCheck;
|
||||
|
||||
struct ClientWarnInfos {
|
||||
QString nick;
|
||||
int lastWarnType;
|
||||
int warnLevel;
|
||||
};
|
||||
struct ClientWarnInfos {
|
||||
QString nick;
|
||||
int lastWarnType;
|
||||
int warnLevel;
|
||||
};
|
||||
|
||||
struct ClientKickInfos {
|
||||
size_t lastKickTimestamp;
|
||||
int kickNumber;
|
||||
};
|
||||
struct ClientKickInfos {
|
||||
size_t lastKickTimestamp;
|
||||
int kickNumber;
|
||||
};
|
||||
|
||||
QMap<unsigned, ClientWarnInfos> myClientWarnLevelList;
|
||||
QMap<QString, ClientKickInfos> myClientKickCounterList;
|
||||
QMap<unsigned, ClientWarnInfos> myClientWarnLevelList;
|
||||
QMap<QString, ClientKickInfos> myClientKickCounterList;
|
||||
|
||||
int warnLevelToKick;
|
||||
int kickNumberToBan;
|
||||
int warnLevelToKick;
|
||||
int kickNumberToBan;
|
||||
|
||||
CleanerConfig *config;
|
||||
CleanerConfig *config;
|
||||
|
||||
boost::timers::portable::second_timer timer;
|
||||
QTimer *cleanTimer;
|
||||
boost::timers::portable::second_timer timer;
|
||||
QTimer *cleanTimer;
|
||||
};
|
||||
|
||||
#endif // MESSAGEFILTER_H
|
||||
|
||||
@@ -5,13 +5,13 @@ TextFloodCheck::TextFloodCheck()
|
||||
{
|
||||
timer.reset();
|
||||
timer.start();
|
||||
|
||||
|
||||
cleanTimer = new QTimer();
|
||||
|
||||
|
||||
connect(cleanTimer, SIGNAL(timeout()), this, SLOT(cleanMsgTimesList()));
|
||||
|
||||
cleanTimer->start(4000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TextFloodCheck::~TextFloodCheck()
|
||||
@@ -19,24 +19,24 @@ TextFloodCheck::~TextFloodCheck()
|
||||
delete cleanTimer;
|
||||
}
|
||||
|
||||
bool TextFloodCheck::run(unsigned playerId) {
|
||||
|
||||
bool TextFloodCheck::run(unsigned playerId)
|
||||
{
|
||||
|
||||
QMapIterator<unsigned, TextFloodInfos> it(msgTimesList);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
it.next();
|
||||
// qDebug() << "counter: " << msgTimesList.count() << " playerid: " << it.key() << " floodlevel: " << it.value().floodLevel << " timestamp: " << it.value().timeStamp;
|
||||
}
|
||||
|
||||
|
||||
QMap<unsigned, TextFloodInfos>::const_iterator i = msgTimesList.find(playerId);
|
||||
|
||||
|
||||
if(i == msgTimesList.end()) {
|
||||
TextFloodInfos tmpInfos1;
|
||||
tmpInfos1.floodLevel = 0;
|
||||
tmpInfos1.timeStamp = timer.elapsed().total_seconds();
|
||||
msgTimesList.insert(playerId, tmpInfos1);
|
||||
qDebug () << "Add Player: set player floodlevel to " << tmpInfos1.floodLevel;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
TextFloodInfos tmpInfos2;
|
||||
if(timer.elapsed().total_seconds()-i.value().timeStamp <= 1) {
|
||||
if(i.value().floodLevel == textFloodLevelToTrigger) {
|
||||
@@ -46,35 +46,33 @@ bool TextFloodCheck::run(unsigned playerId) {
|
||||
qDebug () << "Trigger: set player floodlevel to " << tmpInfos3.floodLevel;
|
||||
msgTimesList.insert(playerId, tmpInfos3);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tmpInfos2.floodLevel = i.value().floodLevel+1;
|
||||
qDebug () << "Raise: set player floodlevel to " << tmpInfos2.floodLevel << " from " << i.value().floodLevel;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tmpInfos2.floodLevel = i.value().floodLevel;
|
||||
}
|
||||
} else {
|
||||
tmpInfos2.floodLevel = i.value().floodLevel;
|
||||
qDebug () << "Keep: player floodlevel is " << tmpInfos2.floodLevel << " from " << i.value().floodLevel;
|
||||
}
|
||||
|
||||
|
||||
tmpInfos2.timeStamp = timer.elapsed().total_seconds();
|
||||
msgTimesList.insert(playerId, tmpInfos2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextFloodCheck::cleanMsgTimesList() {
|
||||
void TextFloodCheck::cleanMsgTimesList()
|
||||
{
|
||||
|
||||
QMapIterator<unsigned, TextFloodInfos> it(msgTimesList);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if(timer.elapsed().total_seconds()-it.value().timeStamp > 3) {
|
||||
|
||||
it.next();
|
||||
if(timer.elapsed().total_seconds()-it.value().timeStamp > 3) {
|
||||
|
||||
if(it.value().floodLevel == 0) {
|
||||
msgTimesList.remove(it.key());
|
||||
qDebug () << "Refresh: player removed from List";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
TextFloodInfos tmpInfos;
|
||||
tmpInfos.floodLevel = it.value().floodLevel-1;
|
||||
tmpInfos.timeStamp = it.value().timeStamp;
|
||||
@@ -86,8 +84,9 @@ void TextFloodCheck::cleanMsgTimesList() {
|
||||
}
|
||||
}
|
||||
|
||||
void TextFloodCheck::removeNickFromList(unsigned playerId) {
|
||||
|
||||
void TextFloodCheck::removeNickFromList(unsigned playerId)
|
||||
{
|
||||
|
||||
// qDebug() << "id " << playerId << "removed from textfloodcheck list" << endl;
|
||||
msgTimesList.remove(playerId);
|
||||
}
|
||||
|
||||
@@ -10,18 +10,20 @@ class TextFloodCheck: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextFloodCheck();
|
||||
TextFloodCheck();
|
||||
~TextFloodCheck();
|
||||
|
||||
void setTextFloodLevelToTrigger(int level) { textFloodLevelToTrigger = level; }
|
||||
|
||||
|
||||
void setTextFloodLevelToTrigger(int level) {
|
||||
textFloodLevelToTrigger = level;
|
||||
}
|
||||
|
||||
bool run(unsigned);
|
||||
|
||||
|
||||
public slots:
|
||||
void cleanMsgTimesList();
|
||||
void removeNickFromList(unsigned);
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
QTimer *cleanTimer;
|
||||
boost::timers::portable::second_timer timer;
|
||||
struct TextFloodInfos {
|
||||
@@ -29,7 +31,7 @@ private:
|
||||
size_t timeStamp;
|
||||
};
|
||||
QMap<unsigned, TextFloodInfos> msgTimesList;
|
||||
|
||||
|
||||
int textFloodLevelToTrigger;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,23 +6,25 @@ UrlCheck::UrlCheck()
|
||||
{
|
||||
}
|
||||
|
||||
bool UrlCheck::run(QString msg)
|
||||
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;
|
||||
if(msg.contains(it2.next())) {
|
||||
exception = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!exception) { return true; }
|
||||
if(!exception) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -3,15 +3,20 @@
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class UrlCheck: public QObject {
|
||||
Q_OBJECT
|
||||
class UrlCheck: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UrlCheck();
|
||||
|
||||
void setUrlStrings(QStringList us) { urlStrings = us; }
|
||||
void setUrlExceptionStrings(QStringList ues) { urlExceptionStrings = ues; }
|
||||
UrlCheck();
|
||||
|
||||
void setUrlStrings(QStringList us) {
|
||||
urlStrings = us;
|
||||
}
|
||||
void setUrlExceptionStrings(QStringList ues) {
|
||||
urlExceptionStrings = ues;
|
||||
}
|
||||
bool run(QString);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
QStringList urlStrings;
|
||||
|
||||
Reference in New Issue
Block a user