Ver código fonte

S-P detection.

Mihawk 12 anos atrás
pai
commit
3a655cae91
2 arquivos alterados com 36 adições e 0 exclusões
  1. 29 0
      Client.cpp
  2. 7 0
      Client.h

+ 29 - 0
Client.cpp

@@ -36,6 +36,7 @@ Client::Client(App *app, ActiveClient* ac, bool supportsSendPrivate):
   mySpamMutedFlag(false),
   myQWMutedFlag(false),
   myKeepNickTimer(new QTimer()),
+  mySPDetectionTimer(new QTimer()),
   myFloodTimer(new QTimer()),
   myQWBroadcastFloodTimer(new QTimer()),
   mySpamBroadcastFloodTimer(new QTimer()),
@@ -55,6 +56,7 @@ Client::~Client()
   delete myFloodTimer;
   delete myQWBroadcastFloodTimer;
   delete mySpamBroadcastFloodTimer;
+  delete mySPDetectionTimer;
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -166,6 +168,23 @@ void Client::parsePrintedLine()
 
   QString message(myPrintLine.right(myPrintLine.size() - lastMatchSize));
 
+  // Detects whether s-p command is supported
+  if(mySPDetectionActive)
+  {
+    if(mySPDetectionTimer->isActive() && nick == Settings::globalInstance()->botName() && message == "s-p")
+    {
+      mySupportsSendPrivate = false;
+      mySPDetectionTimer->stop();
+      mySPDetectionActive = false;
+    }
+    else if(!mySPDetectionTimer->isActive())
+    {
+      mySupportsSendPrivate = true;
+      mySPDetectionTimer->stop();
+      mySPDetectionActive = false;
+    }
+  }
+
   QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute|lm)\\s*(.+)$");
   if(regex.indexIn(message) == -1)
     return;
@@ -450,6 +469,7 @@ void Client::onStuffedCmd(const char *cmd)
     myOnServerFlag = true;
 
     setPing(Settings::globalInstance()->botPing());
+    spDetection();
   }
 }
 
@@ -482,6 +502,15 @@ bool Client::supportsSendPrivate() const
   return mySupportsSendPrivate;
 }
 
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+void Client::spDetection()
+{
+  say("s-p");
+  mySPDetectionTimer->setSingleShot(true);
+  mySPDetectionTimer->start(2000);
+  mySPDetectionActive = true;
+}
+
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 QString Client::parseNameFun(const QString &string)
 {

+ 7 - 0
Client.h

@@ -231,6 +231,8 @@ private:
   bool              myQWMutedFlag;
 
   QTimer*           myKeepNickTimer;    // Interval in which the bot tries to retake his nickname
+  QTimer*           mySPDetectionTimer; // Timer to wait for a say s-p command reply (if it replies there is support for it)
+  bool              mySPDetectionActive;
 
   // Flood timers
   QTimer*           myFloodTimer;              // Floodtimer for all commands
@@ -282,6 +284,11 @@ private:
   */
   int  maxClients() const;
 
+  /**
+    Detects whether this server supports s-p command or not.
+  */
+  void spDetection();
+
   /**
     Parses any namefun string and converts it to readable text.