|
@@ -56,7 +56,7 @@ App::App(int &argc, char **argv) :
|
|
|
QCoreApplication(argc, argv),
|
|
|
myServer(new QTcpServer()),
|
|
|
mySocketConnectedFlag(false),
|
|
|
- myQWNETSshClient(new SshClient(this))
|
|
|
+ mySshClient(new SshClient(this))
|
|
|
{
|
|
|
if(!parseCommandLine())
|
|
|
{
|
|
@@ -64,19 +64,21 @@ App::App(int &argc, char **argv) :
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- print("CIMS Bot Service v0.101\n========================================================\n");
|
|
|
+ print("CIMS Bot Service v0.12\n========================================================\n");
|
|
|
|
|
|
setApplicationName("CIMSBOT");
|
|
|
setOrganizationDomain("http://redmine.b4r.org/projects/cimsqwbot/");
|
|
|
setOrganizationName("CIMS");
|
|
|
- setApplicationVersion("0.101");
|
|
|
+ setApplicationVersion("0.12");
|
|
|
|
|
|
myClientsFrameTimerID = startTimer(0);
|
|
|
|
|
|
- myQWNETSshClient->connectToHost(Settings::globalInstance()->sshUserName(), Settings::globalInstance()->sshHostName());
|
|
|
-
|
|
|
loadServerList();
|
|
|
|
|
|
+ print("Connecting to central...\n");
|
|
|
+ connect(mySshClient, SIGNAL(connected()), SLOT(onCentralConnection()));
|
|
|
+ mySshClient->connectToHost(Settings::globalInstance()->sshUserName(), Settings::globalInstance()->sshHostName());
|
|
|
+
|
|
|
Settings::globalInstance()->save();
|
|
|
}
|
|
|
|
|
@@ -337,15 +339,15 @@ 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");
|
|
|
}
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
@@ -516,6 +518,18 @@ void App::timerEvent(QTimerEvent *e)
|
|
|
{
|
|
|
ac->run();
|
|
|
}
|
|
|
+
|
|
|
+ // HostNames scheduled daily refresh
|
|
|
+ int currentHour = QTime::currentTime().hour();
|
|
|
+ if(currentHour == 21 && !myHostNamesRequested)
|
|
|
+ {
|
|
|
+ requestCachedHostNames();
|
|
|
+ myHostNamesRequested = true;
|
|
|
+ }
|
|
|
+ else if(currentHour != 21 && myHostNamesRequested)
|
|
|
+ {
|
|
|
+ myHostNamesRequested = false;
|
|
|
+ }
|
|
|
}
|
|
|
Sleeper::msleep(1);
|
|
|
}
|
|
@@ -524,9 +538,9 @@ void App::timerEvent(QTimerEvent *e)
|
|
|
void App::requestBroadcast(const QString &type, const QString &user, const QString &server, const QString &message)
|
|
|
{
|
|
|
if(!Settings::globalInstance()->developerMode())
|
|
|
- myQWNETSshClient->write("REQ_BC QWalt,-" + type + "-,qw://" + server + ",'" + user + "','" + message + "'\n");
|
|
|
+ mySshClient->write("REQ_BC QWalt,-" + type + "-,qw://" + server + ",'" + user + "','" + message + "'\n");
|
|
|
else
|
|
|
- myQWNETSshClient->write("REQ_BC QDEV,-dev-,qw://" + server + ",'" + user + "','" + message + "'\n");
|
|
|
+ mySshClient->write("REQ_BC QDEV,-dev-,qw://" + server + ",'" + user + "','" + message + "'\n");
|
|
|
}
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
@@ -622,3 +636,47 @@ void App::incrementReplyCounters(const QString &hash, int userCount, int channel
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+void App::requestCachedHostNames() const
|
|
|
+{
|
|
|
+ ActiveClient* ac;
|
|
|
+ foreach(ac, myClients)
|
|
|
+ mySshClient->write("REQ_DNS " + ac->serverAddressString() + "\n");
|
|
|
+}
|
|
|
+
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+void App::setServerHostName(const QString &serverAddress, const QString &hostName)
|
|
|
+{
|
|
|
+ ActiveClient* ac;
|
|
|
+ foreach(ac, myClients)
|
|
|
+ {
|
|
|
+ if(ac->serverAddressString() == serverAddress)
|
|
|
+ {
|
|
|
+ qDebug() << serverAddress << hostName;
|
|
|
+ ac->setHostName(hostName);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+QString App::serverHostName(const QString &serverAddress) const
|
|
|
+{
|
|
|
+ ActiveClient* ac;
|
|
|
+ foreach(ac, myClients)
|
|
|
+ {
|
|
|
+ if(ac->serverAddressString() == serverAddress)
|
|
|
+ {
|
|
|
+ return ac->hostName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return QString();
|
|
|
+}
|
|
|
+
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+void App::onCentralConnection()
|
|
|
+{
|
|
|
+ print("Connected!\nRefreshing cached hostnames...\n");
|
|
|
+ requestCachedHostNames();
|
|
|
+}
|