Переглянути джерело

Removed unused files. Bot now says Hi only on connection.

Mihawk 14 роки тому
батько
коміт
586f9b350a
6 змінених файлів з 18 додано та 204 видалено
  1. 0 1
      App.cpp
  2. 16 3
      Client.cpp
  3. 2 0
      Client.h
  4. 0 143
      ServerQueryThread.cpp
  5. 0 55
      ServerQueryThread.h
  6. 0 2
      cimsqwbot.pro

+ 0 - 1
App.cpp

@@ -12,7 +12,6 @@
 #include <QHostAddress>
 #include "SshClient.h"
 #include "ActiveClient.h"
-#include "ServerQueryThread.h"
 #include "Settings.h"
 
 App::App(int &argc, char **argv) :

+ 16 - 3
Client.cpp

@@ -17,7 +17,8 @@ Client::Client(App *app, ActiveClient* ac):
   mySpamMutedFlag(false),
   myQWMutedFlag(false),
   myJoinMessageTimer(new QTimer()),
-  myJoinMessagePrinted(false)
+  myJoinMessagePrinted(false),
+  myJoinMessageScheduled(false)
 {
   myEndFloodTime = QTime::currentTime();
   myQWBroadcastFloodTime = myEndFloodTime;
@@ -30,6 +31,12 @@ Client::~Client()
   delete myJoinMessageTimer;
 }
 
+void Client::connect(const char *host, quint16 port)
+{
+  myJoinMessageScheduled = true; //Hi message only scheduled at bot connection
+  QWClient::connect(host, port);
+}
+
 void Client::say(const QString &msg)
 {
 	QString cmd = "say " + msg;
@@ -329,8 +336,14 @@ void Client::onStuffedCmd(const char *cmd)
 	{
 		myConnectionRetries = 0;
     myOnServerFlag = true;
-    myJoinMessageTimer->start(Settings::globalInstance()->timeToSayHiAfterConnected()*1000);
-    myJoinMessagePrinted = false;
+
+    /* Only say hi if hi is scheduled */
+    if(myJoinMessageScheduled)
+    {
+      myJoinMessageTimer->start(Settings::globalInstance()->timeToSayHiAfterConnected()*1000);
+      myJoinMessagePrinted = false;
+      myJoinMessageScheduled = false;
+    }
 	}
 }
 

+ 2 - 0
Client.h

@@ -18,6 +18,7 @@ class Client : public QWClient
 public:
   Client(App* app, ActiveClient* ac);
   ~Client();
+  void connect(const char *host, quint16 port);
   void run();
   void disconnect();
   void say(const QString& msg);
@@ -60,6 +61,7 @@ private:
   QTime             myQWBroadcastFloodTime;
   QTime             mySpamBroadcastFloodTime;
   bool              myJoinMessagePrinted;
+  bool              myJoinMessageScheduled;
   PlayerList        myPlayerList;
 
   void print(const QString& msg);

+ 0 - 143
ServerQueryThread.cpp

@@ -1,143 +0,0 @@
-/*
-GNU General Public License version 3 notice
-
-Copyright (C) 2012 Mihawk <luiz@netdome.biz>. All rights reserved.
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see < http://www.gnu.org/licenses/ >.
-*/
-
-#include "ServerQueryThread.h"
-#include <QReadWriteLock>
-#include <QThreadPool>
-#include <QThread>
-
-class Sleeper: public QThread
-{
-public:
-  static void msleep(unsigned long msec)
-  {
-    QThread::msleep(msec);
-  }
-};
-
-ServerQueryThread::ServerQueryThread():
-  QRunnable(),
-  myStopMutex(new QReadWriteLock()),
-  myServerInfoMutex(new QReadWriteLock()),
-  myStopThreadFlag(true),
-  myThreadRunningFlag(false),
-  myServerPlayerCount(0)
-{
-  setAutoDelete(false);
-  myStopMutex->unlock();
-  myServerInfoMutex->unlock();
-}
-
-ServerQueryThread::~ServerQueryThread()
-{
-  delete myStopMutex;
-  delete myServerInfoMutex;
-}
-
-void ServerQueryThread::setAddress(const QHostAddress &address, quint16 port)
-{
-  myServerAddress = address;
-  myServerPort = port;
-  return;
-}
-
-bool ServerQueryThread::startQueryThread()
-{
-  if(!isRunning())
-  {
-    myStopThreadFlag = false;
-    myThreadRunningFlag = true;
-    QThreadPool::globalInstance()->start(this);
-    return true;
-  }
-  return false;
-}
-
-void ServerQueryThread::stopQueryThread()
-{
-  myStopMutex->lockForWrite();
-  myStopThreadFlag = true;
-  myStopMutex->unlock();
-}
-
-quint8 ServerQueryThread::playerCount() const
-{
-  myServerInfoMutex->lockForRead();
-  quint8 c = myServerPlayerCount;
-  myServerInfoMutex->unlock();
-  return c;
-}
-
-bool ServerQueryThread::isRunning() const
-{
-  myStopMutex->lockForRead();
-  bool r = myThreadRunningFlag;
-  myStopMutex->unlock();
-  return r;
-}
-
-const QHostAddress& ServerQueryThread::serverAddress() const
-{
-  return myServerAddress;
-}
-
-quint16 ServerQueryThread::serverPort() const
-{
-  return myServerPort;
-}
-
-void ServerQueryThread::run()
-{
-  ServerQuery* query = new ServerQuery();
-  query->setAddress(myServerAddress, myServerPort);
-
-  forever
-  {
-    /* Handle thread stop request */
-    myStopMutex->lockForRead();
-    if(myStopThreadFlag)
-    {
-      myStopMutex->unlock();
-
-      myStopMutex->lockForWrite();
-      myThreadRunningFlag = false;
-      myStopMutex->unlock();
-
-      delete query;
-      return;
-    }
-    myStopMutex->unlock();
-
-    if(query->query())
-    {
-      myServerInfoMutex->lockForWrite();
-      myServerPlayerCount = query->playerList().size();
-      myServerInfoMutex->unlock();
-    }
-    //    else
-    //    {
-    //      /* On fail set to 0xff to indicate bad read, so that the client don't act on this */
-    //      myServerInfoMutex->lockForWrite();
-    //      myServerPlayerCount = 0xff;
-    //      myServerInfoMutex->unlock();
-    //    }
-    Sleeper::msleep(1000);
-  }
-}
-

+ 0 - 55
ServerQueryThread.h

@@ -1,55 +0,0 @@
-/*
-GNU General Public License version 3 notice
-
-Copyright (C) 2012 Mihawk <luiz@netdome.biz>. All rights reserved.
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see < http://www.gnu.org/licenses/ >.
-*/
-
-#ifndef SERVERQUERYTHREAD_H
-#define SERVERQUERYTHREAD_H
-
-#include <QRunnable>
-#include "ServerQuery.h"
-
-class QReadWriteLock;
-
-class ServerQueryThread : public QRunnable
-{
-public:
-  ServerQueryThread();
-  virtual ~ServerQueryThread();
-
-  void setAddress(const QHostAddress& serverAddress, quint16 serverPort);
-  bool startQueryThread();
-  void stopQueryThread();
-  quint8 playerCount() const;
-  bool isRunning() const;
-  const QHostAddress& serverAddress() const;
-  quint16 serverPort() const;
-
-protected:
-  void run();
-
-private:
-  QReadWriteLock* myStopMutex; /* For reading thread state and for stopping the thread */
-  QReadWriteLock* myServerInfoMutex; /* For retrieving server information regarding the player count */
-  bool myStopThreadFlag;
-  bool myThreadRunningFlag;
-  QHostAddress myServerAddress;
-  quint16 myServerPort;
-  quint8 myServerPlayerCount;
-};
-
-#endif // SERVERQUERYTHREAD_H

+ 0 - 2
cimsqwbot.pro

@@ -8,7 +8,6 @@ SOURCES += main.cpp \
     App.cpp \
     ServerQuery.cpp \
     SshClient.cpp \
-    ServerQueryThread.cpp \
     ActiveClient.cpp \
     Settings.cpp
 
@@ -17,7 +16,6 @@ HEADERS += \
     App.h \
     ServerQuery.h \
     SshClient.h \
-    ServerQueryThread.h \
     ActiveClient.h \
     Settings.h