summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2015-04-01 13:42:20 +0200
committerMarkus Mittendrein <git@maxmitti.tk>2015-04-01 13:42:20 +0200
commit282ca19b2e72c3c9d66caed3421318aabcaed192 (patch)
treed52e10874ea7e4e305d9ee1d71650bd7e8d8d7bd
parent0e0593acc8509b82425d91d2607c12871f03f786 (diff)
downloadmanager-282ca19b2e72c3c9d66caed3421318aabcaed192.tar.gz
manager-282ca19b2e72c3c9d66caed3421318aabcaed192.zip
Code cleanup, added idle protection (configurable), when last user
leaves.
-rw-r--r--crsm.cpp61
-rw-r--r--crsm.hpp3
2 files changed, 43 insertions, 21 deletions
diff --git a/crsm.cpp b/crsm.cpp
index af05fc0..7e31467 100644
--- a/crsm.cpp
+++ b/crsm.cpp
@@ -32,7 +32,6 @@ CRSM::CRSM(QObject *parent) :
connect(&managementServer, SIGNAL(newConnection()), this, SLOT(newManagementConnection()));
managementServer.listen(QHostAddress::LocalHostIPv6, settings["ManagementPort"].toUInt());
- //cleanUp();
listC4Folders();
readScenarios();
@@ -59,7 +58,7 @@ CRSM::CRSM(QObject *parent) :
if(processManager->isRunning())
{
- writeToServer("Server Manager läuft wieder.\n");
+ writeToServer("Server Manager läuft wieder.\nBis zur nächsten Runde könnte unerwartetes Verhalten auftreten.\n");
}
setupCmds();
@@ -125,7 +124,7 @@ bool CRSM::isOk()
void CRSM::readServerOutput()
{
- QRegExp timeRemover("^>?\\s*\\[\\d\\d:\\d\\d:\\d\\d\\]\\s+(.*)$");
+ static QRegExp timeRemover("^>?\\s*\\[\\d\\d:\\d\\d:\\d\\d\\]\\s+(.*)$");
QString what(processManager->readLine());
if(settings["ServerUsesReadline"] == "true")
@@ -158,13 +157,13 @@ void CRSM::readServerOutput()
return;
what = timeRemover.cap(1).trimmed();
- QRegExp userexp("^\\s*<(.*)\\|(\\d+)\\|([^>]*)>\\s+(.*)$");
+ static QRegExp userexp("^\\s*<(.*)\\|(\\d+)\\|([^>]*)>\\s+(.*)$");
if(userexp.exactMatch(what))
{
QString user = userexp.cap(3);
QString pcName = userexp.cap(1);
//QString cuid = userexp.cap(2);
- ClientInfo& info = clients[pcName];
+ const ClientInfo& info = clients.value(pcName);
if(user != settings["ServerNick"])
{
QString msg = userexp.cap(4).trimmed();
@@ -185,10 +184,10 @@ void CRSM::readServerOutput()
}
}
}
- QRegExp joinExp("^Client (.+) (?:verbunden|connected)\\.\\s*$");
+ static QRegExp joinExp("^Client (.+) (?:verbunden|connected)\\.\\s*$");
if(joinExp.exactMatch(what))
{
- QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$");
+ static QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$");
if(infoMatch.exactMatch(joinExp.cap(1)))
{
ClientInfo info;
@@ -203,10 +202,10 @@ void CRSM::readServerOutput()
greetMapper.setMapping(timer, info.pcName);
timer->start(500);
}
- ++clientcount;
}
- joinExp = QRegExp("^Client (.+) (?:aktiviert|activated)\\.\\s*$");
+ static QRegExp activatedExp("^Client (.+) (?:aktiviert|activated)\\.\\s*$");
+ if(activatedExp.exactMatch(what))
{
QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$");
if(infoMatch.exactMatch(joinExp.cap(1)))
@@ -216,7 +215,8 @@ void CRSM::readServerOutput()
}
}
- joinExp = QRegExp("^Client (.+) (?:deaktiviert|deactivated)\\.\\s*$");
+ static QRegExp deactivatedExp("^Client (.+) (?:deaktiviert|deactivated)\\.\\s*$");
+ if(deactivatedExp.exactMatch(what))
{
QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$");
if(infoMatch.exactMatch(joinExp.cap(1)))
@@ -226,7 +226,7 @@ void CRSM::readServerOutput()
}
}
- QRegExp startExp("^Start!\\s*$");
+ static QRegExp startExp("^Start!\\s*$");
if(startExp.exactMatch(what))
{
if(session["league"] != "true")
@@ -237,7 +237,7 @@ void CRSM::readServerOutput()
}
- QRegExp leaveExp("^Client (.+) (?:entfernt|removed)(.*)");
+ static QRegExp leaveExp("^Client (.+) (?:entfernt|removed)(.*)");
if(leaveExp.exactMatch(what))
{
QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$");
@@ -247,10 +247,26 @@ void CRSM::readServerOutput()
writeToServer(QString(info.nick +" ist ein L34V0R!\n"));
clients.remove(info.pcName);
}
- if(--clientcount == 0 && userlist.length() > 0 && session["userwish"] != "true")
+ if(clients.size() == 0 && userlist.length() > 0 && session["userwish"] != "true")
{
processManager->closeProgFifos();
}
+ else if(clients.size() == 0 && settings["EmptyTimer"] != "-1" && (session["CountDown"] == "false" || session["CountDown"].toInt() > settings["EmptyTimer"].toInt()))
+ {
+ writeToServer("/start " + settings["EmptyTimer"] + "\n");
+ }
+ }
+
+ static QRegExp countDownExp("^(?:Das Spiel beginnt in (\\d+) Sekunden\\!|The game will start in (\\d+) seconds\\.)");
+ if(countDownExp.exactMatch(what))
+ {
+ session["CountDown"] = countDownExp.cap(1);
+ }
+
+ static QRegExp countDownStopExp("^(?:Spielstart abgebrochen\\.|Game start aborted\\.)");
+ if(countDownStopExp.exactMatch(what))
+ {
+ session["CountDown"] = "false";
}
}
@@ -376,7 +392,6 @@ void CRSM::scenarioFinished()
ircAdmin = ClientInfo();
clients.clear();
greeted.clear();
- clientcount = 0;
if((autoHost || userlist.length() > 0) && !finish)
nextScen();
else if(!settings["IrcIngameChannel"].isEmpty())
@@ -520,7 +535,7 @@ void CRSM::greet(QString pcName)
{
if(!clients.contains(pcName))
return;
- ClientInfo &info = clients[pcName];
+ const ClientInfo &info = clients.value(pcName);
writeToServer(QString("Hallo " + info.nick + "!\n"));
}
@@ -635,6 +650,7 @@ void CRSM::startScen(const ScenarioSettings &scen, QStringList argList)
void CRSM::readConfig()
{
+ settings["EmptyTimer"] = "60";
QFile config(CONFIG_FILE_NAME);
if(!config.exists() || !config.open(QIODevice::ReadOnly | QIODevice::Text))
{
@@ -1214,6 +1230,8 @@ bool CRSM::cmd(const QString &name, const QString &args, const ClientInfo &clien
case Management:
(this->*cmdRef.func)(name, args, client, UserType::Max);
break;
+ case Auto: //just to avoid the compiler warning, there can't be a command from this interface
+ break;
}
return true;
@@ -1243,6 +1261,10 @@ UserType CRSM::clientUserType(const ClientInfo &client)
return Moderator;
if(ircAdmin == client)
return Admin;
+ case Management:
+ return Max;
+ case Auto: //just to avoid the compiler warning
+ break;
}
return User;
@@ -1264,7 +1286,7 @@ void CRSM::setupCmds()
addCommand("ingamechat", &CRSM::ircchat, IRC | Management, Admin, "Schaltet den Irc-Ingame-Chat ein bzw. aus.", "<on¦off>");
}
addCommand("queue", &CRSM::queue, Clonk | IRC | Management, User, "Zeigt die nächsten " + settings["UserListLength"] + " Szenarien auf der Warteliste.");
- addCommand("host", &CRSM::host, Clonk | IRC | Management, User, "Nimmt das angegebene Szenario in die Wunschliste auf. Optional in der Liga, wenn \"--league\" angegeben wird.", "[--league] <Szenarioname¦Alias>");
+ addCommand("host", &CRSM::host, Clonk | IRC | Management, User, "Nimmt das angegebene Szenario in die Warteschlange auf. Optional in der Liga, wenn \"--league\" angegeben wird.", "[--league] <Szenarioname¦Alias>");
addCommand("list", &CRSM::list, Clonk | IRC | Management, User, "Listet alle definierten Aliase oder alle möglichen Szenarien und Ordner auf, bzw. alle Szenarien im Ordner oder Rundenordner.", "[Aliase¦Rundenordner[.c4f]]");
addCommand("clientlist", &CRSM::clientlist, IRC | Management, User, "Listet alle verbundenen Clients mit PC-Name und Chatnick auf.");
addCommand("help", &CRSM::help, Clonk | IRC | Management, User, "Zeigt die Hilfe an.", "[long¦Befehlsname]", "Listet alle verfügbaren Befehle auf. Mit long werden alle verfügbaren Befehle mit Kurzbeschreibung aufgelistet.");
@@ -1337,6 +1359,8 @@ void CRSM::respond(const ClientInfo &client, const QString &message, const Respo
case Management:
client.management.socket->write(message.toUtf8());
break;
+ case Auto: //just to avoid the compiler warning
+ break;
}
}
@@ -1538,9 +1562,9 @@ CMD_FUNCTION_IMPL(host)
{
userlist << scen;
respond(client, "Szenario " + scen.name + " wurde der Warteschlange" + (scen.league ? " mit Liga" : "") + " hinzugefügt.\n");
- if(userlist.length() == 1 && session["userwish"] != "true" && session["running"] != "true" && session["hosting"] == "true")
+ if(userlist.length() == 1 && session["userwish"] != "true" && session["running"] != "true" && session["hosting"] == "true" && clients.size() > 0)
respond(client, "Überrede alle Spieler zu leaven und dein Wunsch wird sofort gehostet ;-)\n");
- else if(session["hosting"] != "true")
+ else if(session["hosting"] != "true" && clients.size() == 0)
{
nextScen();
}
@@ -1923,6 +1947,7 @@ CMD_FUNCTION_IMPL(reload)
ircModIOList.clear();
ircStatusFifos.clear();
readConfig();
+ readScenarios();
out("Configuration reloaded.");
}
diff --git a/crsm.hpp b/crsm.hpp
index 0d15134..f76656a 100644
--- a/crsm.hpp
+++ b/crsm.hpp
@@ -86,7 +86,6 @@ signals:
private slots:
void readServerOutput();
- //void processError();
void readInput();
void nextScen();
void printAdditionalHelp();
@@ -100,7 +99,6 @@ private slots:
void managementConnectionDisconnected();
private:
- //QStringList scenlist;
QList<ScenarioSettings> userlist;
QList<ScenarioSettings> autolist;
QStringList args;
@@ -121,7 +119,6 @@ private:
QStringList greeted;
QMap<QString, QStringList> lists;
QMap<QString, QMap<QString, QString>> maps;
- int clientcount;
IrcConnection *connection = 0;
bool autoHost = true;
QSignalMapper greetMapper;