Raised This Month: $ Target: $400
 0% 

Plugin possible or wrong?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
DWIGHTpN
Senior Member
Join Date: Jan 2013
Location: Romania.
Old 08-10-2013 , 11:42   Plugin possible or wrong?
Reply With Quote #1

It's posible to receive played hours(for another name) from gametracker with socket?

I follow OT_207 tutorial (https://forums.alliedmods.net/showthread.php?t=151401) and i make this plugin:
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_socket32 ]; // Every player handle
new g_serverip22 ];
new 
g_enableg_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(0g_serveripcharsmaxg_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(idlevelcid) {
    if( !
cmd_access(idlevelcid2) || !get_pcvar_numg_enable ) )
        return 
PLUGIN_HANDLED;
    
    if( 
CheckBitid ) ) {
        
console_printid"Another quest is sending now. Please wait for get information and end process !" );
        return 
PLUGIN_HANDLED;
    }
    else
        
SetBitid );
    
    new 
arg32 ];
    
read_argv1argcharsmaxarg ) );
    new 
player cmd_targetidargCMDTARGET_NO_BOTS CMDTARGET_ALLOW_SELF );
    
    if( !( 
<= player <= get_maxplayers() ) ) {
        
console_print(id"This player is invalid !");
        return 
PLUGIN_HANDLED;
    }
    
    new 
name32 ], errorsendbuffer512 ];
    
get_user_nameplayernamecharsmax(name) );
    new 
topic100 ];
    
formattopiccharsmaxtopic ), "/player/%s/%s/"name,g_serverip );
    
    
// Connect, quest for amx_gt own command...not for player target...
    
g_socketid ] = socket_openg_szHost80SOCKET_TCPerror );
    
    
// If found error.
    
switch( error ) {
        case 
1: {
            
console_printid"Unable to create socket, close quest !" );
            return 
PLUGIN_HANDLED;
        }
        case 
2: {
            
console_printid"Unable to connect Gametracker Server, close quest !" );
            return 
PLUGIN_HANDLED;
        }
        case 
3: {
            
console_printid"Unable to connect to the HTTP port, close quest !" );
            return 
PLUGIN_HANDLED;
        }
    }
    
    
    
console_printid"Please wait (%d seconds) to receive hour !"1+floatround(get_pcvar_floatg_request )) );
    
formatsendbuffercharsmaxsendbuffer ), "GET %s HTTP/1.1^nHost:%s^r^n^r^n"topicg_szHost);
    
socket_sendg_socketid ], sendbuffercharsmaxsendbuffer ) );
    
    
    
set_task1.0"CheckReceive"idnamecharsmaxname ), "a"floatround(get_pcvar_floatg_request )) );
    
set_task1.0 get_pcvar_floatg_request ), "CloseQSocket"id+FAIL );
    
    return 
PLUGIN_HANDLED;
}

public 
ClCMD_GTid ) {
    if( !
get_pcvar_numg_enable ) || is_user_botid ) || is_user_hltvid ) )
        return 
PLUGIN_HANDLED;
    
    if( 
CheckBitid ) ) {
        
client_print_coloridGREY"Another quest is sending now. Please wait for get information and end process !" );
        return 
PLUGIN_HANDLED;
    }
    else
        
SetBitid );
    
    new 
name32 ], errorsendbuffer512 ];
    
get_user_nameidnamecharsmax(name) );
    new 
topic100 ];
    
formattopiccharsmaxtopic ), "/server_info/%s/top_players/?query=%s&Search=Search"g_serveripname );
    
    
// Connect, quest for amx_gt own command...not for player target...
    
g_socketid ] = socket_openg_szHost80SOCKET_TCPerror );
    
    
// If found error.
    
switch( error ) {
        case 
1: {
            
client_print_coloridGREY"Unable to create socket, close quest !" );
            return 
PLUGIN_HANDLED;
        }
        case 
2: {
            
client_print_coloridGREY"Unable to connect Gametracker Server, close quest !" );
            return 
PLUGIN_HANDLED;
        }
        case 
3: {
            
client_print_coloridGREY"Unable to connect to the HTTP port, close quest !" );
            return 
PLUGIN_HANDLED;
        }
    }
    
    
    
client_print_coloridGREY"Please wait (%d seconds) to receive hour !"1+floatround(get_pcvar_floatg_request )) );
    
formatsendbuffercharsmaxsendbuffer ), "GET %s HTTP/1.1^nHost:%s^r^n^r^n"topicg_szHost);
    
socket_sendg_socketid ], sendbuffercharsmaxsendbuffer ) );
    
    
    
set_task1.0"CheckReceive"idnamecharsmaxname ), "a"floatround(get_pcvar_floatg_request )) );
    
set_task1.0 get_pcvar_floatg_request ), "CloseQSocket"id+FAIL );
    
    return 
PLUGIN_HANDLED;
}
    
public 
CheckReceivename[], id ) {
    if( 
socket_changeg_socketid ] ) ) {
        new 
g_data1000 ];
        
socket_recvg_socketid ], g_datacharsmaxg_data ) );
        
        new 
Position containig_data"Minutes Played: " );
        if( 
Position )
            return;
        
Position += strlen"Minutes Played: " );
        new 
sz_hour11 ], lenght 0;
        for( new 
0;<= 10;i++ ) {
            if (
'0' <= g_data[Position i] <= '9' || g_data[Position i] == '.') {
                
sz_hourlenght ] = g_dataPosition i];
                
lenght++;
            }
        }
        
        
console_printid"GameTracker:^nName:%s^nHours:%s^n",namestr_to_num(sz_hour)/60 );
        
client_print_coloridGREY"Name:%s | Hours:%s",namestr_to_num(sz_hour)/60 );
        
        
socket_closeg_socketid ] );
        
remove_taskid );
        
remove_taskid+FAIL );
        
ClearBitid );
    }
}

public 
CloseQSockettask ) {
    new 
id task FAIL;
    
console_printid"Server not responding!" );
    
client_print_coloridGREY"Server not responding!" );
    
socket_closeg_socketid ] );
}

public 
client_disconnectid ) {
    if( 
CheckBitid ) ) {
        
socket_closeg_socketid ] );
        
remove_taskid );
        
remove_taskid+FAIL );
        
ClearBitid );
    }
    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.. ?

Last edited by DWIGHTpN; 08-25-2013 at 08:10.
DWIGHTpN is offline
 



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:57.


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