Loading...   

  • Created By Uleat On: 07:37 PM January 31, 2019
  • Link

 common/CMakeLists.txt        |   2 +
 common/profanity_manager.cpp | 148 +++++++++++++++++++++++++++++++++++++++++++
 common/profanity_manager.h   |  56 ++++++++++++++++
 zone/client.cpp              |   5 ++
 zone/net.cpp                 |   5 ++
 5 files changed, 216 insertions(+)

diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index b953815e..5e31e679 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -55,6 +55,7 @@ SET(common_sources
 	perl_eqdb.cpp
 	perl_eqdb_res.cpp
 	proc_launcher.cpp
+	profanity_manager.cpp
 	ptimer.cpp
 	races.cpp
 	rdtsc.cpp
@@ -181,6 +182,7 @@ SET(common_headers
 	packet_functions.h
 	platform.h
 	proc_launcher.h
+	profanity_manager.h
 	profiler.h
 	ptimer.h
 	queue.h
diff --git a/common/profanity_manager.cpp b/common/profanity_manager.cpp
new file mode 100644
index 00000000..fb0cd41d
--- /dev/null
+++ b/common/profanity_manager.cpp
@@ -0,0 +1,148 @@
+/*	EQEMu: Everquest Server Emulator
+	
+	Copyright (C) 2001-2019 EQEMu Development Team (http://eqemulator.net)
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; version 2 of the License.
+
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY except by those people which sell it, which
+	are required to give you total support for your newly bought product;
+	without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+	A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+	
+	You should have received a copy of the GNU General Public License
+	along with this program; if not, write to the Free Software
+	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "profanity_manager.h"
+#include "dbcore.h"
+
+
+bool EQEmu::ProfanityManager::LoadProfanityList(DBcore *db) {
+	if (!db)
+		return false;
+
+	m_profanity_list.clear();
+
+	std::string query = "SELECT `word` FROM `profanity_list`";
+	auto results = db->QueryDatabase(query);
+	if (!results.Success())
+		return false;
+	
+	for (auto row = results.begin(); row != results.end(); ++row) {
+		if (std::strlen(row[0]) >= REDACTION_LENGTH_MIN)
+			m_profanity_list.push_back(std::string(row[0]));
+	}
+
+	return true;
+}
+
+bool EQEmu::ProfanityManager::DeleteProfanityList(DBcore *db) {
+	if (!db)
+		return false;
+
+	m_profanity_list.clear();
+
+	if (!clear_database_entries(db))
+		return false;
+
+	return true;
+}
+
+bool EQEmu::ProfanityManager::AddProfanity(DBcore *db, const char *profanity) {
+	if (!db || !profanity)
+		return false;
+
+	if (check_for_existing_entry(profanity))
+		return true;
+
+	if (std::strlen(profanity) < REDACTION_LENGTH_MIN)
+		return false;
+
+	m_profanity_list.push_back(std::string(profanity));
+
+	std::string query = "REPLACE INTO `profanity_list` (`word`) VALUES ('";
+	query.append(profanity);
+	query.append("')");
+	auto results = db->QueryDatabase(query);
+	if (!results.Success())
+		return false;
+
+	return true;
+}
+
+bool EQEmu::ProfanityManager::RemoveProfanity(DBcore *db, const char *profanity) {
+	if (!db || !profanity)
+		return false;
+
+	if (!check_for_existing_entry(profanity))
+		return true;
+
+	m_profanity_list.remove(profanity); // DOUBLE-CHECK THIS!!!
+
+	std::string query = "DELETE FROM `profanity_list` WHERE `word` LIKE '";
+	query.append(profanity);
+	query.append("'");
+	auto results = db->QueryDatabase(query);
+	if (!results.Success())
+		return false;
+
+	return true;
+}
+
+void EQEmu::ProfanityManager::RedactMessage(char *message, size_t length) {
+	if (!message)
+		return;
+
+	if (length == std::string::npos)
+		length = std::strlen(message);
+
+	if (length < REDACTION_LENGTH_MIN)
+		return;
+
+	// consider adding textlink checks if it becomes an issue
+	for (const auto &iter : m_profanity_list) {
+		// do this and command
+	}
+}
+
+void EQEmu::ProfanityManager::RedactMessage(std::string &message) {
+	if (message.length() < REDACTION_LENGTH_MIN)
+		return;
+
+	// consider adding textlink checks if it becomes an issue
+	for (const auto &iter : m_profanity_list) {
+		// do this and command
+	}
+}
+
+bool EQEmu::ProfanityManager::IsCensorshipActive() {
+	return (m_profanity_list.size() != 0);
+}
+
+bool EQEmu::ProfanityManager::clear_database_entries(DBcore *db) {
+	if (!db)
+		return false;
+
+	std::string query = "DELETE FROM `profanity_list`";
+	auto results = db->QueryDatabase(query);
+	if (!results.Success())
+		return false;
+
+	return true;
+}
+
+bool EQEmu::ProfanityManager::check_for_existing_entry(const char *profanity) {
+	if (!profanity)
+		return false;
+
+	for (const auto &iter : m_profanity_list) {
+		if (iter.compare(profanity) == 0)
+			return true;
+	}
+	
+	return false;
+}
diff --git a/common/profanity_manager.h b/common/profanity_manager.h
new file mode 100644
index 00000000..09713b7e
--- /dev/null
+++ b/common/profanity_manager.h
@@ -0,0 +1,56 @@
+/*	EQEMu: Everquest Server Emulator
+	
+	Copyright (C) 2001-2019 EQEMu Development Team (http://eqemulator.net)
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; version 2 of the License.
+	
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY except by those people which sell it, which
+	are required to give you total support for your newly bought product;
+	without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+	A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+	
+	You should have received a copy of the GNU General Public License
+	along with this program; if not, write to the Free Software
+	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#ifndef COMMON_PROFANITY_MANAGER_H
+#define COMMON_PROFANITY_MANAGER_H
+
+#include <string>
+#include <list>
+
+
+class DBcore;
+
+namespace EQEmu
+{
+	class ProfanityManager {
+	public:
+		static bool LoadProfanityList(DBcore *db);
+		static bool DeleteProfanityList(DBcore *db);
+
+		static bool AddProfanity(DBcore *db, const char *profanity);
+		static bool RemoveProfanity(DBcore *db, const char *profanity);
+		
+		static void RedactMessage(char *message, size_t length = std::string::npos);
+		static void RedactMessage(std::string &message);
+
+		static bool IsCensorshipActive();
+
+		static const char REDACTION_CHARACTER = '*';
+		static const int REDACTION_LENGTH_MIN = 3;
+
+	private:
+		static bool clear_database_entries(DBcore *db);
+		static bool check_for_existing_entry(const char *profanity);
+
+		static std::list<std::string> m_profanity_list;
+	};
+
+} /*EQEmu*/
+
+#endif /*COMMON_PROFANITY_MANAGER_H*/
diff --git a/zone/client.cpp b/zone/client.cpp
index beb21ae3..d7be280b 100644
--- a/zone/client.cpp
+++ b/zone/client.cpp
@@ -38,6 +38,7 @@ extern volatile bool RunLoops;
 #include "../common/rulesys.h"
 #include "../common/string_util.h"
 #include "../common/data_verification.h"
+#include "../common/profanity_manager.h"
 #include "data_bucket.h"
 #include "position.h"
 #include "net.h"
@@ -895,6 +896,10 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s
 		language = 0; // No need for language when drunk
 	}
 
+	// Censor the message
+	if (EQEmu::ProfanityManager::IsCensorshipActive())
+		EQEmu::ProfanityManager::RedactMessage(message);
+
 	switch(chan_num)
 	{
 	case 0: { /* Guild Chat */
diff --git a/zone/net.cpp b/zone/net.cpp
index 5dec8747..4fe935be 100644
--- a/zone/net.cpp
+++ b/zone/net.cpp
@@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #include "../common/eq_stream_ident.h"
 #include "../common/patches/patches.h"
 #include "../common/rulesys.h"
+#include "../common/profanity_manager.h"
 #include "../common/misc_functions.h"
 #include "../common/string_util.h"
 #include "../common/platform.h"
@@ -350,6 +351,10 @@ int main(int argc, char** argv) {
 	Log(Logs::General, Logs::Zone_Server, "Loading corpse timers");
 	database.GetDecayTimes(npcCorpseDecayTimes);
 
+	Log(Logs::General, Logs::Zone_Server, "Loading profanity list");
+	if (!EQEmu::ProfanityManager::LoadProfanityList(&database))
+		Log(Logs::General, Logs::Error, "Loading profanity list FAILED!");
+
 	Log(Logs::General, Logs::Zone_Server, "Loading commands");
 	int retval = command_init();
 	if (retval<0)

Raw Paste Data