It's posible to receive played hours(for another name) from gametracker with socket?
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <sockets>
new g_PlayerQuest;
#define SetBit(%0) (g_PlayerQuest |= (1 << (1 & 31)))
#define ClearBit(%0) (g_PlayerQuest &= ~(1 << (1 & 31)))
#define CheckBit(%0) (g_PlayerQuest & (1 << (1 & 31)))
#define FAIL 123
new g_szHost[ ] = "gametracker.com";
new g_socket[ 32 ]; // Every player handle
new g_serverip[ 22 ];
new g_enable, g_request;
public plugin_init() {
register_plugin( "GT Hour", "0.0.5", "Dwight" );
g_enable = register_cvar( "GTh_enable", "1" );
g_request = register_cvar( "GTh_request", "5.0" );
get_user_ip(0, g_serverip, charsmax( g_serverip ), 0);
register_concmd( "amx_gt", "ConCMD_GT", ADMIN_KICK, "< name / # userid >" );
// Can get hour without connected player.
register_clcmd( "say /hour", "ClCMD_GT" );
}
public ConCMD_GT(id, level, cid) {
if( !cmd_access(id, level, cid, 2) || !get_pcvar_num( g_enable ) )
return PLUGIN_HANDLED;
if( CheckBit( id ) ) {
console_print( id, "Another quest is sending now. Please wait for get information and end process !" );
return PLUGIN_HANDLED;
}
else
SetBit( id );
new arg[ 32 ];
read_argv( 1, arg, charsmax( arg ) );
new player = cmd_target( id, arg, CMDTARGET_NO_BOTS | CMDTARGET_ALLOW_SELF );
if( !( 1 <= player <= get_maxplayers() ) ) {
console_print(id, "This player is invalid !");
return PLUGIN_HANDLED;
}
new name[ 32 ], error, sendbuffer[ 512 ];
get_user_name( player, name, charsmax(name) );
new topic[ 100 ];
format( topic, charsmax( topic ), "/player/%s/%s/", name,g_serverip );
// Connect, quest for amx_gt own command...not for player target...
g_socket[ id ] = socket_open( g_szHost, 80, SOCKET_TCP, error );
// If found error.
switch( error ) {
case 1: {
console_print( id, "Unable to create socket, close quest !" );
return PLUGIN_HANDLED;
}
case 2: {
console_print( id, "Unable to connect Gametracker Server, close quest !" );
return PLUGIN_HANDLED;
}
case 3: {
console_print( id, "Unable to connect to the HTTP port, close quest !" );
return PLUGIN_HANDLED;
}
}
console_print( id, "Please wait (%d seconds) to receive hour !", 1+floatround(get_pcvar_float( g_request )) );
format( sendbuffer, charsmax( sendbuffer ), "GET %s HTTP/1.1^nHost:%s^r^n^r^n", topic, g_szHost);
socket_send( g_socket[ id ], sendbuffer, charsmax( sendbuffer ) );
set_task( 1.0, "CheckReceive", id, name, charsmax( name ), "a", floatround(get_pcvar_float( g_request )) );
set_task( 1.0 + get_pcvar_float( g_request ), "CloseQSocket", id+FAIL );
return PLUGIN_HANDLED;
}
public ClCMD_GT( id ) {
if( !get_pcvar_num( g_enable ) || is_user_bot( id ) || is_user_hltv( id ) )
return PLUGIN_HANDLED;
if( CheckBit( id ) ) {
client_print_color( id, GREY, "Another quest is sending now. Please wait for get information and end process !" );
return PLUGIN_HANDLED;
}
else
SetBit( id );
new name[ 32 ], error, sendbuffer[ 512 ];
get_user_name( id, name, charsmax(name) );
new topic[ 100 ];
format( topic, charsmax( topic ), "/server_info/%s/top_players/?query=%s&Search=Search", g_serverip, name );
// Connect, quest for amx_gt own command...not for player target...
g_socket[ id ] = socket_open( g_szHost, 80, SOCKET_TCP, error );
// If found error.
switch( error ) {
case 1: {
client_print_color( id, GREY, "Unable to create socket, close quest !" );
return PLUGIN_HANDLED;
}
case 2: {
client_print_color( id, GREY, "Unable to connect Gametracker Server, close quest !" );
return PLUGIN_HANDLED;
}
case 3: {
client_print_color( id, GREY, "Unable to connect to the HTTP port, close quest !" );
return PLUGIN_HANDLED;
}
}
client_print_color( id, GREY, "Please wait (%d seconds) to receive hour !", 1+floatround(get_pcvar_float( g_request )) );
format( sendbuffer, charsmax( sendbuffer ), "GET %s HTTP/1.1^nHost:%s^r^n^r^n", topic, g_szHost);
socket_send( g_socket[ id ], sendbuffer, charsmax( sendbuffer ) );
set_task( 1.0, "CheckReceive", id, name, charsmax( name ), "a", floatround(get_pcvar_float( g_request )) );
set_task( 1.0 + get_pcvar_float( g_request ), "CloseQSocket", id+FAIL );
return PLUGIN_HANDLED;
}
public CheckReceive( name[], id ) {
if( socket_change( g_socket[ id ] ) ) {
new g_data[ 1000 ];
socket_recv( g_socket[ id ], g_data, charsmax( g_data ) );
new Position = containi( g_data, "Minutes Played: " );
if( Position < 1 )
return;
Position += strlen( "Minutes Played: " );
new sz_hour[ 11 ], lenght = 0;
for( new i = 0;i <= 10;i++ ) {
if ('0' <= g_data[Position + i] <= '9' || g_data[Position + i] == '.') {
sz_hour[ lenght ] = g_data[ Position + i];
lenght++;
}
}
console_print( id, "GameTracker:^nName:%s^nHours:%s^n",name, str_to_num(sz_hour)/60 );
client_print_color( id, GREY, "Name:%s | Hours:%s",name, str_to_num(sz_hour)/60 );
socket_close( g_socket[ id ] );
remove_task( id );
remove_task( id+FAIL );
ClearBit( id );
}
}
public CloseQSocket( task ) {
new id = task - FAIL;
console_print( id, "Server not responding!" );
client_print_color( id, GREY, "Server not responding!" );
socket_close( g_socket[ id ] );
}
public client_disconnect( id ) {
if( CheckBit( id ) ) {
socket_close( g_socket[ id ] );
remove_task( id );
remove_task( id+FAIL );
ClearBit( id );
}
return PLUGIN_CONTINUE;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
It's not posible or my plugin is wrong coded.. ?