add regex filter (#370)
* add regex list * replace CT as well * replace instead of remove * add a default filter
This commit is contained in:
parent
aab41987d9
commit
db50c81ceb
1
bin/config_sample/text/filter.txt
Normal file
1
bin/config_sample/text/filter.txt
Normal file
@ -0,0 +1 @@
|
||||
tranny
|
@ -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;
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user