summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2005-12-27 03:42:40 +0000
committerYohann Ferreira <bertram@cegetel.net>2005-12-27 03:42:40 +0000
commit205579c3be58537060785d174f9f67c89444a21b (patch)
tree31c7c8e0af476e70259650e1c577eaf299f3fc78 /src/utils
parentad9ecbf35e0d986d704deba6f8f20ad72a94a99e (diff)
downloadmanaserv-205579c3be58537060785d174f9f67c89444a21b.tar.gz
manaserv-205579c3be58537060785d174f9f67c89444a21b.tar.bz2
manaserv-205579c3be58537060785d174f9f67c89444a21b.tar.xz
manaserv-205579c3be58537060785d174f9f67c89444a21b.zip
Implemented common chat handling, except for chatting in channels. Also the Channel registering/unregistering isn't there yet and the commands needs to be implemented. Added a small slangs filter to reduce bad words in account names and in conversations a little.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/slangsfilter.cpp67
-rw-r--r--src/utils/slangsfilter.h43
2 files changed, 110 insertions, 0 deletions
diff --git a/src/utils/slangsfilter.cpp b/src/utils/slangsfilter.cpp
new file mode 100644
index 00000000..e950243b
--- /dev/null
+++ b/src/utils/slangsfilter.cpp
@@ -0,0 +1,67 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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; either version 2 of the License, or any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; 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 The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "slangsfilter.h"
+
+namespace tmwserv
+{
+namespace utils
+{
+
+/**
+ * The slang table. Don't be surprised. We need to know about bad words in order
+ * to keep them out of the players' conversations.
+*/
+std::string slangs[] = {
+"fuck","shit","slut","whore","bitch",
+"END" // This is the terminator, don't remove it.
+};
+
+bool filterContent(std::string text)
+{
+ bool good = true;
+ unsigned int i = 0;
+ while ( !(slangs[i] == "END") )
+ {
+ for (unsigned int j = 0; j <= text.length(); j++)
+ {
+ // We look for slangs into the sentence.
+ std::string upcasedText = text;
+ std::string upcasedSlang = slangs[i];
+ std::transform(upcasedText.begin(), upcasedText.end(), upcasedText.begin(),
+ (int(*)(int))std::toupper);
+ std::transform(upcasedSlang.begin(), upcasedSlang.end(), upcasedSlang.begin(),
+ (int(*)(int))std::toupper);
+ if ( upcasedText.substr(j, upcasedSlang.length()) == upcasedSlang )
+ {
+ good = false;
+ }
+ }
+ // Next slang
+ i++;
+ }
+
+ return good;
+}
+
+} // ::utils
+} // ::tmwserv
diff --git a/src/utils/slangsfilter.h b/src/utils/slangsfilter.h
new file mode 100644
index 00000000..cb4d2ecc
--- /dev/null
+++ b/src/utils/slangsfilter.h
@@ -0,0 +1,43 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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; either version 2 of the License, or any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; 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 The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+
+#ifndef _TMWSERV_SLANGSFILTER_H_
+#define _TMWSERV_SLANGSFILTER_H_
+
+#include <string>
+
+namespace tmwserv
+{
+namespace utils
+{
+
+ /**
+ * Useful to filter slangs automatically, by instance.
+ * @return true if the sentence is slangs clear.
+ */
+ bool filterContent(std::string text);
+
+} // ::utils
+} // ::tmwserv
+
+#endif