From 7e3a669af02d7dfd8eab461a3876fd7b062149c2 Mon Sep 17 00:00:00 2001 From: ebbit1q Date: Mon, 8 Mar 2021 18:18:22 +0100 Subject: [PATCH] use correct settings group for command interval settings (#4257) the settings command_counting_interval and max_command_count_per_interval are now in the [security] group as hinted by their location in servatrice.ini.example check values of comand interval settings before use --- common/server_protocolhandler.cpp | 16 +++++++++++----- servatrice/src/servatrice.cpp | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 96715d4e..9f8072ea 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -286,11 +286,13 @@ Response::ResponseCode Server_ProtocolHandler::processGameCommandContainer(const if (!antifloodCommandsWhiteList.contains((GameCommand::GameCommandType)getPbExtension(sc))) ++commandCountOverTime[0]; - for (int i = 0; i < commandCountOverTime.size(); ++i) + for (int i = 0; i < commandCountOverTime.size(); ++i) { totalCount += commandCountOverTime[i]; + } - if (totalCount > maxCommandCountPerInterval) + if (maxCommandCountPerInterval > 0 && totalCount > maxCommandCountPerInterval) { return Response::RespChatFlood; + } } Response::ResponseCode resp = player->processGameCommand(sc, rc, ges); @@ -733,12 +735,16 @@ Server_ProtocolHandler::cmdRoomSay(const Command_RoomSay &cmd, Server_Room *room if (messageCountOverTime.isEmpty()) messageCountOverTime.prepend(0); ++messageCountOverTime[0]; - for (int i = 0; i < messageCountOverTime.size(); ++i) + for (int i = 0; i < messageCountOverTime.size(); ++i) { totalCount += messageCountOverTime[i]; + } - if ((totalSize > server->getMaxMessageSizePerInterval()) || - (totalCount > server->getMaxMessageCountPerInterval())) + int maxMessageSizePerInterval = server->getMaxMessageSizePerInterval(); + int maxMessageCountPerInterval = server->getMaxMessageCountPerInterval(); + if ((maxMessageSizePerInterval > 0 && totalSize > maxMessageSizePerInterval) || + (maxMessageCountPerInterval > 0 && totalCount > maxMessageCountPerInterval)) { return Response::RespChatFlood; + } } msg.replace(QChar('\n'), QChar(' ')); diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index d3bb488b..a7eba247 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -955,12 +955,12 @@ int Servatrice::getMaxGamesPerUser() const int Servatrice::getCommandCountingInterval() const { - return settingsCache->value("game/command_counting_interval", 10).toInt(); + return settingsCache->value("security/command_counting_interval", 10).toInt(); } int Servatrice::getMaxCommandCountPerInterval() const { - return settingsCache->value("game/max_command_count_per_interval", 20).toInt(); + return settingsCache->value("security/max_command_count_per_interval", 20).toInt(); } int Servatrice::getServerStatusUpdateTime() const