|
@@ -18,27 +18,33 @@ Client::Client(App *app, ActiveClient* ac):
|
|
|
myQWMutedFlag(false),
|
|
|
myJoinMessageTimer(new QTimer()),
|
|
|
myKeepNickTimer(new QTimer()),
|
|
|
+ myFloodTimer(new QTimer()),
|
|
|
+ myQWBroadcastFloodTimer(new QTimer()),
|
|
|
+ mySpamBroadcastFloodTimer(new QTimer()),
|
|
|
myJoinMessagePrinted(false),
|
|
|
myJoinMessageScheduled(false),
|
|
|
myMaxClients(0)
|
|
|
{
|
|
|
myJoinMessageTimer->setSingleShot(true);
|
|
|
myKeepNickTimer->setSingleShot(true);
|
|
|
+ myFloodTimer->setSingleShot(true);
|
|
|
+ myQWBroadcastFloodTimer->setSingleShot(true);
|
|
|
+ mySpamBroadcastFloodTimer->setSingleShot(true);
|
|
|
}
|
|
|
|
|
|
Client::~Client()
|
|
|
{
|
|
|
delete myJoinMessageTimer;
|
|
|
+ delete myKeepNickTimer;
|
|
|
+ delete myFloodTimer;
|
|
|
+ delete myQWBroadcastFloodTimer;
|
|
|
+ delete mySpamBroadcastFloodTimer;
|
|
|
}
|
|
|
|
|
|
void Client::connect(const char *host, quint16 port)
|
|
|
{
|
|
|
myJoinMessageScheduled = true; //Hi message only scheduled at bot connection
|
|
|
|
|
|
- myEndFloodTime = QTime::currentTime();
|
|
|
- myQWBroadcastFloodTime = myEndFloodTime;
|
|
|
- mySpamBroadcastFloodTime = myEndFloodTime;
|
|
|
-
|
|
|
QWClient::connect(host, port);
|
|
|
}
|
|
|
|
|
@@ -154,18 +160,18 @@ void Client::parsePrintedLine()
|
|
|
|
|
|
/* Flood prot */
|
|
|
QTime currentTime = QTime::currentTime();
|
|
|
-
|
|
|
- int timeLeft = currentTime.secsTo(myEndFloodTime);
|
|
|
- if(timeLeft > 0)
|
|
|
+ int floodProtTime = Settings::globalInstance()->floodProtTime();
|
|
|
+ if(myFloodTimer->isActive())
|
|
|
{
|
|
|
if(!myFloodMsgPrinted)
|
|
|
{
|
|
|
- say("> FloodProt: Not so fast, wait " + QString::number(timeLeft) + " sec(s).");
|
|
|
+ say("> FloodProt: Not so fast, wait " + QString::number(floodProtTime + currentTime.secsTo(myFloodTimerStart)) + " sec(s).");
|
|
|
myFloodMsgPrinted = true;
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
- myEndFloodTime = currentTime.addSecs(Settings::globalInstance()->floodProtTime());
|
|
|
+ myFloodTimerStart = currentTime;
|
|
|
+ myFloodTimer->start(floodProtTime*1000);
|
|
|
myFloodMsgPrinted = false;
|
|
|
|
|
|
QString command = regex.capturedTexts().at(1);
|
|
@@ -190,25 +196,28 @@ void Client::parsePrintedLine()
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ /* Floodprot for broadcasting commands */
|
|
|
if(command == "qw")
|
|
|
{
|
|
|
- timeLeft = currentTime.secsTo(myQWBroadcastFloodTime);
|
|
|
- if(timeLeft > 0)
|
|
|
+ int qwFloodProtTime = Settings::globalInstance()->qwFloodProtTime();
|
|
|
+ if(myQWBroadcastFloodTimer->isActive())
|
|
|
{
|
|
|
- say("> FloodProt: Wait " + QString::number(timeLeft) + " secs before new .qw");
|
|
|
+ say("> FloodProt: Wait " + QString::number(qwFloodProtTime + currentTime.secsTo(myQWBroadcastFloodTimerStart)) + " secs before new .qw");
|
|
|
return;
|
|
|
}
|
|
|
- myQWBroadcastFloodTime = currentTime.addSecs(Settings::globalInstance()->qwFloodProtTime());
|
|
|
+ myQWBroadcastFloodTimerStart = currentTime;
|
|
|
+ myQWBroadcastFloodTimer->start(qwFloodProtTime*1000);
|
|
|
}
|
|
|
else if(command == "spam")
|
|
|
{
|
|
|
- timeLeft = currentTime.secsTo(mySpamBroadcastFloodTime);
|
|
|
- if(timeLeft > 0)
|
|
|
+ int spamFloodProtTime = Settings::globalInstance()->spamFloodProtTime();
|
|
|
+ if(mySpamBroadcastFloodTimer->isActive())
|
|
|
{
|
|
|
- say("> FloodProt: Wait " + QString::number(timeLeft) + " secs before new .spam");
|
|
|
+ say("> FloodProt: Wait " + QString::number(spamFloodProtTime + currentTime.secsTo(mySpamBroadcastFloodTimerStart)) + " secs before new .spam");
|
|
|
return;
|
|
|
}
|
|
|
- mySpamBroadcastFloodTime = currentTime.addSecs(Settings::globalInstance()->spamFloodProtTime());
|
|
|
+ mySpamBroadcastFloodTimerStart = currentTime;
|
|
|
+ mySpamBroadcastFloodTimer->start(spamFloodProtTime*1000);
|
|
|
}
|
|
|
|
|
|
QString server(QString(host()) + ":" + QString::number(port()) + " " + QString::number(playerCount()) + "/" + QString::number(myMaxClients));
|
|
@@ -383,19 +392,6 @@ void Client::run()
|
|
|
myKeepNickTimer->start(30000);
|
|
|
}
|
|
|
|
|
|
- /* Avoid wrap around of flood timers */
|
|
|
- QTime currentTime = QTime::currentTime();
|
|
|
- // qDebug() << currentTime.secsTo(myEndFloodTime);
|
|
|
-
|
|
|
- if(currentTime.secsTo(myEndFloodTime) < -16000)
|
|
|
- myEndFloodTime = currentTime;
|
|
|
-
|
|
|
- if(currentTime.secsTo(myQWBroadcastFloodTime) < -16000)
|
|
|
- myQWBroadcastFloodTime = currentTime;
|
|
|
-
|
|
|
- if(currentTime.secsTo(mySpamBroadcastFloodTime) < -16000)
|
|
|
- mySpamBroadcastFloodTime = currentTime;
|
|
|
-
|
|
|
QWClient::run();
|
|
|
}
|
|
|
|