Raised This Month: $32 Target: $400
 8% 

Solved Getting userid sourcemod


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rushy
AlliedModders Donor
Join Date: Jul 2015
Location: Melbourne, Australia
Old 09-19-2016 , 09:54   Getting userid sourcemod
Reply With Quote #1

Hi,

Wondering what is the correct method to get a clients userid?

I want to get a clients userid and combine it with the sm_freeze command, I was using a clients name however it seems to not like clients with a space in their nickname

Last edited by Rushy; 09-19-2016 at 10:22.
Rushy is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-19-2016 , 09:56   Re: Getting userid sourcemod
Reply With Quote #2

You can use GetClientUserId to get a client's user id. If you want to use a name with spaces you probably need to use use quotation marks around it. Looking at how sm_freeze is implemented might be of interesting too.
__________________

Last edited by Impact123; 09-19-2016 at 10:03.
Impact123 is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 09-19-2016 , 10:03   Re: Getting userid sourcemod
Reply With Quote #3

What do you mean? Most functions in sourcemod use the Client's Index which can be gotten from the userid through the function: GetClientOfUserId

Most "targeting" functions return a client index rather then the userid, which is then used for other shit.

FindTarget(0, nametocheckagainst);

FindTarget returns a client index if it finds someone, otherwise it returns -1.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 09-19-2016 at 10:04.
OSWO is offline
Rushy
AlliedModders Donor
Join Date: Jul 2015
Location: Melbourne, Australia
Old 09-19-2016 , 10:06   Re: Getting userid sourcemod
Reply With Quote #4

Quote:
Originally Posted by Impact123 View Post
You can use GetClientUserId to get a client's user id. If you want to use a name with spaces you probably need to use use quotation marks around it. Looking at how sm_freeze is implemented might be of interesting too.
Thanks.

I have tried the quotation marks in the console and it works. What would be the correct way in code

ServerCommand("sm_freeze "%N" 15", client);

That way fails to compile with the quotes around %N
Rushy is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-19-2016 , 10:10   Re: Getting userid sourcemod
Reply With Quote #5

You need to escape the character(s) like this
PHP Code:
ServerCommand("sm_freeze \"%N\" 15"client); 
__________________

Last edited by Impact123; 09-19-2016 at 10:14.
Impact123 is offline
Rushy
AlliedModders Donor
Join Date: Jul 2015
Location: Melbourne, Australia
Old 09-19-2016 , 10:17   Re: Getting userid sourcemod
Reply With Quote #6

Quote:
Originally Posted by Impact123 View Post
You need to escape the character(s) like this
PHP Code:
ServerCommand("sm_freeze \"%N\" 15"client); 
Many Thanks
Rushy is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 09-19-2016 , 10:31   Re: Getting userid sourcemod
Reply With Quote #7

Never ever EVER pass a client's name to ServerCommand, doing so runs the risk of your server getting remote command exeuction, example:
  1. Client's Name: "\"; quit; \""
  2. ServerCommand (when formatted) becomes: "sm_freeze \"\"; quit; \"\""
  3. Server executes sm_freeze with 1 string arg reading ""
  4. Server executes the quit command with 0 args
  5. Server shuts down because of "quit" command.

Always pass a userid to ServerCommand, example:
PHP Code:
ServerCommand("sm_freeze #%d 15"GetClientUserId(client)); 
__________________

Last edited by WildCard65; 09-19-2016 at 13:25.
WildCard65 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-19-2016 , 12:54   Re: Getting userid sourcemod
Reply With Quote #8

Indeed!
Quote:
Originally Posted by WildCard65 View Post
Never ever EVER pass a client's name to ServerCommand, doing so runs the risk of your server getting remote command exeuction
...

Always pass a userid to ServerCommand
...
ServerCommand Exploits

Last edited by Bacardi; 09-19-2016 at 12:56.
Bacardi is offline
Rushy
AlliedModders Donor
Join Date: Jul 2015
Location: Melbourne, Australia
Old 09-19-2016 , 13:02   Re: Getting userid sourcemod
Reply With Quote #9

Cheers for that WildCard. You have indeed saved me, I am now using userid's
Rushy 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 23:19.


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