Raised This Month: $ Target: $400
 0% 

is worth and possible cache user ip and auth in index as global string var?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 08-03-2013 , 12:48   is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #1

Well i got my custom plugin its about 4k lines and i thinking about few simple optimisations so get_user_ip and get_user_authid exists in 11 functions its useless to getting same results for same id everytime its called. As far i have done research that calling such things may cause cpu usage, why just don't save it to memory for every player index, on client putinserver event it could be cached to an string variable, as player disconnect called client disconnect event, the ip and authid will be reseted to zero. Also its impossible that authid or ip can be changed in realtime @server.


Okay for the questions..

Is this worth (i see less cpu chokes, slutters, less cpu usage)?

Is this possible (cache ip and auth in player index (global string variable))?

I know that this will use a bit more memory, can i expect memory garbages?

Last edited by seriousspot; 08-03-2013 at 12:51.
seriousspot is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-03-2013 , 12:51   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #2

Quote:
Originally Posted by seriousspot View Post
Is this worth (i see less cpu chokes, slutters, less cpu usage)?
Probably not, but it depends on the number of times it gets called in total

Quote:
Is this possible (cache ip and auth in player index (global variable))?
Yes
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 08-03-2013 , 13:07   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
Probably not, but it depends on the number of times it gets called in total
as expecting caching it one and the only time in client putinserver event


and how about memory garbages?
seriousspot is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-03-2013 , 14:40   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #4

Quote:
Originally Posted by seriousspot View Post
as expecting caching it one and the only time in client putinserver event
What I meant was it all depends on how many times you call get_user_ip or get_user_authid throughout the life of that players connection.


Quote:
and how about memory garbages?
Don't understand the question, hence why I didn't answer it
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 08-03-2013 , 15:28   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
What I meant was it all depends on how many times you call get_user_ip or get_user_authid throughout the life of that players connection.



Don't understand the question, hence why I didn't answer it
alot of times, its management, technical, stastics, admin AIO plugin


memory leaks*, I am sorry
seriousspot is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-03-2013 , 15:47   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #6

PHP Code:
#include < amxmodx >

public plugin_init()
{
    
register_clcmd("say /info""ClCmd_Say_Info");
}

GGETPLAYERAUTHID(idbGet false)
{
    static 
szAuthid[33][32];
    if( 
bGet )
    {
        
get_user_authid(idszAuthid[id], charsmax(szAuthid[]));
    }
    return 
szAuthid[id];
}

public 
client_connect(id)
{
    
GETPLAYERIP(idtrue);
}

public 
client_authorized(id)
{
    
GGETPLAYERAUTHID(idtrue);
}

GETPLAYERAUTHID(idbGet false)
{
    static 
szAuthid[33][32];
    if( 
bGet )
    {
        
get_user_authid(idszAuthid[id], charsmax(szAuthid[]));
    }
    return 
szAuthid[id];
}

GETPLAYERIP(idbGet false)
{
    static 
szAddress[33][16];
    if( 
bGet )
    {
        
get_user_ip(idszAddress[id], charsmax(szAddress[]), 1);
    }
    return 
szAddress[id];
}

public 
ClCmd_Say_Info(id)
{
    
client_print(idprint_chat"Your IP is ^"%s^" and your SteamID is ^"%s^""GETPLAYERIP(id), GETPLAYERAUTHID(id));
}

// function in which you need to use steamid more that one and ip more than once :
public function( id )
{
    static 
szAuthid[32], szIp[16];
    
szAuthid GETPLAYERAUTHID(id);
    
szIp GETPLAYERIP(id);

    if( !(
'0' <= szAuthid[10] <= '9') && !IsLocalIpszIp ) )
    {
        
client_print(idprint_chat"Your IP is ^"%s^" and your SteamID is ^"%s^" tell us you are not using steam"szIpszAuthid);
    }
}

IsLocalIp( const IP[] )
{
    return 
false;

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-04-2013 , 02:15   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #7

Regex is NOT a more efficient method and should not be used here since the possible outputs of get_user_authid() and get_user_ip() are very limited (in fact, the IP output from the function will always be valid). Connor's method will be more efficient.
__________________

Last edited by fysiks; 08-04-2013 at 05:00.
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-04-2013 , 04:56   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #8

But you can use global variables as you did, also steamid array size doesn't need to be 64, 32 is enough.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 08-04-2013 , 09:31   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
Regex is NOT a more efficient method and should not be used here since the possible outputs of get_user_authid() and get_user_ip() are very limited (in fact, the IP output from the function will always be valid). Connor's method will be more efficient.
In some cases you're right, but about auth it depends where plugin is used, there are few questions from me

Is player can successfully connect to a server without unauthorized auth, like VALVE_ID_PENDING or STEAM_ID_PENDING ? i just need clear my minds is aditional check useless . And about ip, is player can connect to server with ipv6 or diffrent kind of ip ?

How to reset ip or auth variable for each id on client_disconnect event or its useless?
seriousspot is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-04-2013 , 20:40   Re: is worth and possible cache user ip and auth in index as global string var?
Reply With Quote #10

Quote:
Originally Posted by seriousspot View Post
In some cases you're right, but about auth it depends where plugin is used, there are few questions from me

Is player can successfully connect to a server without unauthorized auth, like VALVE_ID_PENDING or STEAM_ID_PENDING ? i just need clear my minds is aditional check useless.
You can check for those individually and it will likely be more efficient than having to check for a pattern. Hence why I said there are only a few types of output (a steam ID, pending, lan). For that matter, you can just check the 7th character to see if it is a zero. If it's a zero, it's a SteamID.


Quote:
Originally Posted by seriousspot View Post
And about ip, is player can connect to server with ipv6 or diffrent kind of ip ?
If it's IPv6 (which will probably never happen), it's still an IP. What is a "diffrent kind of ip"???? If they don't have a valid IP then they wouldn't be connecting to the internet.

Quote:
Originally Posted by seriousspot View Post
How to reset ip or auth variable for each id on client_disconnect event or its useless?
To reset a string, you simply set the first character to zero (0): szVariable[0] = 0 and for an array of strings: szArrayOfStrings[string_index][0] = 0
__________________
fysiks 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 15:58.


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