Sayfilter

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Sayfilter

Post 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?
I have promises to keep and miles to go before I sleep.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Sayfilter

Post 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.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Sayfilter

Post by Starter »

jurchiks wrote: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.
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".^^
I have promises to keep and miles to go before I sleep.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Sayfilter

Post 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)
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Sayfilter

Post 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());                        } 
?
I have promises to keep and miles to go before I sleep.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Sayfilter

Post 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")?
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Sayfilter

Post by Starter »

Yep, just tested it, the result is: "the^_^at".

I give up. :mrgreen:
I have promises to keep and miles to go before I sleep.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Sayfilter

Post by jurchiks »

...what does the console output?
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Sayfilter

Post 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. :D

Btw, why you dont use the Scanner-class instead of the BufferedReader-class?
I have promises to keep and miles to go before I sleep.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Sayfilter

Post 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).
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Sayfilter

Post 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. :)
I have promises to keep and miles to go before I sleep.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Sayfilter

Post by jurchiks »

Thanks, same to you too ;)
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Post Reply