Browse Source

Message history

Mihawk 12 years ago
parent
commit
94d9ced84f
3 changed files with 36 additions and 2 deletions
  1. 16 0
      App.cpp
  2. 5 1
      App.h
  3. 15 1
      Client.cpp

+ 16 - 0
App.cpp

@@ -241,6 +241,11 @@ void App::onDataArrival()
 	}
 }
 
+const QStringList& App::lastMessages() const
+{
+  return myLastMessages;
+}
+
 void App::help()
 {
 	print("connect server:port -> connects the bot on a server\n");
@@ -423,11 +428,20 @@ void App::requestBroadcast(const QString &type, const QString &user, const QStri
     myQWNETSshClient->write("REQ_BC QDEV,-dev-,qw://" + server + ",'" + user + "','" + message + "'\n");
 }
 
+void App::addMessageToHistory(const QString &msg)
+{
+  myLastMessages.push_back(msg);
+  if(myLastMessages.size() > 5)
+    myLastMessages.removeAt(0);
+}
+
 void App::broadcast(const QString &msg, ActiveClient* ignoredClient)
 {
   ActiveClient* ac;
   QString frequency = msg.section(' ', 0, 0);
 
+  addMessageToHistory(msg);
+
   foreach(ac, myClients)
   {
     if(ac == ignoredClient)
@@ -450,6 +464,8 @@ void App::broadcast(const QString &msg, int *serverCount, int *userCount)
 
   QString frequency = msg.section(' ', 0, 0);
 
+  addMessageToHistory(msg);
+
   foreach(ac, myClients)
   {
     if((frequency == "-qw-" && ac->client()->isQWMuted()) || (frequency == "-spam-" && ac->client()->isSpamMuted()))

+ 5 - 1
App.h

@@ -5,6 +5,7 @@
 #include <QList>
 #include <QSettings>
 #include <QHostAddress>
+#include <QStringList>
 
 class SshClient;
 class QTcpSocket;
@@ -26,6 +27,7 @@ public:
   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, ActiveClient* ignoreClient = 0);
+  const QStringList&    lastMessages() const;
 
 protected:
 	void									timerEvent(QTimerEvent *e);
@@ -40,12 +42,14 @@ private:
 	quint32								myCurrentClient;
 	QSettings							mySettings;
 	int										myClientsFrameTimerID; //timer for mainloop
+  QStringList           myLastMessages;
 
   void									loadServerList();
   void                  saveServerList();
 	void									cleanup();
+  void                  addMessageToHistory(const QString& msg);
 
-	/* TCP Server */
+  /* TCP Server */
 	bool									checkPassword(const QString& password);
   void									addClient(const QString& host, quint16 port);
 	void									removeClient(const QString& host, quint16 port);

+ 15 - 1
Client.cpp

@@ -148,7 +148,7 @@ void Client::parsePrintedLine()
   QString nick(myPrintLine.left(lastMatchSize));
   QString message(myPrintLine.right(myPrintLine.size() - lastMatchSize));
 
-  QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute)\\s*(.+)$");
+  QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute|lastmsgs)\\s*(.+)$");
   if(regex.indexIn(message) == -1)
     return;
 
@@ -254,6 +254,20 @@ void Client::parsePrintedLine()
     mySpamMutedFlag = false;
     return;
   }
+
+  if(command == "lastmsgs")
+  {
+    QString msg;
+    int i = 0;
+    foreach(msg, myApp->lastMessages())
+    {
+      if(++i > 5)
+        break;
+
+      say(msg);
+    }
+    return;
+  }
 }
 
 int Client::playerCount() const