diff --git a/bin/config_sample/text/filter.txt b/bin/config_sample/text/filter.txt new file mode 100644 index 00000000..01382d70 --- /dev/null +++ b/bin/config_sample/text/filter.txt @@ -0,0 +1 @@ +tranny \ No newline at end of file diff --git a/src/config_manager.cpp b/src/config_manager.cpp index bf8c60a1..c754b5ac 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -93,6 +93,7 @@ bool ConfigManager::verifyServerConfig() m_commands->praises = (loadConfigFile("praise")); m_commands->reprimands = (loadConfigFile("reprimands")); m_commands->gimps = (loadConfigFile("gimp")); + m_commands->filters = (loadConfigFile("filter")); m_commands->cdns = (loadConfigFile("cdns")); if (m_commands->cdns.isEmpty()) m_commands->cdns = QStringList{"cdn.discord.com"}; @@ -621,6 +622,11 @@ QStringList ConfigManager::gimpList() return m_commands->gimps; } +QStringList ConfigManager::filterList() +{ + return m_commands->filters; +} + QStringList ConfigManager::cdnList() { return m_commands->cdns; diff --git a/src/config_manager.h b/src/config_manager.h index 27763544..9106a6d7 100644 --- a/src/config_manager.h +++ b/src/config_manager.h @@ -421,6 +421,13 @@ class ConfigManager */ static QStringList gimpList(); + /** + * @brief Returns the server regex filter list + * + * @return See short description. + */ + static QStringList filterList(); + /** * @brief Returns the server approved domain list. * @@ -519,6 +526,7 @@ class ConfigManager QStringList praises; //!< Contains command praises, found in config/text/praises.txt QStringList reprimands; //!< Contains command reprimands, found in config/text/reprimands.txt QStringList gimps; //!< Contains phrases for /gimp, found in config/text/gimp.txt + QStringList filters; //!< Contains filter regex, found in config/text/filter.txt QStringList cdns; // !< Contains domains for custom song validation, found in config/text/cdns.txt }; diff --git a/src/packet/packet_ct.cpp b/src/packet/packet_ct.cpp index 140f9ecf..21351a59 100644 --- a/src/packet/packet_ct.cpp +++ b/src/packet/packet_ct.cpp @@ -43,9 +43,17 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const } QString l_message = client.dezalgo(m_content[1]); + if (l_message.length() == 0 || l_message.length() > ConfigManager::maxCharacters()) return; - AOPacket *final_packet = PacketFactory::createPacket("CT", {client.name(), l_message, "0"}); + + if (!ConfigManager::filterList().isEmpty()) { + foreach (const QString ®ex, ConfigManager::filterList()) { + QRegularExpression re(regex, QRegularExpression::CaseInsensitiveOption); + l_message.replace(re, "❌"); + } + } + if (l_message.at(0) == '/') { QStringList l_cmd_argv = l_message.split(" ", Qt::SkipEmptyParts); QString l_command = l_cmd_argv[0].trimmed().toLower(); @@ -58,6 +66,7 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const return; } else { + AOPacket *final_packet = PacketFactory::createPacket("CT", {client.name(), l_message, "0"}); client.getServer()->broadcast(final_packet, client.areaId()); } emit client.logOOC((client.character() + " " + client.characterName()), client.name(), client.m_ipid, area->name(), l_message); diff --git a/src/packet/packet_ms.cpp b/src/packet/packet_ms.cpp index 3581576d..9097e2ac 100644 --- a/src/packet/packet_ms.cpp +++ b/src/packet/packet_ms.cpp @@ -138,6 +138,13 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const return l_invalid; } + if (!ConfigManager::filterList().isEmpty()) { + foreach (const QString ®ex, ConfigManager::filterList()) { + QRegularExpression re(regex, QRegularExpression::CaseInsensitiveOption); + l_incoming_msg.replace(re, "❌"); + } + } + if (client.m_is_gimped) { QString l_gimp_message = ConfigManager::gimpList().at((client.genRand(1, ConfigManager::gimpList().size() - 1))); l_incoming_msg = l_gimp_message;