Raised This Month: $ Target: $400
 0% 

get user name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
D3XT3R
AlliedModders Donor
Join Date: Nov 2016
Location: Lithuania, Bomb A (Kauna
Old 06-18-2017 , 10:16   get user name
Reply With Quote #1

Hi, i have some bugs with this script so can tell me what is wroung?

Script to get user name, red line is the problem in logs
PHP Code:
stock get_user_name_ex(id)
{
    new 
szName[33];
    
get_user_name(idszNamecharsmax(szName));

    
replace_all(szNamecharsmax(szName), "'""\'");
    
replace_all(szNamecharsmax(szName), "^"", "\^"");
    
replace_all(szNamecharsmax(szName), ".""");
    
    return 
szName;

Line Error in Log (1842)
Quote:
replace_all(szName, charsmax(szName), "'", "\'");
Log:
Quote:
L 06/18/2017 - 113:03: replace() buffer not big enough (12>=11)
L 06/18/2017 - 113:03: [AMXX] Displaying debug trace (plugin "gunxpmod.amxx", version "4.3.5")
L 06/18/2017 - 113:03: [AMXX] Run time error 10: native error (native "replace")
L 06/18/2017 - 113:03: [AMXX] [0] string.inc::replace_all (line 340)
L 06/18/2017 - 113:03: [AMXX] [1] gunxpmod.sma::get_user_name_ex (line 1842)
L 06/18/2017 - 113:03: [AMXX] [2] gunxpmod.sma::check_level (line 881)
L 06/18/2017 - 113:03: [AMXX] [3] gunxpmod.sma::native_set_user_xp (line 1757)
L 06/18/2017 - 113:03: Unhandled dynamic native error
__________________

Last edited by D3XT3R; 06-18-2017 at 10:19.
D3XT3R is offline
Send a message via Skype™ to D3XT3R
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 06-18-2017 , 10:23   Re: get user name
Reply With Quote #2

Problem is that sometimes you are replacing one character with two characters, and let's say a player has a name of length 32 which is max, but 5 of the chars are ', then you need length 37 to store the replaced version.

easy fix is to change szName[33] (which should be 32 anyways) to szName[64] but this will sometimes clip the player's name if you try to set his name to the newly generated name, since it's too long for the game


also, you must never return a string in AMXX
you must pass the array via reference which will edit the original array

PHP Code:

public using_the_stock(id) {
    new 
theName[64];
    
get_user_name_ex(idtheNamecharsmax(theName));
}

stock get_user_name_ex(idszName[], len)
{
    
get_user_name(idszNamelen);

    
replace_all(szNamelen"'""\'");
    
replace_all(szNamelen"^"", "\^"");
    
replace_all(szNamelen".""");

__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 06-18-2017 at 10:31.
aron9forever is offline
D3XT3R
AlliedModders Donor
Join Date: Nov 2016
Location: Lithuania, Bomb A (Kauna
Old 06-18-2017 , 10:31   Re: get user name
Reply With Quote #3

best option is i remove replacing characters or i change chars to 64
__________________
D3XT3R is offline
Send a message via Skype™ to D3XT3R
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 06-18-2017 , 10:41   Re: get user name
Reply With Quote #4

Quote:
Originally Posted by D3XT3R View Post
best option is i remove replacing characters or i change chars to 64
see my final edited answer, I've edited it quite a lot maybe you missed some stuff

may I ask why you're doing this filtering?
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
D3XT3R
AlliedModders Donor
Join Date: Nov 2016
Location: Lithuania, Bomb A (Kauna
Old 06-18-2017 , 10:52   Re: get user name
Reply With Quote #5

Quote:
Originally Posted by aron9forever View Post
see my final edited answer, I've edited it quite a lot maybe you missed some stuff

may I ask why you're doing this filtering?
using a save for gunxpmod for ip / nick / steamid for save thier xp and filtering for illegal names whitch has ² ... whitch mysql system not allowded them...
ps: i didnt understand any thing from yours answer and why no return in AMXX?
__________________
D3XT3R is offline
Send a message via Skype™ to D3XT3R
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-18-2017 , 13:36   Re: get user name
Reply With Quote #6

Quote:
Originally Posted by D3XT3R View Post
ps: i didnt understand any thing from yours answer and why no return in AMXX?
There is a reason that get_user_name() requires the string to be passed as an argument with a length argument. You should do that exact same thing with your custom name function.
__________________
fysiks is offline
D3XT3R
AlliedModders Donor
Join Date: Nov 2016
Location: Lithuania, Bomb A (Kauna
Old 06-18-2017 , 10:53   Re: get user name
Reply With Quote #7

PHP Code:
stock get_user_name_ex(id)
{
    new 
szName[33];
    
get_user_name(idszNamecharsmax(szName));

    
replace_all(szNamecharsmax(szName), "'""\'");
    
replace_all(szNamecharsmax(szName), "^"", "\^"");
    
replace_all(szNamecharsmax(szName), ".""");
    
    return 
szName;
}

stock get_user_ip_ex(id)
{
    new 
szIP[33];
    
get_user_ip(idszIPcharsmax(szIP), 1);
    
    return 
szIP;
}

stock get_user_authid_ex(id)
{
    new 
szAuthid[33];
    
get_user_authid(idszAuthid32);
    
    return 
szAuthid;

__________________

Last edited by D3XT3R; 06-18-2017 at 10:53.
D3XT3R is offline
Send a message via Skype™ to D3XT3R
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 06-18-2017 , 18:02   Re: get user name
Reply With Quote #8

Quote:
Originally Posted by D3XT3R View Post
PHP Code:
replace_all(szNamecharsmax(szName), "."""); 
This is very bad, because it makes "Pla.yer" and "Player" nicknames the same, so there will be a conflict.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 06-19-2017 , 08:22   Re: get user name
Reply With Quote #9

Here's a stock for preventing mysql injection
It prevents all problems but requires a buffer size x3 the original size

here's how you use it

PHP Code:
    new nume[96];
    
get_user_name(idnumecharsmax(nume));
    
mysql_escape_string(numecharsmax(nume));
    
//nume is now safe to use in a query

stock mysql_escape_string(dest[], len) {
    
replace_all(destlen"\\""\\\\");
    
replace_all(destlen"\0""\\0");
    
replace_all(destlen"\n""\\n");
    
replace_all(destlen"\r""\\r");
    
replace_all(destlen"\x1a""\Z");
    
replace_all(destlen"'""\'");
    
replace_all(destlen"^"", "\^"");

theres no need to replace players names to be SQL safe, just filter every user input before running queries
I'll say it one more time; returning strings the way you're trying to is not supported in pawn
I doubt a full explanation of why would do you any good(and I can't give it to you because I don't know) but the fact that you can't find a single function that returns a string in the entirety of amxmodx should be a hint.
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 06-19-2017 at 08:35.
aron9forever is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 06-19-2017 , 13:32   Re: get user name
Reply With Quote #10

Quote:
Originally Posted by aron9forever View Post
PHP Code:
stock mysql_escape_string(dest[], len) {
    
replace_all(destlen"\\""\\\\");
    
replace_all(destlen"\0""\\0");
    
replace_all(destlen"\n""\\n");
    
replace_all(destlen"\r""\\r");
    
replace_all(destlen"\x1a""\Z");
    
replace_all(destlen"'""\'");
    
replace_all(destlen"^"", "\^"");

It is incorrect. Just use SQL_QuoteString, don't write your own implementations.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
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 22:44.


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