AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Anti-Advertisement plugin questions (https://forums.alliedmods.net/showthread.php?t=143658)

bibu 11-22-2010 15:09

Anti-Advertisement plugin questions
 
I have seen a new plugin in the new plugins section:

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <regex>
new Regex:reret;

public 
plugin_init() {
    
register_plugin("Anti-Ad""0.1""Mati");
    
register_clcmd("say""CheckMessage");
    
register_clcmd("say_team""CheckMessage");
    
    new 
err[32];
    
re regex_compile("(?:\w+\.[a-z]{2,4}\b|(?:\s*\d+\s*\.){3})"reterr31"i");
    if (
re!=REGEX_OKserver_print("Error: %s (%d)"errret);
}

public 
CheckMessage(id) {
    if (
id && id 33 && !is_user_admin(id)) {
        new 
text[64];
        
read_args(text,63);
        
        if (
strlen(text) > 4) {
            new 
match regex_match_c(textreret);
        
            if (
match 0) {
                
client_print(idprint_chat"Advertising is prohibited on this server!");
                return 
PLUGIN_HANDLED;
            }
        }
    }
    return 
PLUGIN_CONTINUE;
}

public 
plugin_end() {
    
regex_free(re);    


Now I wanted to ask, how does it get the IP's and what kind of stuff does it really block, this line should say enough I think but I still don't know how it really works:

PHP Code:

re regex_compile("(?:\w+\.[a-z]{2,4}\b|(?:\s*\d+\s*\.){3})" 


Arkshine 11-22-2010 15:52

Re: Anti-Advertisement plugin questions
 
The regex has 2 parts.

\w+\.[a-z]{2,4}\b
\s*\d+\s*\.){3}

The first is executed and matches : any characters.any character between A and Z with initial length between 2 and 4 but can be expanded if needed. Spaces are not supported around the point. (test . com won't matches)

if the first fails, it tries the second part and matches : any digit. any digit. any digit . Spaces here are supported around the point.

bibu 11-22-2010 16:22

Re: Anti-Advertisement plugin questions
 
Wow thanks for this information, and how did you found that what those 2 lines do? Is that something from the regex module? I can only seen the letters a-z, 2,4 but the rest.... :)

Mati_ 11-22-2010 16:58

Re: Anti-Advertisement plugin questions
 
Well it actually perform a very "rough" check for a domain and an IP address.

The first sub-expression searches for something of the format "<one or more letters>.<minimum 2, maximum 4 characters from A-Z>". That should detect stuff like "Check out example.com".

The second sub-expression searches for " <1 to 3 digits> . <1 to 3 digits> . <1 to 3 digits> .". If that matches it's most likely an IP address and even something like "Visit 127 . 0 . 0 . 1" is matched and blocked.

Arkshine 11-22-2010 17:00

Re: Anti-Advertisement plugin questions
 
Thanks for the precision, I'm a noob in regex. :P


All times are GMT -4. The time now is 11:23.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.