|
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
|

08-03-2013
, 16:25
Re: is worth and possible cache user ip and auth in index as global string var?
|
#4
|
Quote:
Originally Posted by ConnorMcLeod
PHP Code:
#include < amxmodx >
public plugin_init() { register_clcmd("say /info", "ClCmd_Say_Info"); }
GGETPLAYERAUTHID(id, bGet = false) { static szAuthid[33][32]; if( bGet ) { get_user_authid(id, szAuthid[id], charsmax(szAuthid[])); } return szAuthid[id]; }
public client_connect(id) { GETPLAYERIP(id, true); }
public client_authorized(id) { GGETPLAYERAUTHID(id, true); }
GETPLAYERAUTHID(id, bGet = false) { static szAuthid[33][32]; if( bGet ) { get_user_authid(id, szAuthid[id], charsmax(szAuthid[])); } return szAuthid[id]; }
GETPLAYERIP(id, bGet = false) { static szAddress[33][16]; if( bGet ) { get_user_ip(id, szAddress[id], charsmax(szAddress[]), 1); } return szAddress[id]; }
public ClCmd_Say_Info(id) { client_print(id, print_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') && !IsLocalIp( szIp ) ) { client_print(id, print_chat, "Your IP is ^"%s^" and your SteamID is ^"%s^" tell us you are not using steam", szIp, szAuthid); } }
IsLocalIp( const IP[] ) { return false; }
|
done myself i think more efficient way, but on client_disconnect don't know how to reset
PHP Code:
#include <amxmodx> #include <regex>
#define REGEX_IP "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" #define REGEX_AUTH "^^STEAM_0:(0|1):\d+$"
#define is_valid_ip(%1) (regex_match_c(%1, regex_ip, regex_return) > 0) #define is_valid_auth(%1) (regex_match_c(%1, regex_auth, regex_return) > 0)
new Regex:regex_ip, Regex:regex_auth, regex_return, g_AUTH[33][64], g_IP[33][16]
public plugin_init() { // regex stuff new error[2] regex_ip = regex_compile(REGEX_IP, regex_return, error, charsmax(error)) regex_auth = regex_compile(REGEX_AUTH, regex_return, error, charsmax(error)) // testing register_concmd("/test", "echo") }
public client_authorized(id) { new AUTH[64] // future proof get_user_authid(id, AUTH, charsmax(AUTH)) if (is_valid_auth(AUTH)) { g_AUTH[id] = AUTH } else { // client is not authorized return 1 } return 0 }
public client_connect(id) { new IP[16] get_user_ip(id, IP, charsmax(IP), 1) if (is_valid_ip(IP)) { g_IP[id] = IP } else { // client ip is not valid return 1 } return 0 }
/*
TODO
public client_disconnect(id) { new null = 0 g_AUTH[id] = null g_IP[id] = null }
*/
public echo(id) { client_print(id, print_console, "AUTH: %s, IP: %s", g_AUTH[id], g_IP[id]) }
Last edited by seriousspot; 08-03-2013 at 16:26.
|
|