1
This commit is contained in:
parent
4765f1d8ed
commit
eb6775aeb9
@ -1,5 +1,7 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <a8/stringlist.h>
|
#include <a8/stringlist.h>
|
||||||
#include <a8/csvreader.h>
|
#include <a8/csvreader.h>
|
||||||
|
|
||||||
@ -18,12 +20,13 @@
|
|||||||
class MetaDataLoader
|
class MetaDataLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
std::map<size_t, std::map<std::string, std::string> > dirty_words;
|
||||||
|
|
||||||
void Load()
|
void Load()
|
||||||
{
|
{
|
||||||
if (!f8::IsOnlineEnv()) {
|
if (!f8::IsOnlineEnv()) {
|
||||||
if (f8::IsTestEnv()) {
|
if (f8::IsTestEnv()) {
|
||||||
res_path = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver.test/res%d/",
|
res_path = a8::Format("/root/pub/%d/%d/conf_test/game%d/rankserver.test/res%d/",
|
||||||
{
|
{
|
||||||
GAME_ID,
|
GAME_ID,
|
||||||
App::Instance()->instance_id,
|
App::Instance()->instance_id,
|
||||||
@ -31,7 +34,7 @@ public:
|
|||||||
App::Instance()->instance_id
|
App::Instance()->instance_id
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res_path = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver.dev/res%d/",
|
res_path = a8::Format("/root/pub/%d/%d/conf_test/game%d/rankserver.dev/res%d/",
|
||||||
{
|
{
|
||||||
GAME_ID,
|
GAME_ID,
|
||||||
App::Instance()->instance_id,
|
App::Instance()->instance_id,
|
||||||
@ -42,11 +45,32 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
res_path = "../res/";
|
res_path = "../res/";
|
||||||
}
|
}
|
||||||
|
LoadDirtyWordTable();
|
||||||
Check();
|
Check();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void LoadDirtyWordTable()
|
||||||
|
{
|
||||||
|
a8::CsvReader reader;
|
||||||
|
reader.Load(res_path + "dirtyWorld.csv");
|
||||||
|
while (reader.NextLine()) {
|
||||||
|
std::string strword = reader.GetValue("word").GetString();
|
||||||
|
if (strword == " " || strword.empty()) { //忽略空格
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto itr = dirty_words.find(strword.size());
|
||||||
|
if (dirty_words.find(strword.size()) != dirty_words.end()) {
|
||||||
|
itr->second[strword] = strword;
|
||||||
|
} else {
|
||||||
|
std::map<std::string, std::string> words;
|
||||||
|
words[strword] = strword;
|
||||||
|
dirty_words[strword.size()] = words;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Check()
|
void Check()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -80,7 +104,19 @@ void MetaMgr::Reload()
|
|||||||
loader_->Load();
|
loader_->Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MetaMgr::HasDirtyWord(const std::string& word)
|
bool MetaMgr::HasDirtyWord(const std::string& text)
|
||||||
{
|
{
|
||||||
|
for (size_t i = 0; i < text.size(); i++) {
|
||||||
|
for (auto itr = loader_->dirty_words.begin(); itr != loader_->dirty_words.end(); ++itr) {
|
||||||
|
if (itr->first <= text.size() - i) {
|
||||||
|
std::string substr = text.substr(i, itr->first);
|
||||||
|
// 如果是纯英文,则先转为小写,根据策划说明,屏蔽字大小写不敏感
|
||||||
|
std::transform(substr.begin(), substr.end(), substr.begin(), ::tolower);
|
||||||
|
if (substr.size() > 0 && itr->second.find(substr) != itr->second.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
|||||||
void UnInit();
|
void UnInit();
|
||||||
void Reload();
|
void Reload();
|
||||||
|
|
||||||
bool HasDirtyWord(const std::string& word);
|
bool HasDirtyWord(const std::string& text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MetaDataLoader* loader_ = nullptr;
|
MetaDataLoader* loader_ = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user