Raised This Month: $ Target: $400
 0% 

get_user_name and null strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rain
Senior Member
Join Date: Oct 2004
Location: Poland
Old 10-17-2004 , 15:35   get_user_name and null strings
Reply With Quote #1

How can I determine wheter get_user_name() provides me with a real valid player name or a (null) string? As a natural way I thought about the return value of this function, but in fact it returns the set_amxstring return value ;-) which is not what I want. I know this kind of checks is not *that* needed, but I like to write 100% reliable progs/scripts (ya, just my habit :-)). TIA for any replies.
__________________

Last edited by rain; 10-07-2007 at 10:09.
rain is offline
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 10-17-2004 , 16:03  
Reply With Quote #2

strlen(name) > 0?
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
rain
Senior Member
Join Date: Oct 2004
Location: Poland
Old 10-17-2004 , 16:10  
Reply With Quote #3

Nope, tried this. It returns 6. ;-) I don't know why, but non-existent names are returned not as real null strings, but sth like this:

name[0] = '('
name[1] = 'n'
name[2] = 'u'
name[3] = 'l'
name[4] = 'l'
name[5] = ')'

Haven't checked it on the latest amxx yet, so don't how it looks there. The strlen looks reasonable and I was a bit surprised to find this kind of strings. Dind't dig to the code that deep either, I will later check where it gets changed.
__________________

Last edited by rain; 10-07-2007 at 10:09.
rain is offline
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 10-17-2004 , 17:35  
Reply With Quote #4

In what case can you get a null name anyway?
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
rain
Senior Member
Join Date: Oct 2004
Location: Poland
Old 10-18-2004 , 10:29  
Reply With Quote #5

I think that specifying an invalid player ID can result in a null name (try calling get_user_name() with a bogus id).

What I make is:
Code:
// [...] function1() {    new players[32]    new playerCount        /* This is point 1 */    get_players(players, playerCount, "c")    // [...] Then I choose the best player (highest fragcount) and pass his ID to another function which prints his name on screen    function2(id) } function2(id) {    new name[32]        /* This is point 2 */    get_user_name(id, name, 32)    set_hudmessage(200, 100, 0, -1.0, 0.85, 0, 6.0, 10.0, 0.1, 0.2, 3)    show_hudmessage(0, name) }

Well, I know that it is almost impossible for a player to leave in the time occuring between points 1 and 2, but I wouldn't call it a 100% reliable method (or I just don't get it, are there any limits on get_user_name calls?). It doesn't seem to be a problem really, cause it's a simple plugin (the execution time between 1 and 2 should be near 0), so it's not that dangerous. Nevertheless, it's a flaw in a plugin, which I would like to avoid. If it's not possible - nevermind, I will write it the way you all do. ;-)
__________________

Last edited by rain; 10-07-2007 at 10:09.
rain is offline
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 10-18-2004 , 17:47  
Reply With Quote #6

is_valid_user(id)
Just check if the user is valid with that, and if its not, don't try to display the name
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 10-18-2004 , 18:50  
Reply With Quote #7

hmm?
Code:
is_user_connected(id) is_valid_ent(id)
Johnny got his gun is offline
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 10-18-2004 , 19:21  
Reply With Quote #8

is_user_connnected is the one I meant
Couldn't think of the name, and is_valid_user seemed right
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
rain
Senior Member
Join Date: Oct 2004
Location: Poland
Old 10-19-2004 , 09:01  
Reply With Quote #9

Well, yes. But I thought get_players() itself would return valid IDs. I just did not want to split the two operations which IMHO should be combined - validation of ID and its use to get playername. OK, I know I am messing things a bit and I am not clear. Just downloaded the amxx's source code, give me a minute, maybe I will come up with sth more precise.

UPDATE: OK, I think I've nailed down the problem. Stay tuned. ;-)
__________________

Last edited by rain; 10-07-2007 at 10:09.
rain is offline
rain
Senior Member
Join Date: Oct 2004
Location: Poland
Old 10-19-2004 , 10:19  
Reply With Quote #10

Nah, it's resolved. Lastly. My fault, sorry devicenull, you were correct. The strlen() is the way to go (obviously it seemed weird it didn't work). Just forgot the first 'bug reporting' rule - update your sources. Everything is fine on amxx 0.20 and CVS. The thing is I've used an old version - 0.16 and the String handling there, well - let's say could be improved (and in fact it did, thx guys).

Just look at this line of CString.h (old):
Code:
inline const char* str() const {  return napis ? napis : "(null)"; }
And now (the new one):
Code:
const char *c_str() { return v?v:""; }
const char *c_str() const { return v?v:""; }
This is what I was looking for. Thank you for helping me resolve this issue.
__________________

Last edited by rain; 10-07-2007 at 10:09.
rain 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 17:16.


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