我一直在嘗試爲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, –