|
@@ -10,16 +10,30 @@
|
|
|
#include <QtSql/QSqlQuery>
|
|
|
#include <QCryptographicHash>
|
|
|
#include <QHostAddress>
|
|
|
+#include <QThread>
|
|
|
+#include <QTimer>
|
|
|
#include "SshClient.h"
|
|
|
#include "ActiveClient.h"
|
|
|
#include "Settings.h"
|
|
|
|
|
|
+class Sleeper: public QThread
|
|
|
+{
|
|
|
+public:
|
|
|
+ static void msleep(unsigned long msecs)
|
|
|
+ {
|
|
|
+ QThread::msleep(msecs);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
App::App(int &argc, char **argv) :
|
|
|
QCoreApplication(argc, argv),
|
|
|
myServer(new QTcpServer()),
|
|
|
mySocketConnectedFlag(false),
|
|
|
myQWNETSshClient(new SshClient(this))
|
|
|
{
|
|
|
+ if(!parseCommandLine())
|
|
|
+ return;
|
|
|
+
|
|
|
print("CIMS Bot Service v0.101\n========================================================\n");
|
|
|
|
|
|
setApplicationName("CIMSBOT");
|
|
@@ -27,10 +41,7 @@ App::App(int &argc, char **argv) :
|
|
|
setOrganizationName("CIMS");
|
|
|
setApplicationVersion("0.101");
|
|
|
|
|
|
- // myServer->listen(QHostAddress::Any, 45000);
|
|
|
- // connect(myServer, SIGNAL(newConnection()), SLOT(onNewConnection()));
|
|
|
-
|
|
|
- myClientsFrameTimerID = startTimer(0);
|
|
|
+ myClientsFrameTimerID = startTimer(0);
|
|
|
|
|
|
myQWNETSshClient->connectToHost("stomp", "b4r.org");
|
|
|
|
|
@@ -46,6 +57,41 @@ App::~App()
|
|
|
delete myServer;
|
|
|
}
|
|
|
|
|
|
+bool App::parseCommandLine()
|
|
|
+{
|
|
|
+ if(argc() < 2)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ QStringList args = App::arguments();
|
|
|
+ QString arg;
|
|
|
+ QStringList::const_iterator itr;
|
|
|
+ for(itr = args.constBegin()+1; itr != args.constEnd(); ++itr)
|
|
|
+ {
|
|
|
+ arg = *itr;
|
|
|
+ if(arg == "--help" || arg == "-h")
|
|
|
+ {
|
|
|
+ printf("Usage: %s [--config/-c config_file] [-h]\n", args.at(0).section("/", -1).toAscii().data());
|
|
|
+ QTimer::singleShot(0, this, SLOT(quit()));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else if(arg == "--config" || arg == "-c")
|
|
|
+ {
|
|
|
+ itr++;
|
|
|
+ if(itr == args.constEnd())
|
|
|
+ {
|
|
|
+ printf("--config: Expected config file path.\n");
|
|
|
+ QTimer::singleShot(0, this, SLOT(quit()));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ arg = *itr;
|
|
|
+ printf("Using config file [%s]...\n", arg.toAscii().data());
|
|
|
+ Settings::globalInstance()->changeConfigFile(*itr);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
void App::onNewConnection()
|
|
|
{
|
|
|
if(mySocketConnectedFlag)
|
|
@@ -416,8 +462,8 @@ void App::timerEvent(QTimerEvent *e)
|
|
|
{
|
|
|
ac->run();
|
|
|
}
|
|
|
- return;
|
|
|
}
|
|
|
+ Sleeper::msleep(1);
|
|
|
}
|
|
|
|
|
|
void App::requestBroadcast(const QString &type, const QString &user, const QString &server, const QString &message)
|