diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2016-12-29 23:10:12 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2016-12-29 23:10:37 +0100 |
| commit | 811b4654140d11d273f407b5728d4816de2125df (patch) | |
| tree | 99c61212553cd8de16989cb870fb6f80d0fd5509 /src | |
| parent | 538a0b2a6d3811dc7c9c17b8ecb00c14aea3294b (diff) | |
| download | manager-811b4654140d11d273f407b5728d4816de2125df.tar.gz manager-811b4654140d11d273f407b5728d4816de2125df.zip | |
Adapt to new Clonk output
Sound is now considered for flood checkt too
Diffstat (limited to 'src')
| -rw-r--r-- | src/crsm.cpp | 279 | ||||
| -rw-r--r-- | src/crsm.hpp | 1 |
2 files changed, 161 insertions, 119 deletions
diff --git a/src/crsm.cpp b/src/crsm.cpp index 21c502b..a5d052d 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -96,6 +96,58 @@ bool CRSM::isOk() return ok; } +ClientInfo* CRSM::parseClientInfo(QString& message) +{ + if(message.length() > 5 && message.at(0) == '\\') + { + QString parts[3]; + for(int i = 1, part = 0; i < message.length() && part < 3; ++i) + { + bool last = (i == message.length() -1); + QChar c = message.at(i); + QChar next = '\0'; + if(!last) + { + next = message.at(i + 1); + } + if(c == '\\') + { + if((last || next == ' ') && part == 2) + { + message = message.mid(i + 2); + + if(parts[0] == Config.Auto.Volatile.Clonk.ServerPCName) + { + return nullptr; + } + + int CUID = parts[1].toInt(); + ClientInfo* ret = &getClientInfo(parts[0], CUID, parts[2]); + ret->nick = parts[2]; + return ret; + } + else + { + if(next == '\\' || next == '"') + { + i += 2; + parts[part].append(next); + } + else + { + ++part; + } + } + } + else + { + parts[part].append(c); + } + } + } + return nullptr; +} + void CRSM::readServerOutput() { QString what(processManager->readLine().trimmed()); @@ -137,181 +189,170 @@ void CRSM::readServerOutput() Log.clonkLog(what); - static QRegExp userexp("^\\s*(\\*?)\\s*<(.*)\\|(\\d+)\\|([^>]*)>\\s+(.*)$"); - if(userexp.exactMatch(what)) + if(what.length() > 5 && what.midRef(3, 2) == ": ") { - Log.clonkChatLog(what); - bool isMeMessage = (userexp.cap(1) == "*"); - QString user = userexp.cap(4); - QString pcName = userexp.cap(2); - int cuid = userexp.cap(3).toInt(); - if(pcName != Config.Auto.Volatile.Clonk.ServerPCName) + const QString& type = what.left(3); + what = what.mid(5); + if(type == "Cnt") { - ClientInfo& info = getClientInfo(pcName, cuid, user); - Log.clonkUserLog(what, info, isMeMessage); - if(info == Session.Clonk.Admin) + Session.CountDown = what.toInt(); + return; + } + + ClientInfo* clientPtr = parseClientInfo(what); + if(clientPtr == nullptr) + { + return; + } + ClientInfo& client = *clientPtr; + + if(type == "Msg" || type == "Mac" || type == "Snd") + { + bool isMeMessage = (type == "Mac"); + if(type == "Snd") { - checkActivity(Session.Clonk.Admin); + Log.clonkChatLog("Sound: " + client.toString(true, true) + " " + what); } - QString msg = userexp.cap(5).trimmed(); - if(info.floodCheck(Config.Clonk.Chat.AntiFlood.Count, Config.Clonk.Chat.AntiFlood.Time, QDateTime(QDate::currentDate(), msgTime))) + else if(isMeMessage) { - kick(pcName, "Flooding! Maximal " + QString::number(Config.Clonk.Chat.AntiFlood.Count) + " Nachrichten in " + QString::number(Config.Clonk.Chat.AntiFlood.Time) + "s"); + Log.clonkChatLog("* " + client.toString(true, true) + " " + what); } - else if(!isMeMessage) + else + { + Log.clonkChatLog(client.toString(true, true) + " " + what); + } + + if(client.pcName != Config.Auto.Volatile.Clonk.ServerPCName) { - QString command = getCommand(msg); - if(!command.isEmpty()) + Log.clonkUserLog(what, client, isMeMessage); + if(client == Session.Clonk.Admin) { - if(!cmd(command, info)) + checkActivity(Session.Clonk.Admin); + } + if(client.floodCheck(Config.Clonk.Chat.AntiFlood.Count, Config.Clonk.Chat.AntiFlood.Time, QDateTime(QDate::currentDate(), msgTime))) + { + kick(client.pcName, "Flooding! Maximal " + QString::number(Config.Clonk.Chat.AntiFlood.Count) + " Nachrichten in " + QString::number(Config.Clonk.Chat.AntiFlood.Time) + "s"); + } + else if(type == "Snd") + { + return; + } + else if(!isMeMessage) + { + QString command = getCommand(what); + if(!command.isEmpty()) { - respond(info, "Unbekannter Befehl: \"" + command + "\"!\n"); - } + if(!cmd(command, client)) + { + respond(client, "Unbekannter Befehl: \"" + command + "\"!\n"); + } + } + else if(Session.IRC.UseIngameChat) + { + sendIrcMessage("[Clonk]<" + client.nick+ "> " + what, Config.IRC.IngameChannel, false, false); + } } else if(Session.IRC.UseIngameChat) { - sendIrcMessage("[Clonk]<" + user + "> " + msg, Config.IRC.IngameChannel, false, false); + sendIrcMessage("[Clonk] " + client.nick + " " + what, Config.IRC.IngameChannel, true, false); } } - else if(Session.IRC.UseIngameChat) - { - sendIrcMessage("[Clonk] " + user + " " + msg, Config.IRC.IngameChannel, true, false); - } } - } - static QRegExp joinExp("^Client (.+) (?:verbunden|connected)\\.\\s*$"); - if(joinExp.exactMatch(what)) - { - static QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$"); - if(infoMatch.exactMatch(joinExp.cap(1))) + else if(type == "Con") { - const ClientInfo& info = ClientInfo::clonkClient(infoMatch.cap(3), infoMatch.cap(1), infoMatch.cap(2).toInt()); - Session.Clonk.Clients.insert(info.pcName, info); QTimer *timer = new QTimer; connect(timer, SIGNAL(timeout()), &greetMapper, SLOT(map())); connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); - greetMapper.setMapping(timer, info.pcName); + greetMapper.setMapping(timer, client.pcName); timer->start(1000); if(Session.IRC.UseIngameChat) { - sendIrcMessage("[Clonk] " + info.toString() + " verbunden.", Config.IRC.IngameChannel, false, false); + sendIrcMessage("[Clonk] " + client.toString() + " verbunden.", Config.IRC.IngameChannel, false, false); } } - } - - static QRegExp activatedExp("^Client (.+) (?:aktiviert|activated)\\.\\s*$"); - if(activatedExp.exactMatch(what)) - { - QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$"); - if(infoMatch.exactMatch(activatedExp.cap(1))) - { - ClientInfo &info = getClientInfo(infoMatch.cap(1), infoMatch.cap(2).toInt(), infoMatch.cap(3)); - info.activated = true; - } - } - - static QRegExp deactivatedExp("^Client (.+) (?:deaktiviert|deactivated)\\.\\s*$"); - if(deactivatedExp.exactMatch(what)) - { - QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$"); - if(infoMatch.exactMatch(joinExp.cap(1))) - { - ClientInfo &info = getClientInfo(infoMatch.cap(1), infoMatch.cap(2).toInt(), infoMatch.cap(3)); - info.activated = false; - } - } - - static QRegExp lobbyStartExp(R"((?:Los geht's!|Action go!)\s*)"); - if(lobbyStartExp.exactMatch(what) && Session.State == CRSMSession::Lobby) - { - setSessionState(CRSMSession::Loading); - } - - static QRegExp startExp("^Start!\\s*$"); - if(startExp.exactMatch(what)) - { - setSessionState(CRSMSession::Running); - Stats.AddScenarioStart(Session.Scenario.wishClient, scenarioFileName(Session.Scenario.name)); - if(!Session.League) + else if(type == "Act" || type == "Dct") { - writeToServer(QString("/set maxplayer 0\n")); + client.activated = type == "Act"; } - } - - - static QRegExp leaveExp("^Client (.+) (?:entfernt|removed)(.*)"); - if(leaveExp.exactMatch(what)) - { - QRegExp infoMatch("^<(.*)\\|(\\d+)\\|(.*)>$"); - if(infoMatch.exactMatch(leaveExp.cap(1))) + else if(type == "Rem") { - ClientInfo &info = getClientInfo(infoMatch.cap(1), infoMatch.cap(2).toInt(), infoMatch.cap(3)); - writeToServer(QString(info.nick +" ist ein L34V0R!\n")); + writeToServer(QString(client.nick +" ist ein L34V0R!\n")); if(Session.IRC.UseIngameChat) { - sendIrcMessage("[Clonk] " + info.toString() + " entfernt" + leaveExp.cap(2), Config.IRC.IngameChannel, false, false); + sendIrcMessage("[Clonk] " + client.toString() + " entfernt (" + what + ").", Config.IRC.IngameChannel, false, false); } - if(info == Session.Clonk.Admin) + if(client == Session.Clonk.Admin) { - Session.Clonk.LeaveAdmins.insert(info, QDateTime::currentDateTime()); + Session.Clonk.LeaveAdmins.insert(client, QDateTime::currentDateTime()); afkAdminTimer.stop(); Session.AfkAdmin = false; writeToServer("Rundenadmin wurde freigegeben.\n"); Session.Clonk.Admin.clear(); } - Session.Clonk.Clients.remove(info.pcName); - } - if(Session.Clonk.Clients.size() == 0 && ((userlist.length() > 0 && !Session.UserWish) || (Session.State == CRSMSession::Running || Session.State == CRSMSession::Loading))) - { - processManager->closeProgFifos(); - } - else if(Session.Clonk.Clients.size() == 0 && Config.Clonk.Server.EmptyTimer != -1 && (Session.CountDown == -1 || Session.CountDown > Config.Clonk.Server.EmptyTimer)) - { - writeToServer("/start " + QString::number(Config.Clonk.Server.EmptyTimer) + "\n"); + Session.Clonk.Clients.remove(client.pcName); + + if(Session.Clonk.Clients.size() == 0 && ((userlist.length() > 0 && !Session.UserWish) || (Session.State == CRSMSession::Running || Session.State == CRSMSession::Loading))) + { + processManager->closeProgFifos(); + } + else if(Session.Clonk.Clients.size() == 0 && Config.Clonk.Server.EmptyTimer != -1 && (Session.CountDown == -1 || Session.CountDown > Config.Clonk.Server.EmptyTimer)) + { + writeToServer("/start " + QString::number(Config.Clonk.Server.EmptyTimer) + "\n"); + } } + return; } - static QRegExp countDownExp("^(?:Das Spiel beginnt in (\\d+) Sekunden\\!|The game will start in (\\d+) seconds\\.)"); - if(countDownExp.exactMatch(what)) + if((what == "Los geht's!" || what == "Action go!") && Session.State == CRSMSession::Lobby) { - Session.CountDown = countDownExp.cap(1).toInt(); + setSessionState(CRSMSession::Loading); + return; } - static QRegExp countDownExp2(R"(^(\d+)\.\.\.)"); - if(countDownExp2.exactMatch(what)) + + if(what == "Start!") { - Session.CountDown = countDownExp2.cap(1).toInt(); + Stats.AddScenarioStart(Session.Scenario.wishClient, scenarioFileName(Session.Scenario.name)); + if(!Session.League) + { + writeToServer(QString("/set maxplayer 0\n")); + } + setSessionState(CRSMSession::Running); + return; } - static QRegExp countDownStopExp("^(?:Spielstart abgebrochen\\.|Game start aborted\\.)"); - if(countDownStopExp.exactMatch(what)) + if(what == "Spielstart abgebrochen." || what == "Game start aborted.") { Session.CountDown = -1; + return; } - static QRegExp gameRegisterFailExp(R"(^(?:Spiel konnte nicht registriert werden|Could not register game): (.*))"); - if(gameRegisterFailExp.exactMatch(what)) + for(const QString& text : {"Spiel konnte nicht registriert werden: ", "Could not register game: ", "FATALER FEHLER: Liga konnte nicht initialisiert werden: ", "FATAL ERROR: Could not initialize league: "}) { - QString reason = gameRegisterFailExp.cap(1); - userlist.clear(); - if(autoHost && !hostingIsErrorDeactivated) + if(what.startsWith(text)) { - hostingIsErrorDeactivated = true; - gameRegisterFailTimer.start(); - } - autoHost = false; - static const QString gameRegisterFailMessage = "Aufgrund eines Problems beim Registrieren des Spiels am Masterserver (%1) wird Hosting temporär (für 5 Minuten) deaktiviert.\n"; - out(gameRegisterFailMessage.arg(reason)); - if(Config.IRC.Use) - { - sendIrcMessage(gameRegisterFailMessage.arg(reason), Config.IRC.Channel, false, false); - if(Config.IRC.UseIngameChat) + QString reason = what.mid(text.length()); + userlist.clear(); + if(autoHost && !hostingIsErrorDeactivated) + { + hostingIsErrorDeactivated = true; + gameRegisterFailTimer.start(); + } + autoHost = false; + static const QString gameRegisterFailMessage = "Aufgrund eines Problems beim Registrieren des Spiels am Masterserver (%1) wird Hosting temporär (für 5 Minuten) deaktiviert.\n"; + out(gameRegisterFailMessage.arg(reason)); + if(Config.IRC.Use) { - sendIrcMessage(gameRegisterFailMessage.arg(reason), Config.IRC.IngameChannel, false, false); + sendIrcMessage(gameRegisterFailMessage.arg(reason), Config.IRC.Channel, false, false); + if(Config.IRC.UseIngameChat) + { + sendIrcMessage(gameRegisterFailMessage.arg(reason), Config.IRC.IngameChannel, false, false); + } } + return; } } } diff --git a/src/crsm.hpp b/src/crsm.hpp index 0a1b1f4..a40e246 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -296,6 +296,7 @@ private: void prepareAndConnectIrc(); ClientInfo& getClientInfo(const QString& pcName, int cuid, const QString& user); + ClientInfo* parseClientInfo(QString& message); void exit(); |
