Raised This Month: $51 Target: $400
 12% 

Why not works? ((((


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
karaulov
Senior Member
Join Date: Jul 2018
Old 10-13-2019 , 15:08   Why not works? ((((
Reply With Quote #1

Code:
#include <amxmodx>
#include <amxmisc>
#include <regex> 

public plugin_init() {
	register_plugin("No bad usernames", "1", "KARAULOV");
	set_task(1.0, "bad_checker", _, _, _, "b");
}

public bad_checker(xxx)
{ 
	new i;
	new mUserName[64] 
	new players[32], count
	get_players(players, count)
	for(i = 0; i < count; i++)
	{
		new id = players[i]
		get_user_name(id, mUserName, charsmax(mUserName))
		new userid = get_user_userid( id );
		new ret, error[128]
		new Regex:regex_handle = regex_match(mUserName, "\d+\.\d+.\d+.\d+:", ret, error, charsmax(error))
		switch(regex_handle)
		{
			case REGEX_MATCH_FAIL:
			{
				return;
			}
			case REGEX_PATTERN_FAIL:
			{
				return;
			}
			case REGEX_NO_MATCH:
			{
				return;
			}
			default:
			{
				server_cmd( "amx_kick #%d BAD NICKNAME!", userid)
				server_print( "amx_kick %s - #%d BAD NICKNAME!", mUserName, userid)
				regex_free(regex_handle);
			}
		}
	}
}

This not kick users who contain "IP addresss: PORT" in nickname ....
karaulov is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 10-23-2019 , 20:36   Re: Why not works? ((((
Reply With Quote #2

Try this instead.
Attached Files
File Type: sma Get Plugin or Get Source (D7NameChanger122.sma - 59 views - 5.2 KB)
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
iNvectus
Member
Join Date: Sep 2014
Location: Bulgaria
Old 10-24-2019 , 01:36   Re: Why not works? ((((
Reply With Quote #3

Your regex is kinda incorrect. You have a trailing : at the end and you do nothing with it. You validate it only until 90.40.33.22: and that's it. Another thing is that you call it on plugin initialization. I'd rather do that on client_putinserver, but you know best, you are the scripter after all.

Now you have two possibilities regarding the regular expression:
Add a trailing \d+ after the : or take a look at the regex below.
PHP Code:
^(?=\d+\.\d+\.\d+\.\d+\:[0-9]{1,5}$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}\:[0-9]{1,5}$ 
What's actually happening?
We have a positive lookahead
PHP Code:
(?=\d+\.\d+\.\d+\.\d+\:[0-9]{1,5}$) 
and a non-capturing group with 5 alternatives
PHP Code:
(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9]) 
. The rest of it you can understand it yourself with all the digit validations and the range of it. You can sum 2 by 2.

So your regex would look something like the following:
PHP Code:
new Regex:regex_handle regex_match(mUserName"^(?=\d+\.\d+\.\d+\.\d+\:[0-9]{1,5}$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}\:[0-9]{1,5}$"reterrorcharsmax(error)) 
PS:
Another thing, I would also use compiled regular expressions and use regex_match, not relying on the handle itself. Just a point of view, I guess.

Last edited by iNvectus; 10-24-2019 at 01:38.
iNvectus is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:56.


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