Bladeren bron

Sent in one single line. Not counting players on the server broadcasting
the message. .spam and .qw have their own timers now.

Mihawk 12 jaren geleden
bovenliggende
commit
a0f05b0c7e
7 gewijzigde bestanden met toevoegingen van 70 en 19 verwijderingen
  1. 2 3
      ActiveClient.cpp
  2. 4 1
      App.cpp
  3. 1 1
      App.h
  4. 35 11
      Client.cpp
  5. 4 1
      Client.h
  6. 21 2
      Settings.cpp
  7. 3 0
      Settings.h

+ 2 - 3
ActiveClient.cpp

@@ -111,9 +111,8 @@ void ActiveClient::run()
   /* Say the broadcast count */
   if(!myBroadcastReplyTimer->isActive() && myReplyTimerWasActive)
   {
-    myApp->activeClientsReplyCounters(&myUniqueServerCount, &myUniquePlayerCount); //add my internal counter to the list
-    myClient->say("::cims:: Sent to " + QString::number(myUniqueChannelCount) + " channels, " + QString::number(myUniqueUserCount) + " unique users.");
-    myClient->say("::cims:: Sent to " + QString::number(myUniqueServerCount) + " servers, " + QString::number(myUniquePlayerCount) + " unique players.");
+    myApp->activeClientsReplyCounters(&myUniqueServerCount, &myUniquePlayerCount, this); //add our servers to the list
+    myClient->say("::cims:: Sent to " + QString::number(myUniqueChannelCount) + " channels " + QString::number(myUniqueUserCount) + " unique users and to " + QString::number(myUniqueServerCount) + " servers " + QString::number(myUniquePlayerCount) + " unique players.");
     myUniqueServerCount = myUniquePlayerCount = myUniqueChannelCount = myUniqueUserCount = 0;
   }
   myReplyTimerWasActive = myBroadcastReplyTimer->isActive();

+ 4 - 1
App.cpp

@@ -380,12 +380,15 @@ void App::listClients()
 	}
 }
 
-void App::activeClientsReplyCounters(int *serverCount, int *playerCount)
+void App::activeClientsReplyCounters(int *serverCount, int *playerCount, ActiveClient *ignoreClient)
 {
   ActiveClient* ac;
 
   foreach(ac, myClients)
   {
+    if(ac == ignoreClient)
+      continue;
+
     if(ac->client()->state() == Client::ConnectedState)
     {
       int pc = ac->playerCount();

+ 1 - 1
App.h

@@ -25,7 +25,7 @@ public:
   void                  requestBroadcast(const QString& type, const QString& user, const QString& server, const QString& message);
   void                  setReplyHash(const QString& serverAddress, const QString& hash);
   void                  incrementReplyCounters(const QString& hash, int userCount, int channelCount, int playerCount, int serverCount);
-  void                  activeClientsReplyCounters(int *serverCount, int *playerCount);
+  void                  activeClientsReplyCounters(int *serverCount, int *playerCount, ActiveClient* ignoreClient = 0);
 
 protected:
 	void									timerEvent(QTimerEvent *e);

+ 35 - 11
Client.cpp

@@ -12,20 +12,20 @@ Client::Client(App *app, ActiveClient* ac):
   QWClient(),
   myActiveClient(ac),
   myApp(app),
-  myEndFloodTime(new QTime()),
   myConnectionRetries(0),
   myOnServerFlag(false),
   myMutedFlag(false),
   myJoinMessageTimer(new QTimer()),
   myJoinMessagePrinted(false)
 {
-  *myEndFloodTime = QTime::currentTime();
+  myEndFloodTime = QTime::currentTime();
+  myQWBroadcastFloodTime = myEndFloodTime;
+  mySpamBroadcastFloodTime = myEndFloodTime;
   myJoinMessageTimer->setSingleShot(true);
 }
 
 Client::~Client()
 {
-  delete myEndFloodTime;
   delete myJoinMessageTimer;
 }
 
@@ -122,22 +122,25 @@ void Client::parsePrintedLine()
 
   QString nick(myPrintLine.left(lastMatchSize));
   QString message(myPrintLine.right(myPrintLine.size() - lastMatchSize));
-  QRegExp regex("^:\\s+\\.([A-Za-z]+)\\s*(.+)$");
+
+  QRegExp regex("^:\\s+\\.(spam|qw|help|mute|unmute)\\s*(.+)$");
   if(regex.indexIn(message) == -1)
     return;
 
 	/* Flood prot */
-  int timeLeft = QTime::currentTime().secsTo(*myEndFloodTime);
+  QTime currentTime = QTime::currentTime();
+
+  int timeLeft = currentTime.secsTo(myEndFloodTime);
   if(timeLeft > 0)
 	{
 		if(!myFloodMsgPrinted)
 		{
-      say("> Wait " + QString::number(timeLeft) + " second(s) before issuing a new command.");
+      say("> FloodProt: Not so fast, wait " + QString::number(timeLeft) + " sec(s).");
 			myFloodMsgPrinted = true;
 		}
 		return;
 	}
-  *myEndFloodTime = QTime::currentTime().addSecs(Settings::globalInstance()->floodProtTime());
+  myEndFloodTime = QTime::currentTime().addSecs(Settings::globalInstance()->floodProtTime());
   myFloodMsgPrinted = false;
 
   QString command = regex.capturedTexts().at(1);
@@ -160,17 +163,38 @@ void Client::parsePrintedLine()
       return;
     }
 
+    if(command == "qw")
+    {
+      timeLeft = currentTime.secsTo(myQWBroadcastFloodTime);
+      if(timeLeft > 0)
+      {
+        say("> FloodProt: Wait " + QString::number(timeLeft) + " sec(s) before broadcasting a new .qw message.");
+        return;
+      }
+      myQWBroadcastFloodTime = currentTime.addSecs(Settings::globalInstance()->qwFloodProtTime());
+    }
+    else if(command == "spam")
+    {
+      timeLeft = currentTime.secsTo(mySpamBroadcastFloodTime);
+      if(timeLeft > 0)
+      {
+        say("> FloodProt: Wait " + QString::number(timeLeft) + " sec(s) before broadcasting a new .spam message.");
+        return;
+      }
+      mySpamBroadcastFloodTime = currentTime.addSecs(Settings::globalInstance()->spamFloodProtTime());
+    }
+
     QString server(QString(host()) + ":" + QString::number(port()));
     QString message("-" + command + "- " + nick + " - " + server + " : " + args.trimmed());
 
-    //-qw- Skillah - #crazy88 : 4on4 MIX qw.foppa.dk:27503 7/8
+    /* Broadcast within QW servers */
     myApp->broadcast(message, myActiveClient);
 
-    //myApp->requestBroadcast(command, nick, server, args.trimmed());
-
+    /* Broadcast outside QW */
     nick = parseNameFun(nick); //for the irc message namefun must be removed.
     QString parsedMsg = parseNameFun(args.trimmed());
     myApp->requestBroadcast("dev", nick, server, parsedMsg);
+    //myApp->requestBroadcast(command, nick, server, args.trimmed());
 
 		return;
 	}
@@ -277,7 +301,7 @@ void Client::onStuffedCmd(const char *cmd)
 	{
 		myConnectionRetries = 0;
     myOnServerFlag = true;
-    myJoinMessageTimer->start(10000);
+    myJoinMessageTimer->start(Settings::globalInstance()->timeToSayHiAfterConnected()*1000);
     myJoinMessagePrinted = false;
 	}
 }

+ 4 - 1
Client.h

@@ -5,6 +5,7 @@
 #include <QString>
 #include <QStringList>
 #include <QList>
+#include <QTime>
 #include "ServerQuery.h"
 
 class App;
@@ -45,7 +46,7 @@ protected:
 private:
   ActiveClient*     myActiveClient;
 	App*							myApp;
-  QTime*            myEndFloodTime;
+  QTime             myEndFloodTime;
 	bool							myFloodMsgPrinted;
 	int								myConnectionRetries;
 	static const int	ConnectionRetries = 10;
@@ -54,6 +55,8 @@ private:
   bool              myOnServerFlag;
   bool              myMutedFlag;
   QTimer*           myJoinMessageTimer;
+  QTime             myQWBroadcastFloodTime;
+  QTime             mySpamBroadcastFloodTime;
   bool              myJoinMessagePrinted;
   PlayerList        myPlayerList;
 

+ 21 - 2
Settings.cpp

@@ -75,7 +75,7 @@ QString Settings::quakeFolder() const
 
 QString Settings::botName() const
 {
-  return ourSettings->value("botName", "cims").toString();
+  return ourSettings->value("botName", "[ServeMe]").toString();
 }
 
 int Settings::botPing() const
@@ -100,7 +100,17 @@ bool Settings::botSpectator() const
 
 int Settings::floodProtTime() const
 {
-  return ourSettings->value("floodProtTime", 30).toInt();
+  return qBound<int>(6, ourSettings->value("floodProtTime", 6).toInt(), 9999);
+}
+
+int Settings::qwFloodProtTime() const
+{
+  return ourSettings->value("qwFloodProtTime", 600).toInt();
+}
+
+int Settings::spamFloodProtTime() const
+{
+  return ourSettings->value("spamFloodProtTime", 300).toInt();
 }
 
 unsigned int Settings::queryInterval() const
@@ -108,6 +118,11 @@ unsigned int Settings::queryInterval() const
   return ourSettings->value("queryInterval", 1000).toUInt();
 }
 
+int Settings::timeToSayHiAfterConnected() const
+{
+  return ourSettings->value("timeToSayHiAfterConnected", 7).toInt();
+}
+
 void Settings::save()
 {
   ourSettings->setValue("quakeFolder", quakeFolder());
@@ -118,6 +133,10 @@ void Settings::save()
   ourSettings->setValue("botSpectator", botSpectator());
   ourSettings->setValue("floodProtTime", floodProtTime());
   ourSettings->setValue("queryInterval", queryInterval());
+  ourSettings->setValue("qwFloodProtTime", qwFloodProtTime());
+  ourSettings->setValue("spamFloodProtTime", spamFloodProtTime());
+  ourSettings->setValue("timeToSayHiAfterConnected", timeToSayHiAfterConnected());
+
   QStringList list = serverList();
   setServerList(list);
 }

+ 3 - 0
Settings.h

@@ -39,7 +39,10 @@ public:
   int               botBottomColor() const;
   bool              botSpectator() const;
   int               floodProtTime() const;
+  int               qwFloodProtTime() const;
+  int               spamFloodProtTime() const;
   unsigned int      queryInterval() const;
+  int               timeToSayHiAfterConnected() const;
 
   void              save();