Your code could be optimized by a considerable amount.
Your cycling through a text document every single time the chat packet is received.
The better option would be to load the "bad" words at initialization and store them to a collection, saving execution time when chatting.
The coding of the loop isn't great either.
I would do something like this.
Code:
//Declaration of Collection
public static Dictionary<string,string> Filter = new Dictionary<string,string>();
//The filter.txt should always be in the correct directory.
//Use Original word as the key, and the value as the one to replace
//Do this at startup
foreach(string Line in File.ReadAllLines(Directory + @"\Filter.txt"))
{
string[] lSplitter = Line.Split('#');
Filter.Add(lSplitter[0],lSplitter[1]);
}
//Then in your chat.cs
foreach (KeyValuePair<string,string> kvp in Filter)
{
if (message.Contains(kvp.Key))
message = message.Replace(kvp.Key, kvp.Value);
}
Of course, that can still probably be improved, but imo it's superior to your method.