add regex filter (#370)

* add regex list

* replace CT as well

* replace instead of remove

* add a default filter
This commit is contained in:
stonedDiscord 2024-08-02 20:59:47 +02:00 committed by GitHub
parent aab41987d9
commit db50c81ceb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1 @@
tranny

View File

@ -93,6 +93,7 @@ bool ConfigManager::verifyServerConfig()
m_commands->praises = (loadConfigFile("praise")); m_commands->praises = (loadConfigFile("praise"));
m_commands->reprimands = (loadConfigFile("reprimands")); m_commands->reprimands = (loadConfigFile("reprimands"));
m_commands->gimps = (loadConfigFile("gimp")); m_commands->gimps = (loadConfigFile("gimp"));
m_commands->filters = (loadConfigFile("filter"));
m_commands->cdns = (loadConfigFile("cdns")); m_commands->cdns = (loadConfigFile("cdns"));
if (m_commands->cdns.isEmpty()) if (m_commands->cdns.isEmpty())
m_commands->cdns = QStringList{"cdn.discord.com"}; m_commands->cdns = QStringList{"cdn.discord.com"};
@ -621,6 +622,11 @@ QStringList ConfigManager::gimpList()
return m_commands->gimps; return m_commands->gimps;
} }
QStringList ConfigManager::filterList()
{
return m_commands->filters;
}
QStringList ConfigManager::cdnList() QStringList ConfigManager::cdnList()
{ {
return m_commands->cdns; return m_commands->cdns;

View File

@ -421,6 +421,13 @@ class ConfigManager
*/ */
static QStringList gimpList(); static QStringList gimpList();
/**
* @brief Returns the server regex filter list
*
* @return See short description.
*/
static QStringList filterList();
/** /**
* @brief Returns the server approved domain list. * @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 praises; //!< Contains command praises, found in config/text/praises.txt
QStringList reprimands; //!< Contains command reprimands, found in config/text/reprimands.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 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 QStringList cdns; // !< Contains domains for custom song validation, found in config/text/cdns.txt
}; };

View File

@ -43,9 +43,17 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const
} }
QString l_message = client.dezalgo(m_content[1]); QString l_message = client.dezalgo(m_content[1]);
if (l_message.length() == 0 || l_message.length() > ConfigManager::maxCharacters()) if (l_message.length() == 0 || l_message.length() > ConfigManager::maxCharacters())
return; return;
AOPacket *final_packet = PacketFactory::createPacket("CT", {client.name(), l_message, "0"});
if (!ConfigManager::filterList().isEmpty()) {
foreach (const QString &regex, ConfigManager::filterList()) {
QRegularExpression re(regex, QRegularExpression::CaseInsensitiveOption);
l_message.replace(re, "");
}
}
if (l_message.at(0) == '/') { if (l_message.at(0) == '/') {
QStringList l_cmd_argv = l_message.split(" ", Qt::SkipEmptyParts); QStringList l_cmd_argv = l_message.split(" ", Qt::SkipEmptyParts);
QString l_command = l_cmd_argv[0].trimmed().toLower(); QString l_command = l_cmd_argv[0].trimmed().toLower();
@ -58,6 +66,7 @@ void PacketCT::handlePacket(AreaData *area, AOClient &client) const
return; return;
} }
else { else {
AOPacket *final_packet = PacketFactory::createPacket("CT", {client.name(), l_message, "0"});
client.getServer()->broadcast(final_packet, client.areaId()); client.getServer()->broadcast(final_packet, client.areaId());
} }
emit client.logOOC((client.character() + " " + client.characterName()), client.name(), client.m_ipid, area->name(), l_message); emit client.logOOC((client.character() + " " + client.characterName()), client.name(), client.m_ipid, area->name(), l_message);

View File

@ -138,6 +138,13 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const
return l_invalid; return l_invalid;
} }
if (!ConfigManager::filterList().isEmpty()) {
foreach (const QString &regex, ConfigManager::filterList()) {
QRegularExpression re(regex, QRegularExpression::CaseInsensitiveOption);
l_incoming_msg.replace(re, "");
}
}
if (client.m_is_gimped) { if (client.m_is_gimped) {
QString l_gimp_message = ConfigManager::gimpList().at((client.genRand(1, ConfigManager::gimpList().size() - 1))); QString l_gimp_message = ConfigManager::gimpList().at((client.genRand(1, ConfigManager::gimpList().size() - 1)));
l_incoming_msg = l_gimp_message; l_incoming_msg = l_gimp_message;