Page 1 of 1
Sayfilter
Posted: Sat Jun 04, 2011 5:20 pm
by Starter
Hello everyone,
I got a general question about the sayfilter (not really revision dependant so I didnt post my actual revision^^).
So, the problem is as follows:
If I enter a to filter (replace) word in the chatfilter.txt file which shall be replaced by the given chat filter chars its filtered totally correct but if I do the same with a domain ending like ".at" it gets really wierd because when I type "the chat" (for example) ingame the result is "the c^_^" (^_^ are the chat filter chars). I guess its because the regex filter is set up false for my purpose (missing parameter(s)?) but how to set it up so that it filters domain endings correctly too? I tried the whole day and read thousand sites but found nothing useful and now im kinda stuck and im nearly giving up on it. My last hope is the community here. ^.^
So, anyone knows how this could be fixed?
Re: Sayfilter
Posted: Sat Jun 04, 2011 5:49 pm
by jurchiks
That's because java regex considers dot (.) an "any character" replacement.
http://download.oracle.com/javase/tutor ... asses.html
All you need to do to fix is is to escape any dots in your filter with "\\", like so: "abc\\.ef". I think that should work.
Re: Sayfilter
Posted: Sat Jun 04, 2011 6:09 pm
by Starter
This is something I tried first (write "\\" in front of the domain ending which shall be filtered = "\\.at") but then comes an even more wierd result: "the^_^at".^^
Re: Sayfilter
Posted: Sat Jun 04, 2011 6:35 pm
by jurchiks
Weird... I can't reproduce the problem using this test class:
Code: Select all
import java.io.BufferedReader;import java.io.InputStreamReader; public class RegexTest{ public static void main(String[] args) { System.out.print("Enter the string to check: "); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String choice = ""; try { choice = reader.readLine(); System.out.print("enter the replacement: "); String regex = reader.readLine(); System.out.println(choice.replaceAll("(?i)" + regex, "(omg)")); } catch (Exception e) {} }}
If I try to write "\\.at" as a replacement, it doesn't replace anything, but if I write just ".at", it works fine:
Enter the string to check: austria.at
enter the replacement: .at
austria(omg)
Enter the string to check: austria.at
enter the replacement: \\.at
austria.at
The replaceAll function is the one used in Say2.java where the filters are applied so there's no problem there. Could be the reading from file messes things up...
Edit: this works though:
Enter the string to check: austria.at
enter the replacement: [\\.]at
austria(omg)
Re: Sayfilter
Posted: Sat Jun 04, 2011 6:55 pm
by Starter
Just test it ingame under the same circumstances and not under other circumstances and you will see the wierd results. But thanks for your work so far, really nice.
Maybe its this passage in Config.java causing this issue:
Code: Select all
FILTER_LIST = new ArrayList<String>(); LineNumberReader lnr = new LineNumberReader(new BufferedReader(new FileReader(new File(CHAT_FILTER_FILE)))); String line = null; while ((line = lnr.readLine()) != null) { if (line.trim().isEmpty() || line.startsWith("#")) continue; FILTER_LIST.add(line.trim()); }
?
Re: Sayfilter
Posted: Sat Jun 04, 2011 7:15 pm
by jurchiks
There's nothing weird there, that's the problem. It just reads every line from the file that is not commented out or empty, trims the starting/ending spaces and adds it to the list. The only thing I could think of is the reader removing slashes or smth, even though it shouldn't matter.
Try adding a log message in Say2 packet in the loop that replaces the patterns:
Code: Select all
private void checkText() { String filteredText = _text; _log.info("processing message: "+_text); for (String pattern : Config.FILTER_LIST) { _log.info("replacing pattern: "+pattern); filteredText = filteredText.replaceAll("(?i)" + pattern, Config.CHAT_FILTER_CHARS); } _log.info("processed text: "+_text); _text = filteredText; }
This should not require ingame testing.
Edit: did you test the last regex too ("[\\.]at")?
Re: Sayfilter
Posted: Sat Jun 04, 2011 7:25 pm
by Starter
Yep, just tested it, the result is: "the^_^at".
I give up.

Re: Sayfilter
Posted: Sat Jun 04, 2011 8:57 pm
by jurchiks
...what does the console output?
Re: Sayfilter
Posted: Sat Jun 04, 2011 9:18 pm
by Starter
Ok, solved the problem with your great help!
The problem were the other domain endings I had also in the file which I didnt modify the way you suggested above, somehow. oO
Works like a charm, thank you very much.
Btw, why you dont use the Scanner-class instead of the BufferedReader-class?
Re: Sayfilter
Posted: Sat Jun 04, 2011 9:40 pm
by jurchiks
That's good

Though the dots should be escaped in core to avoid future problems.
About the Scanner - haven't dug much into that. The method documentation for "next()" does not specify what it means by "next token", i.e. what if I don't specify any delimiters?
In other words, BufferedReader is simply comfortable, I don't need specific data types, IMO it's better to check each input and show an error, if any, than just do nothing if input is wrong (that's from user perspective, of course).
Re: Sayfilter
Posted: Sat Jun 04, 2011 11:11 pm
by Starter
Hehe, I learned to use the Scanner-class so im always using it and for my purposes it was always good.^^
Well thank you again might, I hope I can help you once too - even though I believe this wont happen since you know what you are doing. Good luck with everything.

Re: Sayfilter
Posted: Sun Jun 05, 2011 9:12 am
by jurchiks
Thanks, same to you too
