Browse Source

Added developer mode. Now messages from the bot contains the player
count and maxclients information.

Mihawk 12 years ago
parent
commit
59d731fdb1
9 changed files with 63 additions and 6 deletions
  1. 1 1
      ActiveClient.cpp
  2. 4 1
      App.cpp
  3. 31 4
      Client.cpp
  4. 4 0
      Client.h
  5. 11 0
      ServerQuery.cpp
  6. 1 0
      ServerQuery.h
  7. 6 0
      Settings.cpp
  8. 1 0
      Settings.h
  9. 4 0
      SshClient.cpp

+ 1 - 1
ActiveClient.cpp

@@ -75,10 +75,10 @@ void ActiveClient::queryError(ServerQuery::Error)
 
 void ActiveClient::queryFinished()
 {
-
   PlayerList playerList = myQuery->playerList();
   int playerCount = playerList.size();
   myClient->setPlayerList(playerList);
+  myClient->setMaxClients(myQuery->serverRuleValue("maxclients").toInt());
 
   myQueryTimer->start(myQueryInterval);
 

+ 4 - 1
App.cpp

@@ -417,7 +417,10 @@ void App::timerEvent(QTimerEvent *e)
 
 void App::requestBroadcast(const QString &type, const QString &user, const QString &server, const QString &message)
 {
-  myQWNETSshClient->write("REQ_BC QWalt,-" + type + "-,qw://" + server + ",'" + user + "','" + message + "'\n");
+  if(!Settings::globalInstance()->developerMode())
+    myQWNETSshClient->write("REQ_BC QWalt,-" + type + "-,qw://" + server + ",'" + user + "','" + message + "'\n");
+  else
+    myQWNETSshClient->write("REQ_BC QDEV,-dev-,qw://" + server + ",'" + user + "','" + message + "'\n");
 }
 
 void App::broadcast(const QString &msg, ActiveClient* ignoredClient)

+ 31 - 4
Client.cpp

@@ -19,7 +19,8 @@ Client::Client(App *app, ActiveClient* ac):
   myJoinMessageTimer(new QTimer()),
   myKeepNickTimer(new QTimer()),
   myJoinMessagePrinted(false),
-  myJoinMessageScheduled(false)
+  myJoinMessageScheduled(false),
+  myMaxClients(0)
 {
   myJoinMessageTimer->setSingleShot(true);
   myKeepNickTimer->setSingleShot(true);
@@ -208,7 +209,7 @@ void Client::parsePrintedLine()
       mySpamBroadcastFloodTime = currentTime.addSecs(Settings::globalInstance()->spamFloodProtTime());
     }
 
-    QString server(QString(host()) + ":" + QString::number(port()));
+    QString server(QString(host()) + ":" + QString::number(port()) + " " + QString::number(playerCount()) + "/" + QString::number(myMaxClients));
     QString message("-" + command + "- " + nick + " - " + server + " : " + args.trimmed());
 
     /* Broadcast within QW servers */
@@ -217,8 +218,11 @@ void Client::parsePrintedLine()
     /* 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());
+
+    if(!Settings::globalInstance()->developerMode())
+      myApp->requestBroadcast(command, nick, server, args.trimmed());
+    else
+      myApp->requestBroadcast("dev", nick, server, parsedMsg);
 
 		return;
 	}
@@ -252,6 +256,29 @@ void Client::parsePrintedLine()
   }
 }
 
+int Client::playerCount() const
+{
+  Player c;
+  int pc = 0;
+  foreach(c, myPlayerList)
+  {
+    if(c.spectator)
+      continue;
+    pc++;
+  }
+  return pc;
+}
+
+void Client::setMaxClients(int maxClients)
+{
+  myMaxClients = maxClients;
+}
+
+int Client::maxClients() const
+{
+  return myMaxClients;
+}
+
 void Client::onPrint(int, const char *msg)
 {
 	if(!strlen(msg))

+ 4 - 0
Client.h

@@ -30,6 +30,7 @@ public:
   bool isQWMuted() const;
   bool isSpamMuted() const;
   void setPlayerList(PlayerList &playerList);
+  void setMaxClients(int maxClients);
 
 protected:
 	void onLevelChanged(int playerNum, const char *levelName, float gravity, float stopSpeed, float maxSpeed, float spectatorMaxSpeed, float accelerate, float airAccelerate, float waterAccelerate, float friction, float waterFriction, float entGravity);
@@ -64,9 +65,12 @@ private:
   bool              myJoinMessagePrinted;
   bool              myJoinMessageScheduled;
   PlayerList        myPlayerList;
+  int               myMaxClients;
 
   void print(const QString& msg);
 	void parsePrintedLine();
+  int  playerCount() const;
+  int  maxClients() const;
 
   static QString parseNameFun(const QString& string);
 };

+ 11 - 0
ServerQuery.cpp

@@ -269,6 +269,17 @@ ServerRules ServerQuery::serverRules() const
   return myRules;
 }
 
+QString ServerQuery::serverRuleValue(const QString &ruleName) const
+{
+  ServerRule r;
+  foreach(r, myRules)
+  {
+    if(r.rule == ruleName)
+      return r.value;
+  }
+  return QString();
+}
+
 //========================================================================
 /* Name fun */
 char ServerQuery::ourReadableCharsTable[256] = {	'.', '_' , '_' , '_' , '_' , '.' , '_' , '_' , '_' , '_' , '\n' , '_' , '\n' , '>' , '.' , '.',

+ 1 - 0
ServerQuery.h

@@ -71,6 +71,7 @@ public:
 
   PlayerList    playerList() const;
   ServerRules   serverRules() const;
+  QString       serverRuleValue(const QString& ruleName) const;
 
 signals:
   void          error(ServerQuery::Error err);

+ 6 - 0
Settings.cpp

@@ -128,6 +128,11 @@ int Settings::timeToWaitForCountReply() const
   return ourSettings->value("timeToWaitForCountReply", 7).toInt();
 }
 
+bool Settings::developerMode() const
+{
+  return ourSettings->value("developerMode", false).toBool();
+}
+
 void Settings::save()
 {
   ourSettings->setValue("quakeFolder", quakeFolder());
@@ -142,6 +147,7 @@ void Settings::save()
   ourSettings->setValue("spamFloodProtTime", spamFloodProtTime());
   ourSettings->setValue("timeToSayHiAfterConnected", timeToSayHiAfterConnected());
   ourSettings->setValue("timeToWaitForCountReply", timeToWaitForCountReply());
+  ourSettings->setValue("developerMode", developerMode());
 
   QStringList list = serverList();
   setServerList(list);

+ 1 - 0
Settings.h

@@ -44,6 +44,7 @@ public:
   unsigned int      queryInterval() const;
   int               timeToSayHiAfterConnected() const;
   int               timeToWaitForCountReply() const;
+  bool              developerMode() const;
 
   void              save();
 

+ 4 - 0
SshClient.cpp

@@ -19,6 +19,7 @@ along with this program.  If not, see < http://www.gnu.org/licenses/ >.
 
 #include "SshClient.h"
 #include "App.h"
+#include "Settings.h"
 #include <QProcess>
 #include <QRegExp>
 #include <QDateTime>
@@ -153,6 +154,9 @@ void SshClient::parse(const QDateTime &time, const QString &command, const QStri
     if(a.indexIn(commandData) == -1)
       return;
 
+    if(a.cap(2) == "QDEV" && !Settings::globalInstance()->developerMode()) //developer mode not enabled ignore this message from developers
+      return;
+
     int serverCount, userCount;
 
     myApp->broadcast(a.cap(3) + " " + a.cap(5) + " - " + a.cap(4) + " : " + a.cap(6), &serverCount, &userCount);