|
@@ -37,7 +37,7 @@ App::App(int &argc, char **argv) :
|
|
|
print("CIMS Bot Service v0.101\n========================================================\n");
|
|
|
|
|
|
setApplicationName("CIMSBOT");
|
|
|
- setOrganizationDomain("qwbr.tk");
|
|
|
+ setOrganizationDomain("qwbr.tk");
|
|
|
setOrganizationName("CIMS");
|
|
|
setApplicationVersion("0.101");
|
|
|
|
|
@@ -94,16 +94,16 @@ bool App::parseCommandLine()
|
|
|
|
|
|
void App::onNewConnection()
|
|
|
{
|
|
|
- if(mySocketConnectedFlag)
|
|
|
- {
|
|
|
- print("Someone just connected to the bot.\nBye Bye.\n");
|
|
|
- mySocket->disconnectFromHost();
|
|
|
- if(mySocket->state() != QTcpSocket::UnconnectedState)
|
|
|
- mySocket->waitForDisconnected();
|
|
|
- mySocketConnectedFlag = false;
|
|
|
+ if(mySocketConnectedFlag)
|
|
|
+ {
|
|
|
+ print("Someone just connected to the bot.\nBye Bye.\n");
|
|
|
+ mySocket->disconnectFromHost();
|
|
|
+ if(mySocket->state() != QTcpSocket::UnconnectedState)
|
|
|
+ mySocket->waitForDisconnected();
|
|
|
+ mySocketConnectedFlag = false;
|
|
|
}
|
|
|
|
|
|
- mySocket = myServer->nextPendingConnection();
|
|
|
+ mySocket = myServer->nextPendingConnection();
|
|
|
mySocketConnectedFlag = true;
|
|
|
connect(mySocket, SIGNAL(readyRead()), SLOT(onDataArrival()));
|
|
|
connect(mySocket, SIGNAL(disconnected()), SLOT(onDisconnection()));
|
|
@@ -113,8 +113,8 @@ void App::onNewConnection()
|
|
|
|
|
|
void App::onDisconnection()
|
|
|
{
|
|
|
- mySocketConnectedFlag = false;
|
|
|
- mySocket->deleteLater();
|
|
|
+ mySocketConnectedFlag = false;
|
|
|
+ mySocket->deleteLater();
|
|
|
}
|
|
|
|
|
|
void App::loadServerList()
|
|
@@ -143,148 +143,148 @@ void App::saveServerList()
|
|
|
ActiveClient* ac;
|
|
|
|
|
|
foreach(ac, myClients)
|
|
|
- list.push_back(ac->serverAddressString());
|
|
|
+ list.push_back(ac->serverAddressString());
|
|
|
|
|
|
Settings::globalInstance()->setServerList(list);
|
|
|
}
|
|
|
|
|
|
void App::parseAddClientCommand(const QString &args)
|
|
|
{
|
|
|
- if(!args.size())
|
|
|
- {
|
|
|
- print("No server specified\n");
|
|
|
- return;
|
|
|
- }
|
|
|
- if(args.contains(" "))
|
|
|
- {
|
|
|
- print("Invalid server address\n");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- QStringList clientData = args.split(":");
|
|
|
- if(clientData.size() == 1)
|
|
|
- {
|
|
|
- addClient(clientData.at(0), 27500);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(clientData.size() == 2)
|
|
|
- {
|
|
|
- addClient(clientData.at(0), clientData.at(1).toUShort());
|
|
|
- return;
|
|
|
- }
|
|
|
+ if(!args.size())
|
|
|
+ {
|
|
|
+ print("No server specified\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(args.contains(" "))
|
|
|
+ {
|
|
|
+ print("Invalid server address\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ QStringList clientData = args.split(":");
|
|
|
+ if(clientData.size() == 1)
|
|
|
+ {
|
|
|
+ addClient(clientData.at(0), 27500);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(clientData.size() == 2)
|
|
|
+ {
|
|
|
+ addClient(clientData.at(0), clientData.at(1).toUShort());
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void App::parseRemoveClientCommand(const QString &args)
|
|
|
{
|
|
|
- if(!args.size())
|
|
|
- {
|
|
|
- print("No server specified\n");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- QStringList clientData = args.split(":");
|
|
|
- if(clientData.size() == 1)
|
|
|
- {
|
|
|
- removeClient(clientData.at(0), 27500);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(clientData.size() == 2)
|
|
|
- {
|
|
|
- removeClient(clientData.at(0), clientData.at(1).toUShort());
|
|
|
- return;
|
|
|
- }
|
|
|
+ if(!args.size())
|
|
|
+ {
|
|
|
+ print("No server specified\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ QStringList clientData = args.split(":");
|
|
|
+ if(clientData.size() == 1)
|
|
|
+ {
|
|
|
+ removeClient(clientData.at(0), 27500);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(clientData.size() == 2)
|
|
|
+ {
|
|
|
+ removeClient(clientData.at(0), clientData.at(1).toUShort());
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void App::onDataArrival()
|
|
|
{
|
|
|
- while(mySocket->canReadLine())
|
|
|
- {
|
|
|
- QByteArray line;
|
|
|
-
|
|
|
- line = mySocket->readLine();
|
|
|
-
|
|
|
- QString data(line);
|
|
|
- QRegExp regex("([0-9a-zA-Z]+)\\s+([a-z]+)\\s+(.*)");
|
|
|
- if(regex.indexIn(data) == -1)
|
|
|
- {
|
|
|
- print("command format: <password> <command> ?<arguments>\nEg.: pss help\nDisconnected\n");
|
|
|
- mySocket->disconnectFromHost();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- QString pass = regex.capturedTexts().at(1);
|
|
|
- if(!checkPassword(pass))
|
|
|
- {
|
|
|
- print("Wrong password\nDisconnected\n");
|
|
|
- mySocket->disconnectFromHost();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- QString cmd = regex.capturedTexts().at(2);
|
|
|
- QString args = regex.capturedTexts().at(3).trimmed();
|
|
|
+ while(mySocket->canReadLine())
|
|
|
+ {
|
|
|
+ QByteArray line;
|
|
|
+
|
|
|
+ line = mySocket->readLine();
|
|
|
+
|
|
|
+ QString data(line);
|
|
|
+ QRegExp regex("([0-9a-zA-Z]+)\\s+([a-z]+)\\s+(.*)");
|
|
|
+ if(regex.indexIn(data) == -1)
|
|
|
+ {
|
|
|
+ print("command format: <password> <command> ?<arguments>\nEg.: pss help\nDisconnected\n");
|
|
|
+ mySocket->disconnectFromHost();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ QString pass = regex.capturedTexts().at(1);
|
|
|
+ if(!checkPassword(pass))
|
|
|
+ {
|
|
|
+ print("Wrong password\nDisconnected\n");
|
|
|
+ mySocket->disconnectFromHost();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ QString cmd = regex.capturedTexts().at(2);
|
|
|
+ QString args = regex.capturedTexts().at(3).trimmed();
|
|
|
|
|
|
if(cmd == "add")
|
|
|
- {
|
|
|
+ {
|
|
|
parseAddClientCommand(args);
|
|
|
- return;
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
if(cmd == "remove")
|
|
|
- {
|
|
|
+ {
|
|
|
parseRemoveClientCommand(args);
|
|
|
- return;
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if(cmd == "say")
|
|
|
- {
|
|
|
+ if(cmd == "say")
|
|
|
+ {
|
|
|
broadcast(args);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "servers")
|
|
|
- {
|
|
|
- listClients();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "name")
|
|
|
- {
|
|
|
- setNick(args);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "color")
|
|
|
- {
|
|
|
- setColor(args);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "setping")
|
|
|
- {
|
|
|
- setPing(args);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "team")
|
|
|
- {
|
|
|
- setTeam(args);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "quit")
|
|
|
- {
|
|
|
- mySocket->disconnectFromHost();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "help")
|
|
|
- {
|
|
|
- help();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cmd == "servers")
|
|
|
+ {
|
|
|
+ listClients();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cmd == "name")
|
|
|
+ {
|
|
|
+ setNick(args);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cmd == "color")
|
|
|
+ {
|
|
|
+ setColor(args);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cmd == "setping")
|
|
|
+ {
|
|
|
+ setPing(args);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cmd == "team")
|
|
|
+ {
|
|
|
+ setTeam(args);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cmd == "quit")
|
|
|
+ {
|
|
|
+ mySocket->disconnectFromHost();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cmd == "help")
|
|
|
+ {
|
|
|
+ help();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const QStringList& App::lastMessages() const
|
|
@@ -294,76 +294,76 @@ const QStringList& App::lastMessages() const
|
|
|
|
|
|
void App::help()
|
|
|
{
|
|
|
- print("connect server:port -> connects the bot on a server\n");
|
|
|
- print("disconnect server:port -> removes the bot from a server\n");
|
|
|
- print("say message -> says the message on all servers where the bot is connected\n");
|
|
|
- print("servers -> lists all servers the bot is connected\n");
|
|
|
- print("name nick -> changes the bot name to nick\n");
|
|
|
- print("color x x -> changes the player color\n");
|
|
|
- print("setping x -> sets the bot ping to x. ofc you can't lower your actual ping with this.\n");
|
|
|
- print("team teamname -> sets the bot team\n");
|
|
|
- print("help -> displays this message\n");
|
|
|
+ print("connect server:port -> connects the bot on a server\n");
|
|
|
+ print("disconnect server:port -> removes the bot from a server\n");
|
|
|
+ print("say message -> says the message on all servers where the bot is connected\n");
|
|
|
+ print("servers -> lists all servers the bot is connected\n");
|
|
|
+ print("name nick -> changes the bot name to nick\n");
|
|
|
+ print("color x x -> changes the player color\n");
|
|
|
+ print("setping x -> sets the bot ping to x. ofc you can't lower your actual ping with this.\n");
|
|
|
+ print("team teamname -> sets the bot team\n");
|
|
|
+ print("help -> displays this message\n");
|
|
|
}
|
|
|
|
|
|
void App::setTeam(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
ac->client()->setTeam(args);
|
|
|
- }
|
|
|
- print("Team changed.\n");
|
|
|
+ }
|
|
|
+ print("Team changed.\n");
|
|
|
}
|
|
|
|
|
|
void App::setColor(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
- quint8 bottom, top;
|
|
|
- QStringList colors = args.split(" ");
|
|
|
+ quint8 bottom, top;
|
|
|
+ QStringList colors = args.split(" ");
|
|
|
|
|
|
- if(colors.size() < 2)
|
|
|
- return;
|
|
|
+ if(colors.size() < 2)
|
|
|
+ return;
|
|
|
|
|
|
- bottom = colors.at(0).toUShort();
|
|
|
- top = colors.at(1).toUShort();
|
|
|
+ bottom = colors.at(0).toUShort();
|
|
|
+ top = colors.at(1).toUShort();
|
|
|
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
ac->client()->setColor(bottom, top);
|
|
|
- }
|
|
|
- print("All clients colors have changed.\n");
|
|
|
+ }
|
|
|
+ print("All clients colors have changed.\n");
|
|
|
}
|
|
|
|
|
|
void App::setPing(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
ac->client()->setPing(args.toInt());
|
|
|
- }
|
|
|
- print("All clients pings have changed.\n");
|
|
|
+ }
|
|
|
+ print("All clients pings have changed.\n");
|
|
|
}
|
|
|
|
|
|
void App::setNick(const QString &args)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
ac->client()->setName(args.toAscii().data());
|
|
|
- }
|
|
|
- print("All clients nicks have changed.\n");
|
|
|
+ }
|
|
|
+ print("All clients nicks have changed.\n");
|
|
|
}
|
|
|
|
|
|
bool App::checkPassword(const QString &password)
|
|
|
{
|
|
|
- if(QCryptographicHash::hash(password.toAscii(), QCryptographicHash::Md4).toHex().toLower() == "bf4df9f74d05c50ea00492224fb02854")
|
|
|
+ if(QCryptographicHash::hash(password.toAscii(), QCryptographicHash::Md4).toHex().toLower() == "bf4df9f74d05c50ea00492224fb02854")
|
|
|
return false; //telnet adm disabled!!
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
void App::print(const QString &msg)
|
|
|
{
|
|
|
- printf("%s", msg.toAscii().data());
|
|
|
+ printf("%s", msg.toAscii().data());
|
|
|
if(mySocketConnectedFlag)
|
|
|
{
|
|
|
mySocket->write(msg.toAscii());
|
|
@@ -374,16 +374,16 @@ void App::print(const QString &msg)
|
|
|
void App::addClient(const QString &host, quint16 port)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
- QHostAddress ha = QHostInfo::fromName(host).addresses().at(0);
|
|
|
+ QHostAddress ha = QHostInfo::fromName(host).addresses().at(0);
|
|
|
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
if(QString(ac->client()->host()) == ha.toString() && ac->client()->port() == port)
|
|
|
- {
|
|
|
- print("That client is already on the list.\n");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
+ {
|
|
|
+ print("That client is already on the list.\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
ac = new ActiveClient(this, this);
|
|
|
ac->setAddress(ha, port);
|
|
@@ -402,12 +402,12 @@ void App::addClient(const QString &host, quint16 port)
|
|
|
void App::removeClient(const QString &host, quint16 port)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
- QHostAddress ha = QHostInfo::fromName(host).addresses().at(0);
|
|
|
+ QHostAddress ha = QHostInfo::fromName(host).addresses().at(0);
|
|
|
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
if(ac->serverAddressString() == QString(ha.toString() + ':' + QString::number(port)))
|
|
|
- {
|
|
|
+ {
|
|
|
ac->client()->disconnect();
|
|
|
delete ac;
|
|
|
myClients.removeAll(ac);
|
|
@@ -415,19 +415,19 @@ void App::removeClient(const QString &host, quint16 port)
|
|
|
saveServerList();
|
|
|
|
|
|
print("Client removed from watch list.\n");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- print("Client not found on the list.\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ print("Client not found on the list.\n");
|
|
|
}
|
|
|
|
|
|
void App::listClients()
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
print(QString(ac->serverAddressString() + '\n'));
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void App::activeClientsReplyCounters(int *serverCount, int *playerCount, ActiveClient *ignoreClient)
|
|
@@ -455,14 +455,14 @@ void App::activeClientsReplyCounters(int *serverCount, int *playerCount, ActiveC
|
|
|
|
|
|
void App::timerEvent(QTimerEvent *e)
|
|
|
{
|
|
|
- if(e->timerId() == myClientsFrameTimerID)
|
|
|
- {
|
|
|
+ if(e->timerId() == myClientsFrameTimerID)
|
|
|
+ {
|
|
|
ActiveClient *ac;
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
ac->run();
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
Sleeper::msleep(1);
|
|
|
}
|
|
|
|
|
@@ -530,10 +530,10 @@ void App::cleanup()
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
foreach(ac, myClients)
|
|
|
- {
|
|
|
+ {
|
|
|
ac->client()->disconnect();
|
|
|
delete ac;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void App::setReplyHash(const QString &serverAddress, const QString &hash)
|