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

GetClientName can't function properly while name contains percent sign


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
22920206
Junior Member
Join Date: Feb 2011
Old 10-17-2012 , 13:22   GetClientName can't function properly while name contains percent sign
Reply With Quote #1

It doesn't seems to be able to get the percent sign
So when a player name is "123%123" it only get "123123"
How could I get the sign properly?
22920206 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-17-2012 , 13:50   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #2

Quote:
Originally Posted by 22920206 View Post
It doesn't seems to be able to get the percent sign
So when a player name is "123%123" it only get "123123"
How could I get the sign properly?
The problem isn't with GetClientName, but instead when you go to print it using any of the print functions. This is because % is a special character in Format-type statements like Format, PrintToChat, PrintHintText, PrintCenterText, etc...

I'd recommend using the %N format specifier and pass the client ID, which will automatically print the client's name without having to use GetClientName.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-17-2012 at 13:51.
Powerlord is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-17-2012 , 15:26   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #3

Source game(s) not support % character in player names, and there was another symbols.
Old exploit.
Bacardi is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 10-17-2012 , 16:20   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #4

When you pass a string to a format function as format parameter that has a %, you have to escape it of course, that is not an exploit.

PHP Code:
newString:str[] = "String with % in it";
ReplaceString(strsizeof(str), "%""%%");
PrintToServer(str); 
However when you pass the string as variable argument, it should work correctly anyway I think.
Like this:

PHP Code:
PrintToServer("%s"str); 
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 10-17-2012 at 16:21.
berni is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 10-17-2012 , 17:39   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #5

Quote:
Originally Posted by berni View Post
PHP Code:
newString:str[] = "String with % in it";
ReplaceString(strsizeof(str), "%""%%");
PrintToServer(str); 
Never, ever, ever, ever, ever, ever, ever do this.

Quote:
Originally Posted by berni View Post
PHP Code:
PrintToServer("%s"str); 
Do this.
__________________
asherkin is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 10-17-2012 , 17:41   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
Never, ever, ever, ever, ever, ever, ever do this.


Do this.
Is that because the former may lack a null terminator or something?
__________________

Last edited by 11530; 10-17-2012 at 17:41.
11530 is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 10-17-2012 , 18:44   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #7

It is bad because you may shorten the players name accidentally.
Also think of applying this replacement for a second time, or even a third one.

Last edited by Chrisber; 10-17-2012 at 18:44.
Chrisber is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 10-17-2012 , 19:17   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #8

Quote:
Originally Posted by 11530 View Post
Is that because the former may lack a null terminator or something?
The 2nd completely sanitises the string and is a lot faster, the former targets a specific issue.
__________________
asherkin is offline
22920206
Junior Member
Join Date: Feb 2011
Old 10-17-2012 , 23:03   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #9

Thank everyone's reply. I should have been more specific that I actually want to compare that string with another string, this is generally how my code look like:
PHP Code:
    new String:nickname[36];
    
GetClientName(client,    nickname,    sizeof(nickname));

    while(!
IsEndOfFile(KickFile))    {
        
ReadFileLine(KickFilekLinesizeof(kLine));
    
       if    (
StrContains(nicknamekLinefalse) != -1)    {
       
KickClient(client"Kicked by Console");
       }
    } 
kLine is read from a txt file.
The plugin works pretty well as long as I don't test with name with % sign(and probably some other symbols too). So is there any workaround for this?

Last edited by 22920206; 10-17-2012 at 23:59.
22920206 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-17-2012 , 23:27   Re: GetClientName can't function properly while name contains percent sign
Reply With Quote #10

What happens when the name has % sign? I don't see bugs in your code.
__________________

Last edited by FaTony; 10-17-2012 at 23:27.
FaTony 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 09:17.


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