From 00a8804ab8cc0bfd7b67a3c947f5d0de0eb958dc Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Thu, 29 Oct 2015 15:29:08 +0100 Subject: Add 5 minute hosting timeout on a failure while registering a game at the masterserver --- src/crsm.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/crsm.hpp | 5 +++++ 2 files changed, 72 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/crsm.cpp b/src/crsm.cpp index ac2ea04..c1fa131 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -278,10 +278,37 @@ void CRSM::readServerOutput() { Session.CountDown = -1; } + + static QRegExp gameRegisterFailExp(R"(^(?:Spiel konnte nicht registriert werden|Could not register game): (.*))"); + if(gameRegisterFailExp.exactMatch(what)) + { + QString reason = gameRegisterFailExp.cap(1); + userlist.clear(); + if(autoHost && !hostingIsErrorDeactivated) + { + hostingIsErrorDeactivated = true; + gameRegisterFailTimer.singleShot(5*60*1000, this, SLOT(enableAutoHosting())); + } + 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) + { + connection->sendCommand(IrcCommand::createMessage(Config.IRC.Channel, gameRegisterFailMessage.arg(reason))); + if(Config.IRC.UseIngameChat) + { + connection->sendCommand(IrcCommand::createMessage(Config.IRC.IngameChannel, gameRegisterFailMessage.arg(reason))); + } + } + } } void CRSM::nextScen() { + if(hostingIsErrorDeactivated) + { + return; + } if(userlist.length()>0) { startScen(userlist.at(0), args); @@ -1351,6 +1378,7 @@ void CRSM::setupCmds() addCommandGroup("packs", Management, UserType::Max, "Über die packs-Befehlsgruppe lassen sich mehrere Versionen eines Objektpakets für unterschiedliche Szenarien verwalten."); addCommand("packs list", &CRSM::packsList, Management, UserType::Max, "Listet alle bekannten Packs und ihre Versionen auf."); + addCommand("packs directory", &CRSM::packsDirectory, Management, UserType::Max, "Fragt den aktuellen Unterordner für Packversionen ab, bzw. setzt ihn auf .", "[Directory]"); addCommandGroup("packs versions", Management, UserType::Max, "Über die packs versions-Befehlsgruppe werden die einzelnen bekannten Packs und vorhandenen Versionen verwaltet."); addCommand("packs versions add", &CRSM::packsVersionsAdd, Management, UserType::Max, "Fügt eine neue für das hinzu.", " = "); addCommand("packs versions delete", &CRSM::packsVersionsDelete, Management, UserType::Max, "Löscht eine .", ""); @@ -1557,6 +1585,18 @@ void CRSM::reconnectIrc() prepareAndConnectIrc(); } +void CRSM::enableAutoHosting() +{ + gameRegisterFailTimer.stop(); + hostingIsErrorDeactivated = false; + + autoHost = true; + if(Session.State == CRSMSession::None) + { + nextScen(); + } +} + ClientInfo &CRSM::getClientInfo(const QString &pcName, int cuid, const QString &user) { if(!Session.Clonk.Clients.contains(pcName)) @@ -1812,7 +1852,12 @@ CMD_FUNCTION_IMPL(admin) } CMD_FUNCTION_IMPL(host) - if(userlist.length() >= Config.Hosting.UserListLength) + if(hostingIsErrorDeactivated) + { + respond(client, "Hosting ist aufgrund eines Problems temporär deaktiviert.\n"); + return Success; + } + else if(userlist.length() >= Config.Hosting.UserListLength) respond(client, "Maximale Warteschlangenlänge von " + QString::number(Config.Hosting.UserListLength) + " erreicht!\n"); else { @@ -1887,16 +1932,13 @@ CMD_FUNCTION_IMPL(ircchat) CMD_FUNCTION_IMPL(autohost) if(cmd == "autohost") { - autoHost = true; respond(client, "Automatisches Hosting aktiviert.\n"); - if(Session.State == CRSMSession::None) - { - nextScen(); - } + enableAutoHosting(); } else if(cmd == "noautohost") { autoHost = false; + gameRegisterFailTimer.stop(); respond(client, "Automatisches Hosting deaktiviert.\n"); } return Success; @@ -2420,6 +2462,25 @@ CMD_FUNCTION_IMPL(packsList) return Success; } +CMD_FUNCTION_IMPL(packsDirectory) + if(args.isEmpty()) + { + respond(client, "Das aktuelle PacksDirectory ist \"" + Packs.PacksDirectory + "\".\n"); + return Success; + } + else + { + Packs.PacksDirectory = args; + QString response = Packs.applyConfig(); + if(response.isEmpty()) + { + response = "Das PackDirectory wurde erfolgreich geändert.\n"; + } + respond(client, response); + return Success; + } +} + CMD_FUNCTION_IMPL(packsVersionsAdd) const QStringList& argList = Util::splitEscaped(args, '='); if(argList.length() != 2) diff --git a/src/crsm.hpp b/src/crsm.hpp index 7c3c34f..18a3b7c 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "CmdFunctionRef.hpp" #include "ProcessManager.hpp" @@ -136,6 +137,7 @@ private slots: void updateNextAutoScens(); void reconnectIrc(); + void enableAutoHosting(); private: CRSMConfig Config; @@ -221,8 +223,10 @@ private: ProcessManager* processManager = nullptr; QTcpServer managementServer; QMap managementConnections; + QTimer gameRegisterFailTimer; bool ok = false; + bool hostingIsErrorDeactivated = false; void startScen(const ScenarioSettings& scen, QStringList); void readConfig(); @@ -333,6 +337,7 @@ private: CMD_FUNCTION(ircWatch); CMD_FUNCTION(packsList); + CMD_FUNCTION(packsDirectory); CMD_FUNCTION(packsVersionsAdd); CMD_FUNCTION(packsVersionsDelete); CMD_FUNCTION(packsVersionsDefault); -- cgit v1.2.3-54-g00ecf