AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Block IP Pattern (With Spaces) (https://forums.alliedmods.net/showthread.php?t=317923)

Alber9091 08-04-2019 18:38

Block IP Pattern (With Spaces)
 
Is there any way to block ips shared like this.

91 87 88 92
OR
91 87 88 92 27015

I saw this in Alka Code, will this be helpful?

PHP Code:

if(digits && periods 2)
 {
  
server_cmd("amx_kick ^"%s^" %s"szNamereason); 

By the way this is just idea, I would like, Replace Text instead of kick, Replace Text: Stop Advertising !! or plugin made by any means, protects server from such kind of ip sharing, like: Regex if it helps, etc, anything, would be appreciated.

Relaxing 08-04-2019 18:55

Re: Block IP Pattern (With Spaces)
 
#define PATTERN "(\d.*){9}"
I would recommend you this. It turns true when you've typed 9 or more numbers on chat.
The order doesn't matter.

edon1337 08-05-2019 06:23

Re: Block IP Pattern (With Spaces)
 
I don't know about Regex but both of these ideas will return false positives sometimes.

Idea #1: If someone writes 123.. the code will think he's advertising an IP, but he isn't.
Idea #2: If someone writes 123456789 , the code will also think he's advertising, but in fact he isn't.

Alber9091 08-05-2019 06:24

Re: Block IP Pattern (With Spaces)
 
Quote:

Originally Posted by Relaxing (Post 2661919)
#define PATTERN "(\d.*){9}"
I would recommend you this. It turns true when you've typed 9 or more numbers on chat.
The order doesn't matter.

Ah I appreciate the method but friend, again I have to remind you its request section, not scripting help :p I can't make plugins and it would be better if it turns true after 8 or more, instead of 9 or more.

thEsp 08-05-2019 06:34

Re: Block IP Pattern (With Spaces)
 
It's more like of both, anyway the best way for checking regex patterns is using a web-tool called RegexR.

Relaxing 08-05-2019 09:16

Re: Block IP Pattern (With Spaces)
 
A quick search: https://forums.alliedmods.net/showpo...17&postcount=3
Code:
#include <amxmodx> #include <regex> #define PATTERN "(\d.*){8}" new Regex:re, ret; public plugin_init(){     register_clcmd("say", "clcmd_say");     register_clcmd("say_team", "clcmd_say");         new err[32];     re = regex_compile(PATTERN, ret, err, 31, "i");     if (re!=REGEX_OK) log_amx("Error: %s (%d)", err, ret); } public plugin_end() {     regex_free(re);    } public clcmd_say(id){     new arg[64];     read_args(arg, charsmax(arg));         remove_quotes(arg);     trim(arg);         if (strlen(arg) > 7){         new match = regex_match_c(arg, re, ret);         if (match > 0){             return PLUGIN_HANDLED;         }     }     return PLUGIN_CONTINUE; }

Alber9091 08-05-2019 11:37

Re: Block IP Pattern (With Spaces)
 
Quote:

Originally Posted by edon1337 (Post 2661991)
I don't know about Regex but both of these ideas will return false positives sometimes.

Idea #1: If someone writes 123.. the code will think he's advertising an IP, but he isn't.
Idea #2: If someone writes 123456789 , the code will also think he's advertising, but in fact he isn't.

Sorry, just saw your message, yes that's true, but there is no another solution to avoid this !! If you have any idea, please share.

Alber9091 08-05-2019 11:39

Re: Block IP Pattern (With Spaces)
 
Quote:

Originally Posted by thEsp (Post 2661996)
It's more like of both, anyway the best way for checking regex patterns is using a web-tool called RegexR.

Can you make one? With good idea? So, IPs with spaces can be avoided. Thanks.

Alber9091 08-05-2019 11:42

Re: Block IP Pattern (With Spaces)
 
Quote:

Originally Posted by Relaxing (Post 2662022)
A quick search: https://forums.alliedmods.net/showpo...17&postcount=3
Code:
#include <amxmodx> #include <regex> #define PATTERN "(\d.*){8}" new Regex:re, ret; public plugin_init(){     register_clcmd("say", "clcmd_say");     register_clcmd("say_team", "clcmd_say");         new err[32];     re = regex_compile(PATTERN, ret, err, 31, "i");     if (re!=REGEX_OK) log_amx("Error: %s (%d)", err, ret); } public plugin_end() {     regex_free(re);    } public clcmd_say(id){     new arg[64];     read_args(arg, charsmax(arg));         remove_quotes(arg);     trim(arg);         if (strlen(arg) > 7){         new match = regex_match_c(arg, re, ret);         if (match > 0){             return PLUGIN_HANDLED;         }     }     return PLUGIN_CONTINUE; }

I will use it, till yet any other ideas are shared, between can you add message, If IP Pattern found, say: 8 or More digits are not allowed in a single message to avoid IP spam.
+ Can you add Whitelist, so I can whitelist my servers own IPs?

Relaxing 08-05-2019 12:15

Re: Block IP Pattern (With Spaces)
 
Code:
#include <amxmodx> #include <regex> #define PATTERN "(\d.*){8}" new whitelist[][] = {     "123.456.789.101:27099",     "123.456.789.101",     "yeah" } new Regex:re, ret; public plugin_init(){     register_clcmd("say", "clcmd_say");     register_clcmd("say_team", "clcmd_say");         new err[32];     re = regex_compile(PATTERN, ret, err, 31, "i");     if (re!=REGEX_OK) log_amx("Error: %s (%d)", err, ret); } public plugin_end() {     regex_free(re);    } public clcmd_say(id){     new arg[64], bool: whitestlist;     read_args(arg, charsmax(arg));         remove_quotes(arg);     trim(arg);         for (new i = 0; i < sizeof(whitelist); i++){         if (contain(arg, whitelist[i])){             whitestlist = true;             break;         }     }         if (strlen(arg) > 7 && !whitestlist){         new match = regex_match_c(arg, re, ret);         if (match > 0){             client_print(id, print_chat, "More digits are not allowed in a single message to avoid IP spam.")             return PLUGIN_HANDLED;         }     }     return PLUGIN_CONTINUE; }


All times are GMT -4. The time now is 18:42.

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