|
@@ -77,7 +77,7 @@ App::App(int &argc, char **argv) :
|
|
|
|
|
|
print("Connecting to central...\n");
|
|
|
connect(mySshClient, SIGNAL(connected()), SLOT(onCentralConnection()));
|
|
|
- mySshClient->connectToHost(Settings::globalInstance()->sshUserName(), Settings::globalInstance()->sshHostName());
|
|
|
+ mySshClient->connectToHost(Settings::globalInstance()->sshUserName(), Settings::globalInstance()->sshHostName(), Settings::globalInstance()->sshPort());
|
|
|
|
|
|
Settings::globalInstance()->save();
|
|
|
}
|
|
@@ -124,33 +124,6 @@ bool App::parseCommandLine()
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-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;
|
|
|
- }
|
|
|
-
|
|
|
- mySocket = myServer->nextPendingConnection();
|
|
|
- mySocketConnectedFlag = true;
|
|
|
- connect(mySocket, SIGNAL(readyRead()), SLOT(onDataArrival()));
|
|
|
- connect(mySocket, SIGNAL(disconnected()), SLOT(onDisconnection()));
|
|
|
-
|
|
|
- print("Connected to CIMS's bot service.\n");
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::onDisconnection()
|
|
|
-{
|
|
|
- mySocketConnectedFlag = false;
|
|
|
- mySocket->deleteLater();
|
|
|
-}
|
|
|
-
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void App::loadServerList()
|
|
|
{
|
|
@@ -159,6 +132,11 @@ void App::loadServerList()
|
|
|
|
|
|
foreach(sv, list)
|
|
|
{
|
|
|
+ if(myClients.size() == Settings::globalInstance()->maxServers())
|
|
|
+ {
|
|
|
+ print("Maximum number of servers allowed reached, some servers weren't added to the monitoring list.\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
ActiveClient* ac = new ActiveClient(this, sv.supportsSendPrivate);
|
|
|
ac->setAddress(QHostAddress(sv.address), sv.port);
|
|
|
ac->client()->setQuakeFolder(Settings::globalInstance()->quakeFolder().toAscii().data());
|
|
@@ -166,7 +144,6 @@ void App::loadServerList()
|
|
|
ac->client()->setSpectator(Settings::globalInstance()->botSpectator());
|
|
|
ac->client()->setPing(Settings::globalInstance()->botPing());
|
|
|
ac->client()->setColor(Settings::globalInstance()->botTopColor(), Settings::globalInstance()->botBottomColor());
|
|
|
-
|
|
|
myClients.push_back(ac);
|
|
|
}
|
|
|
}
|
|
@@ -188,148 +165,6 @@ void App::saveServerList()
|
|
|
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;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-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;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-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();
|
|
|
-
|
|
|
- if(cmd == "add")
|
|
|
- {
|
|
|
- parseAddClientCommand(args);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(cmd == "remove")
|
|
|
- {
|
|
|
- parseRemoveClientCommand(args);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
const QStringList& App::lastMessages() const
|
|
|
{
|
|
@@ -337,107 +172,45 @@ 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");
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::setTeam(const QString &args)
|
|
|
-{
|
|
|
- ActiveClient* ac;
|
|
|
- foreach(ac, myClients)
|
|
|
- {
|
|
|
- ac->client()->setTeam(args);
|
|
|
- }
|
|
|
- print("Team changed.\n");
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::setColor(const QString &args)
|
|
|
+void App::print(const QString &msg)
|
|
|
{
|
|
|
- ActiveClient* ac;
|
|
|
- quint8 bottom, top;
|
|
|
- QStringList colors = args.split(" ");
|
|
|
-
|
|
|
- if(colors.size() < 2)
|
|
|
- return;
|
|
|
-
|
|
|
- bottom = colors.at(0).toUShort();
|
|
|
- top = colors.at(1).toUShort();
|
|
|
-
|
|
|
- foreach(ac, myClients)
|
|
|
+ printf("%s", msg.toAscii().data());
|
|
|
+ if(mySocketConnectedFlag)
|
|
|
{
|
|
|
- ac->client()->setColor(bottom, top);
|
|
|
+ mySocket->write(msg.toAscii());
|
|
|
+ mySocket->waitForBytesWritten();
|
|
|
}
|
|
|
- print("All clients colors have changed.\n");
|
|
|
}
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::setPing(const QString &args)
|
|
|
+bool App::hasSendPrivateSupport(const QString &serverAddress) const
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
- foreach(ac, myClients)
|
|
|
- {
|
|
|
- ac->client()->setPing(args.toInt());
|
|
|
- }
|
|
|
- print("All clients pings have changed.\n");
|
|
|
-}
|
|
|
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::setNick(const QString &args)
|
|
|
-{
|
|
|
- ActiveClient* ac;
|
|
|
foreach(ac, myClients)
|
|
|
{
|
|
|
- ac->client()->setName(args.toAscii().data());
|
|
|
+ if(ac->serverAddressString() == serverAddress)
|
|
|
+ return ac->client()->supportsSendPrivate();
|
|
|
}
|
|
|
- print("All clients nicks have changed.\n");
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-bool App::checkPassword(const QString &password)
|
|
|
-{
|
|
|
- if(QCryptographicHash::hash(password.toAscii(), QCryptographicHash::Md4).toHex().toLower() == "bf4df9f74d05c50ea00492224fb02854")
|
|
|
- return false; //telnet adm disabled!!
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::print(const QString &msg)
|
|
|
-{
|
|
|
- printf("%s", msg.toAscii().data());
|
|
|
- if(mySocketConnectedFlag)
|
|
|
- {
|
|
|
- mySocket->write(msg.toAscii());
|
|
|
- mySocket->waitForBytesWritten();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::addClient(const QString &host, quint16 port)
|
|
|
+bool App::addClient(const QString &host, quint16 port, bool sendPrivateSupport)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
- QHostAddress ha = QHostInfo::fromName(host).addresses().at(0);
|
|
|
+ QHostAddress ha(host);
|
|
|
|
|
|
foreach(ac, myClients)
|
|
|
{
|
|
|
if(QString(ac->client()->host()) == ha.toString() && ac->client()->port() == port)
|
|
|
{
|
|
|
print("That client is already on the list.\n");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ac = new ActiveClient(this, this);
|
|
|
+ ac = new ActiveClient(this, sendPrivateSupport, this);
|
|
|
ac->setAddress(ha, port);
|
|
|
ac->client()->setQuakeFolder(Settings::globalInstance()->quakeFolder().toAscii().data());
|
|
|
ac->client()->setName(Settings::globalInstance()->botName().toAscii().data());
|
|
@@ -449,10 +222,12 @@ void App::addClient(const QString &host, quint16 port)
|
|
|
saveServerList();
|
|
|
|
|
|
print("Client added to watch list.\n");
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::removeClient(const QString &host, quint16 port)
|
|
|
+bool App::removeClient(const QString &host, quint16 port)
|
|
|
{
|
|
|
ActiveClient* ac;
|
|
|
QHostAddress ha = QHostInfo::fromName(host).addresses().at(0);
|
|
@@ -468,20 +243,11 @@ void App::removeClient(const QString &host, quint16 port)
|
|
|
saveServerList();
|
|
|
|
|
|
print("Client removed from watch list.\n");
|
|
|
- return;
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
print("Client not found on the list.\n");
|
|
|
-}
|
|
|
-
|
|
|
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-void App::listClients()
|
|
|
-{
|
|
|
- ActiveClient* ac;
|
|
|
- foreach(ac, myClients)
|
|
|
- {
|
|
|
- print(QString(ac->serverAddressString() + '\n'));
|
|
|
- }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|