ソースを参照

.qw_mute/unmute .spam_mute/unmute commands added.

Mihawk 12 年 前
コミット
3cdef267ae
3 ファイル変更48 行追加17 行削除
  1. 11 2
      App.cpp
  2. 33 13
      Client.cpp
  3. 4 2
      Client.h

+ 11 - 2
App.cpp

@@ -424,13 +424,17 @@ void App::requestBroadcast(const QString &type, const QString &user, const QStri
 void App::broadcast(const QString &msg, ActiveClient* ignoredClient)
 {
   ActiveClient* ac;
+  QString frequency = msg.section(' ', 0, 0);
 
   foreach(ac, myClients)
   {
     if(ac == ignoredClient)
       continue;
 
-    if(ac->client()->state() == Client::ConnectedState && !ac->client()->isMuted())
+    if((frequency == "-qw-" && ac->client()->isQWMuted()) || (frequency == "-spam-" && ac->client()->isSpamMuted()))
+      continue;
+
+    if(ac->client()->state() == Client::ConnectedState)
       ac->client()->say(msg);
   }
 }
@@ -442,9 +446,14 @@ void App::broadcast(const QString &msg, int *serverCount, int *userCount)
   *serverCount = 0;
   *userCount = 0;
 
+  QString frequency = msg.section(' ', 0, 0);
+
   foreach(ac, myClients)
   {
-    if(ac->client()->state() == Client::ConnectedState && !ac->client()->isMuted())
+    if((frequency == "-qw-" && ac->client()->isQWMuted()) || (frequency == "-spam-" && ac->client()->isSpamMuted()))
+      continue;
+
+    if(ac->client()->state() == Client::ConnectedState)
     {
       ac->client()->say(msg);
       *userCount += ac->playerCount() - 1;

+ 33 - 13
Client.cpp

@@ -14,7 +14,8 @@ Client::Client(App *app, ActiveClient* ac):
   myApp(app),
   myConnectionRetries(0),
   myOnServerFlag(false),
-  myMutedFlag(false),
+  mySpamMutedFlag(false),
+  myQWMutedFlag(false),
   myJoinMessageTimer(new QTimer()),
   myJoinMessagePrinted(false)
 {
@@ -90,9 +91,14 @@ void Client::retryConnection()
 	myConnectionRetries++;
 }
 
-bool Client::isMuted() const
+bool Client::isQWMuted() const
 {
-  return myMutedFlag;
+  return myQWMutedFlag;
+}
+
+bool Client::isSpamMuted() const
+{
+  return mySpamMutedFlag;
 }
 
 void Client::parsePrintedLine()
@@ -130,7 +136,7 @@ void Client::parsePrintedLine()
   QString nick(myPrintLine.left(lastMatchSize));
   QString message(myPrintLine.right(myPrintLine.size() - lastMatchSize));
 
-  QRegExp regex("^:\\s+\\.(spam|qw|help|mute|unmute)\\s*(.+)$");
+  QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute)\\s*(.+)$");
   if(regex.indexIn(message) == -1)
     return;
 
@@ -156,8 +162,8 @@ void Client::parsePrintedLine()
 	if(command == "help")
 	{
     say("> Commands:");
-    say("> Broadcast message: .qw <message> and .spam <message>");
-    say("> Mute/Unmute the bot: .mute and .unmute");
+    say("> Broadcast a message: .qw <message> and .spam <message>, beware of the floodprot limits 600s for .qw and 300s for .spam");
+    say("> Mute/Unmute: .qw_mute and .qw_unmute or .spam_mute or .spam_unmute");
     say("> .help to show this help message.");
 		return;
 	}
@@ -206,17 +212,31 @@ void Client::parsePrintedLine()
 		return;
 	}
 
-  if(command == "mute")
+  if(command == "qw_mute")
+  {
+    say("> .qw Frequency Muted.");
+    myQWMutedFlag = true;
+    return;
+  }
+
+  if(command == "qw_unmute")
+  {
+    say("> .qw Frequency Unmuted.");
+    myQWMutedFlag = false;
+    return;
+  }
+
+  if(command == "spam_mute")
   {
-    say("> Muted!");
-    myMutedFlag = true;
+    say("> .spam Frequency Muted.");
+    mySpamMutedFlag = true;
     return;
   }
 
-  if(command == "unmute")
+  if(command == "spam_unmute")
   {
-    say("> Unmuted!");
-    myMutedFlag = false;
+    say("> .spam Frequency Unmuted.");
+    mySpamMutedFlag = false;
     return;
   }
 }
@@ -263,7 +283,7 @@ void Client::onLevelChanged(int, const char *levelName, float, float, float, flo
 {
 	print(QString(levelName) + "\n");
 	myDownloadProgressPrintedFlag = false;
-  myMutedFlag = false;
+  mySpamMutedFlag = false;
 }
 
 void Client::onChallenge()

+ 4 - 2
Client.h

@@ -26,7 +26,8 @@ public:
 	void setSocket(class QTcpSocket* socket);
   void retryConnection(); //unused
   bool isOnServer() const;
-  bool isMuted() const;
+  bool isQWMuted() const;
+  bool isSpamMuted() const;
   void setPlayerList(PlayerList &playerList);
 
 protected:
@@ -53,7 +54,8 @@ private:
 	QString						myPrintLine;
 	bool							myDownloadProgressPrintedFlag;
   bool              myOnServerFlag;
-  bool              myMutedFlag;
+  bool              mySpamMutedFlag;
+  bool              myQWMutedFlag;
   QTimer*           myJoinMessageTimer;
   QTime             myQWBroadcastFloodTime;
   QTime             mySpamBroadcastFloodTime;