mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-21 13:07:31 +00:00
replace white and blacklist (#1530)
This commit is contained in:
parent
24de0e5fdb
commit
b340d7c8f9
@ -103,7 +103,7 @@ make_directory(${CMAKE_BINARY_DIR}/resServer)
|
||||
make_directory(${CMAKE_BINARY_DIR}/logs)
|
||||
|
||||
# Copy resource files on first build
|
||||
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf")
|
||||
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blocklist.dcf")
|
||||
message(STATUS "Checking resource file integrity")
|
||||
|
||||
include(Utils)
|
||||
|
@ -27,8 +27,8 @@ dChatFilter::dChatFilter(const std::string& filepath, bool dontGenerateDCF) {
|
||||
ExportWordlistToDCF(filepath + ".dcf", true);
|
||||
}
|
||||
|
||||
if (BinaryIO::DoesFileExist("blacklist.dcf")) {
|
||||
ReadWordlistDCF("blacklist.dcf", false);
|
||||
if (BinaryIO::DoesFileExist("blocklist.dcf")) {
|
||||
ReadWordlistDCF("blocklist.dcf", false);
|
||||
}
|
||||
|
||||
//Read player names that are ok as well:
|
||||
@ -44,20 +44,20 @@ dChatFilter::~dChatFilter() {
|
||||
m_DeniedWords.clear();
|
||||
}
|
||||
|
||||
void dChatFilter::ReadWordlistPlaintext(const std::string& filepath, bool whiteList) {
|
||||
void dChatFilter::ReadWordlistPlaintext(const std::string& filepath, bool allowList) {
|
||||
std::ifstream file(filepath);
|
||||
if (file) {
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
|
||||
std::transform(line.begin(), line.end(), line.begin(), ::tolower); //Transform to lowercase
|
||||
if (whiteList) m_ApprovedWords.push_back(CalculateHash(line));
|
||||
if (allowList) m_ApprovedWords.push_back(CalculateHash(line));
|
||||
else m_DeniedWords.push_back(CalculateHash(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool whiteList) {
|
||||
bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool allowList) {
|
||||
std::ifstream file(filepath, std::ios::binary);
|
||||
if (file) {
|
||||
fileHeader hdr;
|
||||
@ -70,13 +70,13 @@ bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool whiteList) {
|
||||
if (hdr.formatVersion == formatVersion) {
|
||||
size_t wordsToRead = 0;
|
||||
BinaryIO::BinaryRead(file, wordsToRead);
|
||||
if (whiteList) m_ApprovedWords.reserve(wordsToRead);
|
||||
if (allowList) m_ApprovedWords.reserve(wordsToRead);
|
||||
else m_DeniedWords.reserve(wordsToRead);
|
||||
|
||||
size_t word = 0;
|
||||
for (size_t i = 0; i < wordsToRead; ++i) {
|
||||
BinaryIO::BinaryRead(file, word);
|
||||
if (whiteList) m_ApprovedWords.push_back(word);
|
||||
if (allowList) m_ApprovedWords.push_back(word);
|
||||
else m_DeniedWords.push_back(word);
|
||||
}
|
||||
|
||||
@ -90,14 +90,14 @@ bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool whiteList) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool whiteList) {
|
||||
void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool allowList) {
|
||||
std::ofstream file(filepath, std::ios::binary | std::ios_base::out);
|
||||
if (file) {
|
||||
BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::header));
|
||||
BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::formatVersion));
|
||||
BinaryIO::BinaryWrite(file, size_t(whiteList ? m_ApprovedWords.size() : m_DeniedWords.size()));
|
||||
BinaryIO::BinaryWrite(file, size_t(allowList ? m_ApprovedWords.size() : m_DeniedWords.size()));
|
||||
|
||||
for (size_t word : whiteList ? m_ApprovedWords : m_DeniedWords) {
|
||||
for (size_t word : allowList ? m_ApprovedWords : m_DeniedWords) {
|
||||
BinaryIO::BinaryWrite(file, word);
|
||||
}
|
||||
|
||||
@ -105,10 +105,10 @@ void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool whiteLis
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool whiteList) {
|
||||
std::vector<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList) {
|
||||
if (gmLevel > eGameMasterLevel::FORUM_MODERATOR) return { }; //If anything but a forum mod, return true.
|
||||
if (message.empty()) return { };
|
||||
if (!whiteList && m_DeniedWords.empty()) return { { 0, message.length() } };
|
||||
if (!allowList && m_DeniedWords.empty()) return { { 0, message.length() } };
|
||||
|
||||
std::stringstream sMessage(message);
|
||||
std::string segment;
|
||||
@ -126,16 +126,16 @@ std::vector<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::
|
||||
|
||||
size_t hash = CalculateHash(segment);
|
||||
|
||||
if (std::find(m_UserUnapprovedWordCache.begin(), m_UserUnapprovedWordCache.end(), hash) != m_UserUnapprovedWordCache.end() && whiteList) {
|
||||
if (std::find(m_UserUnapprovedWordCache.begin(), m_UserUnapprovedWordCache.end(), hash) != m_UserUnapprovedWordCache.end() && allowList) {
|
||||
listOfBadSegments.emplace_back(position, originalSegment.length());
|
||||
}
|
||||
|
||||
if (std::find(m_ApprovedWords.begin(), m_ApprovedWords.end(), hash) == m_ApprovedWords.end() && whiteList) {
|
||||
if (std::find(m_ApprovedWords.begin(), m_ApprovedWords.end(), hash) == m_ApprovedWords.end() && allowList) {
|
||||
m_UserUnapprovedWordCache.push_back(hash);
|
||||
listOfBadSegments.emplace_back(position, originalSegment.length());
|
||||
}
|
||||
|
||||
if (std::find(m_DeniedWords.begin(), m_DeniedWords.end(), hash) != m_DeniedWords.end() && !whiteList) {
|
||||
if (std::find(m_DeniedWords.begin(), m_DeniedWords.end(), hash) != m_DeniedWords.end() && !allowList) {
|
||||
m_UserUnapprovedWordCache.push_back(hash);
|
||||
listOfBadSegments.emplace_back(position, originalSegment.length());
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ public:
|
||||
dChatFilter(const std::string& filepath, bool dontGenerateDCF);
|
||||
~dChatFilter();
|
||||
|
||||
void ReadWordlistPlaintext(const std::string& filepath, bool whiteList);
|
||||
bool ReadWordlistDCF(const std::string& filepath, bool whiteList);
|
||||
void ExportWordlistToDCF(const std::string& filepath, bool whiteList);
|
||||
std::vector<std::pair<uint8_t, uint8_t>> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool whiteList = true);
|
||||
void ReadWordlistPlaintext(const std::string& filepath, bool allowList);
|
||||
bool ReadWordlistDCF(const std::string& filepath, bool allowList);
|
||||
void ExportWordlistToDCF(const std::string& filepath, bool allowList);
|
||||
std::vector<std::pair<uint8_t, uint8_t>> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList = true);
|
||||
|
||||
private:
|
||||
bool m_DontGenerateDCF;
|
||||
|
@ -29,8 +29,8 @@ enum class eWorldMessageType : uint32_t {
|
||||
ROUTE_PACKET, // Social?
|
||||
POSITION_UPDATE,
|
||||
MAIL,
|
||||
WORD_CHECK, // Whitelist word check
|
||||
STRING_CHECK, // Whitelist string check
|
||||
WORD_CHECK, // AllowList word check
|
||||
STRING_CHECK, // AllowList string check
|
||||
GET_PLAYERS_IN_ZONE,
|
||||
REQUEST_UGC_MANIFEST_INFO,
|
||||
BLUEPRINT_GET_ALL_DATA_REQUEST,
|
||||
|
@ -83,7 +83,7 @@ void UserManager::Initialize() {
|
||||
auto chatListStream = Game::assetManager->GetFile("chatplus_en_us.txt");
|
||||
if (!chatListStream) {
|
||||
LOG("Failed to load %s", (Game::assetManager->GetResPath() / "chatplus_en_us.txt").string().c_str());
|
||||
throw std::runtime_error("Aborting initialization due to missing chat whitelist file.");
|
||||
throw std::runtime_error("Aborting initialization due to missing chat allowlist file.");
|
||||
}
|
||||
|
||||
while (std::getline(chatListStream, line, '\n')) {
|
||||
|
@ -352,16 +352,11 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
|
||||
auto* spawner = Game::zoneManager->GetSpawner(spawnerId);
|
||||
|
||||
auto ldfModelBehavior = new LDFData<LWOOBJID>(u"modelBehaviors", 0);
|
||||
auto userModelID = new LDFData<LWOOBJID>(u"userModelID", info.spawnerID);
|
||||
auto modelType = new LDFData<int>(u"modelType", 2);
|
||||
auto propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
|
||||
auto componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
|
||||
info.nodes[0]->config.push_back(componentWhitelist);
|
||||
info.nodes[0]->config.push_back(ldfModelBehavior);
|
||||
info.nodes[0]->config.push_back(modelType);
|
||||
info.nodes[0]->config.push_back(propertyObjectID);
|
||||
info.nodes[0]->config.push_back(userModelID);
|
||||
info.nodes[0]->config.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0));
|
||||
info.nodes[0]->config.push_back(new LDFData<LWOOBJID>(u"userModelID", info.spawnerID));
|
||||
info.nodes[0]->config.push_back(new LDFData<int>(u"modelType", 2));
|
||||
info.nodes[0]->config.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
info.nodes[0]->config.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
|
||||
auto* model = spawner->Spawn();
|
||||
|
||||
@ -585,29 +580,17 @@ void PropertyManagementComponent::Load() {
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
|
||||
|
||||
LDFBaseData* ldfBlueprintID = new LDFData<LWOOBJID>(u"blueprintid", blueprintID);
|
||||
LDFBaseData* componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
|
||||
LDFBaseData* modelType = new LDFData<int>(u"modelType", 2);
|
||||
LDFBaseData* propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
|
||||
LDFBaseData* userModelID = new LDFData<LWOOBJID>(u"userModelID", databaseModel.id);
|
||||
|
||||
settings.push_back(ldfBlueprintID);
|
||||
settings.push_back(componentWhitelist);
|
||||
settings.push_back(modelType);
|
||||
settings.push_back(propertyObjectID);
|
||||
settings.push_back(userModelID);
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"blueprintid", blueprintID));
|
||||
settings.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
settings.push_back(new LDFData<int>(u"modelType", 2));
|
||||
settings.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"userModelID", databaseModel.id));
|
||||
} else {
|
||||
auto modelType = new LDFData<int>(u"modelType", 2);
|
||||
auto userModelID = new LDFData<LWOOBJID>(u"userModelID", databaseModel.id);
|
||||
auto ldfModelBehavior = new LDFData<LWOOBJID>(u"modelBehaviors", 0);
|
||||
auto propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
|
||||
auto componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
|
||||
|
||||
settings.push_back(componentWhitelist);
|
||||
settings.push_back(ldfModelBehavior);
|
||||
settings.push_back(modelType);
|
||||
settings.push_back(propertyObjectID);
|
||||
settings.push_back(userModelID);
|
||||
settings.push_back(new LDFData<int>(u"modelType", 2));
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"userModelID", databaseModel.id));
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0));
|
||||
settings.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
settings.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
}
|
||||
|
||||
node->config = settings;
|
||||
|
@ -2663,17 +2663,11 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* ent
|
||||
info.spawnerID = entity->GetObjectID();
|
||||
info.spawnerNodeID = 0;
|
||||
|
||||
LDFBaseData* ldfBlueprintID = new LDFData<LWOOBJID>(u"blueprintid", blueprintID);
|
||||
LDFBaseData* componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
|
||||
LDFBaseData* modelType = new LDFData<int>(u"modelType", 2);
|
||||
LDFBaseData* propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
|
||||
LDFBaseData* userModelID = new LDFData<LWOOBJID>(u"userModelID", newIDL);
|
||||
|
||||
info.settings.push_back(ldfBlueprintID);
|
||||
info.settings.push_back(componentWhitelist);
|
||||
info.settings.push_back(modelType);
|
||||
info.settings.push_back(propertyObjectID);
|
||||
info.settings.push_back(userModelID);
|
||||
info.settings.push_back(new LDFData<LWOOBJID>(u"blueprintid", blueprintID));
|
||||
info.settings.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
info.settings.push_back(new LDFData<int>(u"modelType", 2));
|
||||
info.settings.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
info.settings.push_back(new LDFData<LWOOBJID>(u"userModelID", newIDL));
|
||||
|
||||
Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr);
|
||||
if (newEntity) {
|
||||
|
Loading…
Reference in New Issue
Block a user