我一直在尝试为WoW模拟器创建一个名为TrinityCore的审查系统。我基本上做的是填充一个数据库表(chat_filter)和'坏词',在启动时和每个由玩家制作的聊天线上填充一个矢量,它会根据我的矢量内容进行检查。如果它包含一个不好的单词,则被替换为* *(而*的数量也将从数据库表(todo)的一列中取出),玩家将受到惩罚(静音或)。将正则表达式添加到C++的审查系统中
现在我遇到了麻烦,是如何做出适当的过滤器。现在你必须添加你能想到的每个可能的单词组合,例如'a.s.s.'也应该读作'屁股',我不知道该怎么做!
这是当前代码的重要部分,我省去了数据库拉,因为它不会有任何用处(它会使它不太清晰,因为它在不同的文件中)。
char* msg3 = strdup(msg.c_str());
char* words = strtok(msg3, " ,.-()&^%$#@!{}'<>/?|\\=+-_1234567890"); // This splits the sentence in seperated words and removes the symbols
ObjectMgr::ChatFilterContainer const& censoredWords = sObjectMgr->GetCensoredWords();
while (words != NULL && !censoredWords.empty())
{
for (uint32 i = 0; i < censoredWords.size(); ++i)
{
if (!stricmp(censoredWords[i].c_str(), words))
{
sLog->outString("%s", words);
//msg.replace(msg.begin(), msg.end(), msg.c_str(), "***");
msg.replace(msg.begin(), msg.end(), censoredWords[i].c_str(), '*');
}
//msg.replace(msg.begin(), msg.end(), censoredWords[i].c_str(), /*replacement*/ "***");
//msg.replace(msg.find(censoredWords[i].c_str()), censoredWords.size(),
}
words = strtok(NULL, " ,.-()&^%$#@!{}'<>/?|\=+-_1234567890");
}
由于提前,
碧玉
附: 'GetCensoredWords'返回该向量。
P.S.S. 'msg'是一个std :: string - 这是玩家发送的ACTUAL消息。
对于初学者来说,不要使用'strtok',这是一个破损的API。使用'strdup'创建一旦你在符号上进行标记,你打算如何判断“屁股”是否作为单词输入? –
我没有答案,但建议提问者阅读http://thedailywtf.com/Articles/该-Clbuttic-错误-的.aspx, –