Browse Source

New .spam and .qw timing proposal, anti-flooding.

Mihawk 10 years ago
parent
commit
8253cb3b41
2 changed files with 23 additions and 39 deletions
  1. 20 34
      Client.cpp
  2. 3 5
      Client.h

+ 20 - 34
Client.cpp

@@ -41,8 +41,7 @@ Client::Client(App *app, ActiveClient* ac):
   myQWMutedFlag(false),
   myKeepNickTimer(new QTimer()),
   myFloodTimer(new QTimer()),
-  myQWBroadcastFloodTimer(new QTimer()),
-  mySpamBroadcastFloodTimer(new QTimer()),
+  myBroadcastFloodTimer(new QTimer()),
   mySPDetectionTimer(new QTimer()),
   mySPSupport(false),
   mySPAutoDetect(true),
@@ -52,8 +51,7 @@ Client::Client(App *app, ActiveClient* ac):
   rxBrackets.setMinimal(true);
   myKeepNickTimer->setSingleShot(true);
   myFloodTimer->setSingleShot(true);
-  myQWBroadcastFloodTimer->setSingleShot(true);
-  mySpamBroadcastFloodTimer->setSingleShot(true);
+  myBroadcastFloodTimer->setSingleShot(true);
   mySPDetectionTimer->setSingleShot(true);
   myCmdScheduledTimer->setSingleShot(true);
 }
@@ -63,8 +61,7 @@ Client::~Client()
 {
   delete myKeepNickTimer;
   delete myFloodTimer;
-  delete myQWBroadcastFloodTimer;
-  delete mySpamBroadcastFloodTimer;
+  delete myBroadcastFloodTimer;
   delete mySPDetectionTimer;
   delete myCmdScheduledTimer;
 }
@@ -208,7 +205,7 @@ void Client::parsePrintedLine()
   QString message(myPrintLine.right(myPrintLine.size() - lastMatchSize));
 
 
-  QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute|lm)\\s*(.+)$");
+  QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute|lm|about)\\s*(.+)$");
   if(regex.indexIn(message) == -1)
     return;
 
@@ -236,7 +233,13 @@ void Client::parsePrintedLine()
     say("Broadcast a message: .qw <message> and .spam <message>", bestPlayer.name);
     say("(Un)Mute: .qw_mute .qw_unmute or .spam_mute .spam_unmute", bestPlayer.name);
     say("Last 5 messages: .lm", bestPlayer.name);
+    say("About this bot: .about", bestPlayer.name);
+    return;
+  }
 
+  if(command == "about")
+  {
+    say("ServeMe specbots by mihawk & Haudraufwienix, find us on #qwnet @ irc.quakenet.org", bestPlayer.name);
     return;
   }
 
@@ -249,30 +252,21 @@ void Client::parsePrintedLine()
     }
 
     /* Floodprot for broadcasting commands */
-    if(command == "qw")
+    if(command == "qw" || command == "spam")
     {
-      int qwFloodProtTime = Settings::globalInstance()->qwFloodProtTime();
-      if(myQWBroadcastFloodTimer->isActive())
+      if(myBroadcastFloodTimer->isActive())
       {
-        say("FloodProt: Wait " + QString::number(qwFloodProtTime + currentTime.secsTo(myQWBroadcastFloodTimerStart)) + " secs before new .qw", bestPlayer.name);
+        say("FloodProt: Wait " + QString::number(myBroadcastFloodTimer->interval()/1000 + currentTime.secsTo(myBroadcastFloodTimerStart)) + " sec(s) before issuing a new " + command, bestPlayer.name);
         return;
       }
-      myQWBroadcastFloodTimerStart = currentTime;
-      myQWBroadcastFloodTimer->start(qwFloodProtTime*1000);
-    }
-    else if(command == "spam")
-    {
-      say("Only .qw is allowed within QW servers. Please use .qw to broadcast your message.");
-      return;
 
-//      int spamFloodProtTime = Settings::globalInstance()->spamFloodProtTime();
-//      if(mySpamBroadcastFloodTimer->isActive())
-//      {
-//        say("FloodProt: Wait " + QString::number(spamFloodProtTime + currentTime.secsTo(mySpamBroadcastFloodTimerStart)) + " secs before new .spam", bestPlayer.name);
-//        return;
-//      }
-//      mySpamBroadcastFloodTimerStart = currentTime;
-//      mySpamBroadcastFloodTimer->start(spamFloodProtTime*1000);
+      int time;
+      if(command == "qw")
+        time = Settings::globalInstance()->qwFloodProtTime();
+      else
+        time = Settings::globalInstance()->spamFloodProtTime();
+      myBroadcastFloodTimerStart = currentTime;
+      myBroadcastFloodTimer->start(time*1000);
     }
 
     // Prepare all strings to be broadcasted
@@ -463,12 +457,6 @@ void Client::onDownloadStarted(const char *fileName)
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void Client::run()
 {
-  //  if(!myJoinMessageTimer->isActive() && !myJoinMessagePrinted)
-  //  {
-  //    say("Hi, I am QWNET's bot, type .help to see my commands.");
-  //    myJoinMessagePrinted = true;
-  //  }
-
   // Keep nick... Simply set name again after 30 secs
   if(!myKeepNickTimer->isActive())
   {
@@ -538,13 +526,11 @@ void Client::setAutoDetectSP(bool autoDetect)
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void Client::spDetection()
 {
-//  scheduleCmd("say s-p", 2000);
   say("s-p");
   mySPDetectionTimer->start(2000);
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-static QRegExp coloredTextStrings("(\\{&c[0-9a-fA-F]{3}).*?(\\{&c[0-9a-fA-F]{3})|(\\})");
 QString Client::parseNameFun(const QString &string)
 {
   QByteArray b(string.toLatin1());

+ 3 - 5
Client.h

@@ -231,14 +231,12 @@ private:
   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
+  QTimer*           myFloodTimer;            // Floodtimer for all commands
+  QTimer*           myBroadcastFloodTimer;   // Floodtimer for .qw|.spam broadcasts
 
   // Used to calculate how much time is there left on the flood timers
   QTime             myFloodTimerStart;
-  QTime             myQWBroadcastFloodTimerStart;
-  QTime             mySpamBroadcastFloodTimerStart;
+  QTime             myBroadcastFloodTimerStart;
 
   // Used to avoid information printed countless times
   bool							myFloodMsgPrinted;