فهرست منبع

Floodprot code rewritten, now its simpler. Changed broadcast count reply
message, BC_RE regex fixed to match new playercount parameter.

Mihawk 12 سال پیش
والد
کامیت
91bc38c5b5
4فایلهای تغییر یافته به همراه56 افزوده شده و 40 حذف شده
  1. 3 1
      ActiveClient.cpp
  2. 26 30
      Client.cpp
  3. 23 8
      Client.h
  4. 4 1
      SshClient.cpp

+ 3 - 1
ActiveClient.cpp

@@ -112,7 +112,7 @@ void ActiveClient::run()
   if(!myBroadcastReplyTimer->isActive() && myReplyTimerWasActive)
   {
     myApp->activeClientsReplyCounters(&myUniqueServerCount, &myUniquePlayerCount, this); //add our servers to the list
-    myClient->say("Sent to " + QString::number(myUniqueChannelCount) + " channels " + QString::number(myUniqueUserCount) + " unique users and to " + QString::number(myUniqueServerCount) + " servers " + QString::number(myUniquePlayerCount) + " unique players.");
+    myClient->say("Sent to " + QString::number(myUniqueChannelCount) + " channels " + QString::number(myUniqueUserCount) + " users and to " + QString::number(myUniqueServerCount) + " servers " + QString::number(myUniquePlayerCount) + " players.");
     myUniqueServerCount = myUniquePlayerCount = myUniqueChannelCount = myUniqueUserCount = 0;
   }
   myReplyTimerWasActive = myBroadcastReplyTimer->isActive();
@@ -140,6 +140,8 @@ void ActiveClient::setReplyHash(const QString &hash)
   /* Wait for reply */
   myBroadcastReplyTimer->setSingleShot(true);
   myBroadcastReplyTimer->start(Settings::globalInstance()->timeToWaitForCountReply()*1000);
+
+  qDebug() << "reply hash set" << hash;
 }
 
 const QString& ActiveClient::replyHash() const

+ 26 - 30
Client.cpp

@@ -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();
 }
 

+ 23 - 8
Client.h

@@ -49,21 +49,36 @@ protected:
 private:
   ActiveClient*     myActiveClient;
 	App*							myApp;
-  QTime             myEndFloodTime;
-	bool							myFloodMsgPrinted;
+
 	int								myConnectionRetries;
 	static const int	ConnectionRetries = 10;
-	QString						myPrintLine;
-	bool							myDownloadProgressPrintedFlag;
+
+  QString						myPrintLine;
+
+  bool							myDownloadProgressPrintedFlag;
+
   bool              myOnServerFlag;
+
   bool              mySpamMutedFlag;
   bool              myQWMutedFlag;
-  QTimer*           myJoinMessageTimer;
-  QTimer*           myKeepNickTimer;
-  QTime             myQWBroadcastFloodTime;
-  QTime             mySpamBroadcastFloodTime;
+
+  QTimer*           myJoinMessageTimer;             //after that time the bot will say hi.
+  QTimer*           myKeepNickTimer;                //interval in which the bot tries to retake his nickname
+
+  /* flood timers */
+  QTimer*           myFloodTimer;                   //floodtimer for all commands
+  QTimer*           myQWBroadcastFloodTimer;        //floodtimer for .qw broadcasts
+  QTimer*           mySpamBroadcastFloodTimer;      //floodtimer for .spam broadcasts
+
+  /* time when floodtimer was started for calc time left */
+  QTime             myFloodTimerStart;
+  QTime             myQWBroadcastFloodTimerStart;
+  QTime             mySpamBroadcastFloodTimerStart;
+
   bool              myJoinMessagePrinted;
+  bool							myFloodMsgPrinted;
   bool              myJoinMessageScheduled;
+
   PlayerList        myPlayerList;
   int               myMaxClients;
 

+ 4 - 1
SshClient.cpp

@@ -170,7 +170,8 @@ void SshClient::parse(const QDateTime &time, const QString &command, const QStri
   if(command == "BC_ID")
   {
     //BC_ID 4e5fca581569e168c7a86a0a9a91949f for: QDEV,-dev-,qw://123.123
-    QRegExp a("^([A-Za-z0-9]+) for: .+,-(.+)-,qw://(.+)$");
+    qDebug() << commandData;
+    QRegExp a("^([A-Za-z0-9]+) for: .+,-(.+)-,qw://(.+) [0-9]+/[0-9]+$");
     if(a.indexIn(commandData) == -1)
       return;
 
@@ -220,6 +221,8 @@ void SshClient::parse(const QDateTime &time, const QString &command, const QStri
       channelCount = 0;
     }
 
+    qDebug() << commandData;
+
     myApp->incrementReplyCounters(hash, userCount, channelCount, playerCount, serverCount);
 
     return;