AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Plugin possible or wrong? (https://forums.alliedmods.net/showthread.php?t=223163)

DWIGHTpN 08-10-2013 11:42

Plugin possible or wrong?
 
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.. ?

DWIGHTpN 08-25-2013 07:36

Re: Plugin possible or wrong?
 
BUMP :crab:

Black Rose 08-25-2013 09:13

Re: Plugin possible or wrong?
 
There are some examples in this thread that can easily be modified to do what you want.
https://forums.alliedmods.net/showthread.php?t=223244

If you're having delay problems I could rewrite it using HTTP2 instead.

Black Rose 08-25-2013 14:23

Re: Plugin possible or wrong?
 
Quote:

Originally Posted by devilicioux (Post 2021460)
If we can get the hours played ..we can get the ranks as well ..That would be awesome :D

If I understand you correctly that function already exists in one of the examples in that thread.

DWIGHTpN 08-25-2013 18:52

Re: Plugin possible or wrong?
 
I try with http library, but is to slow. I got information after 20 sec .

Black Rose 08-26-2013 16:14

Re: Plugin possible or wrong?
 
Sorry for the delay. I rewrote it using HTTP2 and on-the-fly parsing.
You obviously have to edit the way this information is printed to your liking. I made it fit my purpose of testing.
Code:
#include <amxmodx> #include <http2> #include <regex> #define SERVER_IP "PUT YOUR IP HERE" #define TOTAL   0 #define CURRENT 1 new g_patterns[][] = {     "(?:First Seen:[\r\n\s]*<.+>[\r\n\s]*)(\w{3} [0-3][0-9], [12][019][0-9][0-9])",     "(?:Last Seen:[\r\n\s]*<.+>[\r\n\s]*)(Online Now|(?:(?:(?:Yester|To)day)|(?:\w{3} [0-3][0-9], [12][019][0-9][0-9])) (?:1[0-2]|[0-9]):[0-5]\d [A|P]M)",     "(?:Score:[\r\n\s]*<.+>[\r\n\s]*)(\d+)",     "(?:Minutes Played:[\r\n\s]*<.+>[\r\n\s]*)(\d+)",     "(?:Score per Minute:[\r\n\s]*<.+>[\r\n\s]*)(\d+\.?\d?)",     "(?:Rank on Server:[\r\n\s]*<.+>[\r\n\s]*(?:<a.*>[\r\n\s]*)?)(#\d+(?: out of \d+)?)" } enum playerinfo_enum {     FirstSeen[16],     LastSeen[16],     Score[2],     MinutesPlayed[2],     Float:ScorePerMinute[2],     RankOnServer[2],     bool:CurrentStats }; new g_playerinfo[33][playerinfo_enum]; new g_downloadinfo[HTTP2_MAX_DOWNLOAD_SLOTS]; new g_totalranks; new bool:g_cmd_blocked[33]; new buffer[HTTP2_BUFFER_SIZE]; public plugin_init() {     register_plugin("Gametracker Test", "1.1", "[ --{-@ ]");         register_clcmd("say /myinfo", "clcmd_myinfo"); } public clcmd_myinfo(id, level, cid) {         if ( g_cmd_blocked[id] )         return;         g_cmd_blocked[id] = true;         clear_pinfo_array(id);         new name[32];     get_user_name(id, name, charsmax(name));         new URL[128];     formatex(URL, charsmax(URL), "http://www.gametracker.com/player/%s/%s/", name, SERVER_IP);         new download_index = HTTP2_Download(URL, _, _, "DownloadProcess");     if ( download_index >= 0 )         g_downloadinfo[download_index] = id; } public DownloadProcess(index) {         new id = g_downloadinfo[index];     new num, startpos, result[32];         HTTP2_getDataSafe(index, buffer, charsmax(buffer));         if ( contain(buffer, "PLAYER SUMMARY") == -1 )         return PLUGIN_CONTINUE;         if ( contain(buffer, "CURRENT STATS") != -1 )         g_playerinfo[id][CurrentStats] = true;         for ( new i = 0 ; i < sizeof g_patterns ; i++ ) {         new Regex:hRegex = regex_match(buffer[startpos], g_patterns[i], num, result, charsmax(result));                 if ( hRegex >= REGEX_OK ) {             regex_substr(hRegex, 1, result, charsmax(result));                         new slot = g_playerinfo[id][CurrentStats] && ! startpos ? CURRENT : TOTAL;                         switch ( i ) {                 case 0: copy(g_playerinfo[id][FirstSeen], charsmax(g_playerinfo[][FirstSeen]), result);                 case 1: copy(g_playerinfo[id][LastSeen], charsmax(g_playerinfo[][LastSeen]), result);                 case 2: g_playerinfo[id][Score][slot] = str_to_num(result);                 case 3: g_playerinfo[id][MinutesPlayed][slot] = str_to_num(result);                 case 4: g_playerinfo[id][ScorePerMinute][slot] = any:str_to_float(result);                 case 5: {                     g_playerinfo[id][RankOnServer][slot] = str_to_num(result[1]);                     if ( slot == TOTAL ) {                         g_totalranks = str_to_num(result[contain(result, "out of") + 7]);                     }                 }             }                         regex_free(hRegex);         }         if ( i == sizeof g_patterns - 1 && g_playerinfo[id][CurrentStats] && ! startpos ) {             i -= 4;             startpos = contain(buffer, "ALL TIME STATS");         }         else if ( i == sizeof g_patterns - 1 ) {             server_print("");             server_print("First Seen: %s", g_playerinfo[id][FirstSeen]);             server_print("Last Seen: %s", g_playerinfo[id][LastSeen]);             server_print("");             server_print("Total Score: %d", g_playerinfo[id][Score][TOTAL]);             server_print("Total Minutes Played: %d", g_playerinfo[id][MinutesPlayed][TOTAL]);             server_print("Total Score Per Minute: %0.1f", g_playerinfo[id][ScorePerMinute][TOTAL]);             server_print("Total Rank: #%d/#%d", g_playerinfo[id][RankOnServer][TOTAL], g_totalranks);             server_print("");             server_print("Current Score: %d", g_playerinfo[id][Score][CURRENT]);             server_print("Current Minutes Played: %d", g_playerinfo[id][MinutesPlayed][CURRENT]);             server_print("Current Score Per Minute: %0.1f", g_playerinfo[id][ScorePerMinute][CURRENT]);             server_print("Current Rank: #%d", g_playerinfo[id][RankOnServer][CURRENT]);             g_cmd_blocked[id] = false;             return PLUGIN_HANDLED;         }     }     return PLUGIN_CONTINUE; } clear_pinfo_array(id) {     arrayset(g_playerinfo[id][FirstSeen], 0, sizeof g_playerinfo[][FirstSeen]);     arrayset(g_playerinfo[id][LastSeen], 0, sizeof g_playerinfo[][LastSeen]);     g_playerinfo[id][Score][TOTAL] = 0;     g_playerinfo[id][Score][CURRENT] = 0;     g_playerinfo[id][MinutesPlayed][TOTAL] = 0;     g_playerinfo[id][MinutesPlayed][CURRENT] = 0;     g_playerinfo[id][ScorePerMinute][TOTAL] = any:0.0;     g_playerinfo[id][ScorePerMinute][CURRENT] = any:0.0;     g_playerinfo[id][RankOnServer][TOTAL] = 0;     g_playerinfo[id][RankOnServer][CURRENT] = 0;     g_playerinfo[id][CurrentStats] = false; }

devilicioux 08-27-2013 06:16

Re: Plugin possible or wrong?
 
Hey Blackrose .. First of all thank you for helping with the codes everytime ..
I tried the code you made in that thread using HTTP.inc .. There seems to be a little problem .. whenever i type /myinfo in chat .. The server gets stuck for 2-3 seconds and few of the players get Overflowed,I got lagged for atleast a minute .. and suddenly i woke up back in next round .. Checked up the server console it showed almost 10-12 ppl got overflowed and kicked.
This was the bad thing that happened.Now Gud thing was this happened second time.
When i tried first time .. 2-3 Seconds stucking and game continuous and then out of no where after 15-20 seconds the Info was shown on HUD :grrr: Such a delay is not gud.
So i had to remove the plugin as a result.May be the socket connections are happening too slow in that plugin.

Now i ll go and try the code you made with Http2.inc and Give you the accurate feedback :D

DWIGHTpN 08-27-2013 10:21

Re: Plugin possible or wrong?
 
@Black Rose : Thank you :), this method is fast.

Here is http2 library: https://forums.alliedmods.net/showpo...62&postcount=1

ss1234 01-23-2015 00:02

Re: Plugin possible or wrong?
 
Hi,
Could someone rewrite the plugin of #6 made by black rose?
I tried compiling it but it gave errors as below :
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Rank.sma(67) : error 017: undefined symbol "HTTP2_getDataSafe"
Rank.sma(67) : error 088: number of arguments does not match definition

2 Errors.
Could not locate output file rank.amx (compile failed).

thanks!


All times are GMT -4. The time now is 15:57.

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