|
@@ -16,6 +16,13 @@
|
|
|
#include "ActiveClient.h"
|
|
|
#include "Settings.h"
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+/**
|
|
|
+ Used just to expose the msleep function
|
|
|
+ from QThread
|
|
|
+
|
|
|
+ @author Mihawk <luiz@netdome.biz>
|
|
|
+*/
|
|
|
class Sleeper: public QThread
|
|
|
{
|
|
|
public:
|
|
@@ -25,6 +32,7 @@ public:
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
App::App(int &argc, char **argv) :
|
|
|
QCoreApplication(argc, argv),
|
|
|
myServer(new QTcpServer()),
|
|
@@ -32,7 +40,10 @@ App::App(int &argc, char **argv) :
|
|
|
myQWNETSshClient(new SshClient(this))
|
|
|
{
|
|
|
if(!parseCommandLine())
|
|
|
+ {
|
|
|
+ QTimer::singleShot(0, this, SLOT(quit()));
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
print("CIMS Bot Service v0.101\n========================================================\n");
|
|
|
|
|
@@ -50,6 +61,7 @@ App::App(int &argc, char **argv) :
|
|
|
Settings::globalInstance()->save();
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
App::~App()
|
|
|
{
|
|
|
Settings::globalInstance()->save();
|
|
@@ -57,6 +69,7 @@ App::~App()
|
|
|
delete myServer;
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
bool App::parseCommandLine()
|
|
|
{
|
|
|
if(argc() < 2)
|
|
@@ -71,7 +84,6 @@ bool App::parseCommandLine()
|
|
|
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")
|
|
@@ -80,7 +92,6 @@ bool App::parseCommandLine()
|
|
|
if(itr == args.constEnd())
|
|
|
{
|
|
|
printf("--config: Expected config file path.\n");
|
|
|
- QTimer::singleShot(0, this, SLOT(quit()));
|
|
|
return false;
|
|
|
}
|
|
|
arg = *itr;
|
|
@@ -92,6 +103,7 @@ bool App::parseCommandLine()
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::onNewConnection()
|
|
|
{
|
|
|
if(mySocketConnectedFlag)
|
|
@@ -111,12 +123,14 @@ void App::onNewConnection()
|
|
|
print("Connected to CIMS's bot service.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::onDisconnection()
|
|
|
{
|
|
|
mySocketConnectedFlag = false;
|
|
|
mySocket->deleteLater();
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::loadServerList()
|
|
|
{
|
|
|
QStringList list = Settings::globalInstance()->serverList();
|
|
@@ -137,6 +151,7 @@ void App::loadServerList()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::saveServerList()
|
|
|
{
|
|
|
QStringList list;
|
|
@@ -148,6 +163,7 @@ void App::saveServerList()
|
|
|
Settings::globalInstance()->setServerList(list);
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::parseAddClientCommand(const QString &args)
|
|
|
{
|
|
|
if(!args.size())
|
|
@@ -175,6 +191,7 @@ void App::parseAddClientCommand(const QString &args)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::parseRemoveClientCommand(const QString &args)
|
|
|
{
|
|
|
if(!args.size())
|
|
@@ -197,6 +214,7 @@ void App::parseRemoveClientCommand(const QString &args)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::onDataArrival()
|
|
|
{
|
|
|
while(mySocket->canReadLine())
|
|
@@ -287,11 +305,13 @@ void App::onDataArrival()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
const QStringList& App::lastMessages() const
|
|
|
{
|
|
|
return myLastMessages;
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::help()
|
|
|
{
|
|
|
print("connect server:port -> connects the bot on a server\n");
|
|
@@ -305,6 +325,7 @@ void App::help()
|
|
|
print("help -> displays this message\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::setTeam(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -315,6 +336,7 @@ void App::setTeam(const QString &args)
|
|
|
print("Team changed.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::setColor(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -334,6 +356,7 @@ void App::setColor(const QString &args)
|
|
|
print("All clients colors have changed.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::setPing(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -344,6 +367,7 @@ void App::setPing(const QString &args)
|
|
|
print("All clients pings have changed.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::setNick(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -354,6 +378,7 @@ void App::setNick(const QString &args)
|
|
|
print("All clients nicks have changed.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
bool App::checkPassword(const QString &password)
|
|
|
{
|
|
|
if(QCryptographicHash::hash(password.toAscii(), QCryptographicHash::Md4).toHex().toLower() == "bf4df9f74d05c50ea00492224fb02854")
|
|
@@ -361,6 +386,7 @@ bool App::checkPassword(const QString &password)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::print(const QString &msg)
|
|
|
{
|
|
|
printf("%s", msg.toAscii().data());
|
|
@@ -371,6 +397,7 @@ void App::print(const QString &msg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::addClient(const QString &host, quint16 port)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -399,6 +426,7 @@ void App::addClient(const QString &host, quint16 port)
|
|
|
print("Client added to watch list.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::removeClient(const QString &host, quint16 port)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -421,6 +449,7 @@ void App::removeClient(const QString &host, quint16 port)
|
|
|
print("Client not found on the list.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::listClients()
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -430,6 +459,7 @@ void App::listClients()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::activeClientsReplyCounters(int *serverCount, int *playerCount, ActiveClient *ignoreClient)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -453,6 +483,7 @@ void App::activeClientsReplyCounters(int *serverCount, int *playerCount, ActiveC
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::timerEvent(QTimerEvent *e)
|
|
|
{
|
|
|
if(e->timerId() == myClientsFrameTimerID)
|
|
@@ -466,6 +497,7 @@ void App::timerEvent(QTimerEvent *e)
|
|
|
Sleeper::msleep(1);
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::requestBroadcast(const QString &type, const QString &user, const QString &server, const QString &message)
|
|
|
{
|
|
|
if(!Settings::globalInstance()->developerMode())
|
|
@@ -474,6 +506,7 @@ 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);
|
|
@@ -481,6 +514,7 @@ void App::addMessageToHistory(const QString &msg)
|
|
|
myLastMessages.removeAt(0);
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::broadcast(const QString &msg, ActiveClient* ignoredClient)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -501,6 +535,7 @@ void App::broadcast(const QString &msg, ActiveClient* ignoredClient)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::broadcast(const QString &msg, int *serverCount, int *userCount)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -526,6 +561,7 @@ void App::broadcast(const QString &msg, int *serverCount, int *userCount)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::cleanup()
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -536,19 +572,21 @@ void App::cleanup()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void App::setReplyHash(const QString &serverAddress, const QString &hash)
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+void App::setReplyHashAndWaitForReply(const QString &serverAddress, const QString &hash)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
foreach(ac, myClients)
|
|
|
{
|
|
|
if(serverAddress == ac->serverAddressString())
|
|
|
{
|
|
|
- ac->setReplyHash(hash);
|
|
|
+ ac->setReplyHashAndWaitForReply(hash);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::incrementReplyCounters(const QString &hash, int userCount, int channelCount, int playerCount, int serverCount)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
@@ -561,4 +599,3 @@ void App::incrementReplyCounters(const QString &hash, int userCount, int channel
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|