Uber Emulator Chat Filter

Status
Not open for further replies.

VBabe

New Member
May 5, 2011
1
0
This is my first piece of work for the Habbo Hotel section. For those that use Uber Emulator, you will enjoy this. I noticed that Uber Emulator did not have an efficient or functional word filter. Therefore I developed this piece of work for Andres Herron, upon his request. I am now releasing it to all of you.

Uber Emulator Chat Filter

First we are going to add the database table which will contain all the banned words and replacement letters or words. Run the following query in your database.

Code:
CREATE TABLE IF NOT EXISTS `banned_words` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `word` varchar(100) NOT NULL,
  `replace_letter_with` varchar(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Open the Uber Emulator project files and create a new file called "RoomWordFilter.cs" in the "Rooms" folder. Paste the following code into that file.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using Uber.Storage;

namespace Uber.HabboHotel.Rooms
{
    /// <summary>
    /// Filters case-sensitive banned words from client's room messages.
    /// 
    /// NOTE: Redo this to have the banned words cache in a dictionary variable, and add a reload dictionary function + command.
    /// </summary>
    sealed public class RoomWordFilter
    {
        #region Fields
        public readonly static string DefaultReplacement = "bobba";
        #endregion

        #region Methods
        public static string FilterMessage(string Message)
        {
            DataTable BannedWords;

            using (DatabaseClient dbClient = TitanEnvironment.GetDatabase().GetClient())
            {
                BannedWords = dbClient.ReadDataTable("SELECT DISTINCT bw.word AS 'word'"
                                                            + ",bw.replace_letter_with AS 'replace'"
                                                        + "FROM banned_words bw");

                foreach (DataRow Row in BannedWords.Rows)
                {
                    string Word = (string)Row["word"];
                    string Replace = (string)Row["replace"];
                    string ParsedMessage;

                    StringBuilder ParsedWord = new StringBuilder();

                    if (Message.Contains(Word) == true)
                    {
                        // Case Bobba/bobba.
                        if (Replace == "")
                        {
                            if (Message.StartsWith(Word) == true)
                            {
                                string newDefaultReplacement;
                                string flDefaultReplacement = DefaultReplacement.Substring(0, 1);

                                newDefaultReplacement = flDefaultReplacement.ToUpper() + DefaultReplacement.Substring(1);

                                ParsedWord.Append(newDefaultReplacement);
                            }
                            else
                            {
                                ParsedWord.Append(RoomWordFilter.DefaultReplacement);
                            }
                        }
                        // Case *.
                        else
                        {
                            for (ushort i = 1; i <= Word.Length; i++)
                            {
                                ParsedWord.Append(Replace);
                            }
                        }

                        ParsedMessage = Message.Replace(Word, ParsedWord.ToString());

                        Message = ParsedMessage;
                    }
                }
            }

            return Message;
        } 
        #endregion
    }
}

Now open the RoomUser.cs file located in the "Rooms" folder. Find the public function "Chat". Add the following code after the chat command handler. Note, The command handler function is called inside the public function "Chat".

Code:
#region Filters Banned Words
            Message = RoomWordFilter.FilterMessage(Message);
            #endregion

After that stage is done, you can now compile and run your emulator. If you are interested in being able to add and remove banned words in-game through commands, you can add this to your command handler file using the appropriate fuse for your hotel.

Code:
// Takes parameter <word>.
                case "delete_banned_word":
                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        string Word;

                        if (Params.Length == 2)
                        {
                            Word = Params[1];

                            using (DatabaseClient dbClient = TitanEnvironment.GetDatabase().GetClient())
                            {
                                DataRow Row = dbClient.ReadDataRow("SELECT bw.word FROM banned_words bw WHERE bw.word = '" + Word + "' LIMIT 0,1");

                                if (Row != null)
                                {
                                    dbClient.ExecuteQuery("DELETE FROM banned_words WHERE word = '" + Word + "'");

                                    Session.SendNotif("The word \"" + Word + "\" has been removed from the banned words list.");
                                }
                                else
                                {
                                    Session.SendNotif("The word \"" + Word + "\" does not exist in the banned words list.");
                                }
                            }

                            return true;
                        }
                        else
                        {
                            Session.SendNotif("The command \"delete_banned_word\" requires 1 additional parameter.\n\nThe first parameter is the word you would like to remove.");
                            
                            return true;
                        }
                    }

                    return false;

                    // Takes parameters <word>, <replace>.
                case "add_banned_word":
                    if (Session.GetHabbo().HasFuse("fuse_mod"))
                    {
                        string Word;
                        string Replace;

                        if (Params.Length == 3)
                        {
                            Word = Params[1];
                            Replace = Params[2];

                            if (Replace.Length == 1 || Replace == RoomWordFilter.DefaultReplacement)
                            {
                                using (DatabaseClient dbClient = TitanEnvironment.GetDatabase().GetClient())
                                {
                                    DataRow Row = dbClient.ReadDataRow("SELECT bw.word FROM banned_words bw WHERE bw.word = '" + Word + "' LIMIT 0,1");

                                    if (Row != null)
                                    {
                                        Session.SendNotif("The word \"" + Word + "\" already exists in the banned words list.");

                                        return true;
                                    }
                                    else
                                    {
                                        if (Replace.Length == 1)
                                        {
                                            dbClient.ExecuteQuery("INSERT INTO banned_words (word, replace_letter_with) VALUES ('" + Word + "', '" + Replace + "');");
                                        }

                                        if (Replace == RoomWordFilter.DefaultReplacement)
                                        {
                                            Replace = RoomWordFilter.DefaultReplacement;

                                            dbClient.ExecuteQuery("INSERT INTO banned_words (word) VALUES ('" + Word + "');");
                                        }
                                    }
                                }

                                Session.SendNotif("The word \"" + Word + "\" has been added to the banned word list. It is replaced with \"" + Replace + "\".");
                            }
                            else
                            {
                                Session.SendNotif("The second parameter must be one character in length or be the value \"" + RoomWordFilter.DefaultReplacement + "\".");
                            }

                            return true;
                        }
                        else
                        {
                            Session.SendNotif("The command \"add_banned_word\" requires 2 additional parameters.\n\nThe first parameter is the word you would like to ban, the second parameter is the letter you would like to replace it with.\n\nNote, if you would like to replace the banned word with the default replacement, enter \"" + RoomWordFilter.DefaultReplacement + "\" for the second parameter.");

                            return true;
                        }
                    }

                    return false;

Release Notes

If you have any trouble setting it up, or have any questions, let me know and I will see what I can do.

There is one thing I did not do, which if you read through all the code I am sure you will be able to figure it out. I'll give you a hint, it's called performance. You can change around my code to be "resourceful" if you like (which I highly suggest). I did not release the "resourceful" code mainly because it's very easy to code yourself, seeing as I have done all the work.

Dictionaries, lists... they will help you!

Credits

Veronica :rolleyes:.
 

LMFAO

New Member
May 5, 2011
20
0
That's very nice where is this for do you have any screenshot's with approval about this though it looks very neat and i will be sure to use this.
 
Status
Not open for further replies.

Users who are viewing this thread

Top