Raised This Month: $12 Target: $400
 3% 

Solved CURL: Downloanding an page ?


Post New Thread Reply   
 
Thread Tools Display Modes
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-27-2022 , 05:40   Re: CURL: Downloanding an page ?
Reply With Quote #11

Quote:
Originally Posted by JocAnis View Post
Where is captcha on gametracker
From cloudflare

Just made this script, I tested it, works as charm, but your only problem is the GameTracker captcha. You can bypass that by changing User-Agent I think.

Also, you'll need cacert.pem inside the amxmodx folder, you can change it's path where you want. You can download a certificate from here: https://curl.se/docs/caextract.html

Tested with a random player from a random server. Results:
Code:
Score: 16552 | Minutes: 15403 | Score p. m.: 1.100000 | Rank: 9
PHP Code:
#include <amxmodx>
#include <curl>

#if !defined MAX_IP_WITH_PORT_LENGTH
#define MAX_IP_WITH_PORT_LENGTH 22
#endif

enum _:PlayerData
{
    
iScore,
    
iMinutes,
    
Float:flAvgScore,
    
iRank
}

new 
g_ePlayerData[MAX_PLAYERS 1][PlayerData]

public 
plugin_init()
{
    
register_concmd("test""SendRequest")
}

public 
SendRequest(id)
{
    new 
CURL:curl curl_easy_init();

    new 
szTemp[100];
    new 
szIP[MAX_IP_WITH_PORT_LENGTH]
    
get_user_ip(0szIPcharsmax(szIP))

    new 
iID[1]
    
iID[0] = id

    
new curl_slist:header

    header 
curl_slist_append(header"text/html; charset=UTF-8");
    
header curl_slist_append(header"User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.126 Mobile Safari/537.36");

    
formatex(szTempcharsmax(szTemp), "https://www.gametracker.com/player/%n/%s/"idszIP);

    if(
curl)
    {
        
curl_easy_setopt(curlCURLOPT_URLszTemp);
        
curl_easy_setopt(curlCURLOPT_COOKIE1);
        
curl_easy_setopt(curlCURLOPT_HTTPHEADERheader)
        
curl_easy_setopt(curlCURLOPT_CUSTOMREQUEST"GET");
        
curl_easy_setopt(curlCURLOPT_FOLLOWLOCATIONtrue);

        
curl_easy_setopt(curlCURLOPT_WRITEFUNCTION"ReceiveData");
        
curl_easy_setopt(curlCURLOPT_WRITEDATAid);
        
curl_easy_setopt(curlCURLOPT_BUFFERSIZE1028);

        
curl_easy_setopt(curlCURLOPT_SSL_VERIFYPEER1);
        
curl_easy_setopt(curlCURLOPT_SSL_VERIFYHOST2);
        
curl_easy_setopt(curlCURLOPT_CAINFO"cstrike/addons/amxmodx/cacert.pem");
        
curl_easy_perform(curl"CurlCallback"iIDsizeof(iID) );
    }
}

public 
ReceiveData(data[], sizenmembid)
{
    
// The position of the "Score: " div
    
new iPos containi(data"Score:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][iScore] = str_to_num(data[iPos 23])
    }

    
iPos containi(data"Minutes Played:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][iMinutes] = str_to_num(data[iPos 32])
    }

    
iPos containi(data"Score per Minute:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][flAvgScore] = str_to_float(data[iPos 34])
    }

    
iPos containi(data"Rank on Server:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][iRank] = str_to_num(data[iPos 95])
    }

    return 
size nmemb
}

public 
CurlCallback(CURL:cURLHandle CURLcode:codeiID[])
{
    if(
code != CURLE_OK)
    {
        new 
szError[CURL_ERROR_SIZE]
        
curl_easy_strerror(codeszError,charsmax(szError))
        
log_amx("cURL error: %d ^"%s^""codeszError);
    }

    new 
id iID[0]

    
server_print("Score: %d | Minutes: %d | Score p. m.: %f | Rank: %d"g_ePlayerData[id][iScore], g_ePlayerData[id][iMinutes], \
     
g_ePlayerData[id][flAvgScore], g_ePlayerData[id][iRank])

    
curl_easy_cleanup(cURLHandle);

__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 04-27-2022 at 06:18.
Shadows Adi is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-27-2022 , 10:10   Re: CURL: Downloanding an page ?
Reply With Quote #12

Shdow adi, why it gives me those errors at compileation:

Code:
//// atest.sma
scripting\include\curl_consts.inc(497) : warning 200: symbol "CURLINFO_CONTENT_LENGTH_DOWNLOA" is truncated to 31 characters
scripting\include\curl_consts.inc(1033) : warning 200: symbol "CURLOPT_CONV_FROM_NETWORK_FUNCT" is truncated to 31 characters
scripting\include\curl_consts.inc(1037) : warning 200: symbol "CURLOPT_CONV_TO_NETWORK_FUNCTIO" is truncated to 31 characters
scripting\include\curl.inc(160) : warning 207: unknown #pragma
scripting\include\curl.inc(160) : error 038: extra characters on line
scripting\include\curl.inc(166) : warning 207: unknown #pragmascripting
scripting\include\curl.inc(166)  error 038: extra characters on line
scripting\atest.sma(16) : error 017: undefined symbol "MAX_PLAYERS"
scripting\atest.sma(81 -- 82) : warning 213: tag mismatch
//
Craxor is offline
Send a message via ICQ to Craxor
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-27-2022 , 10:14   Re: CURL: Downloanding an page ?
Reply With Quote #13

Because the plugin was made for amxx 190 or later.
__________________








CrazY. is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-27-2022 , 13:02   Re: CURL: Downloanding an page ?
Reply With Quote #14

ok ill test later and come with an edit of this post to print the results
Craxor is offline
Send a message via ICQ to Craxor
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-29-2022 , 10:40   Re: CURL: Downloanding an page ?
Reply With Quote #15

A friend with AMXX 1.10 got same errors:

Code:
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl_consts.inc(497) : warning 200: symbol "CURLINFO_CONTENT_LENGTH_DOWNLOA" is truncated to 31 characters
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl_consts.inc(1033) : warning 200: symbol "CURLOPT_CONV_FROM_NETWORK_FUNCT" is truncated to 31 characters
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl_consts.inc(1037) : warning 200: symbol "CURLOPT_CONV_TO_NETWORK_FUNCTIO" is truncated to 31 characters
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(160) : warning 207: unknown #pragma
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(160) : error 038: extra characters on line
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(166) : warning 207: unknown #pragma
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(166) : error 038: extra characters on line
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\ore.sma(16) : error 017: undefined symbol "MAX_PLAYERS"
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\ore.sma(81 -- 82) : warning 213: tag mismatch
`


Meta List :
Code:
 [ 1] AMX Mod X        RUN   -    amxmodx_mm_i386.so          v1.10.0.5461  ini  Start ANY 
[15] CURL AMXX        RUN   -    curl_amxx_i386.so           v1.1.1        pl1  ANY   ANY
So why the hall doesn't work compile ?

Is because the COMPILER is 1.8.2 maybe ?`

--------------------

Edit: I've changed the compile to 1.9 and it compiles but the plugin doesn't work it shows 0 to everything.

I've made changes to be a client_command in chat to print the output, code:

PHP Code:
#include <amxmodx>
#include <curl>

#if !defined MAX_IP_WITH_PORT_LENGTH
#define MAX_IP_WITH_PORT_LENGTH 22
#endif

enum _:PlayerData
{
    
iScore,
    
iMinutes,
    
Float:flAvgScore,
    
iRank
}

new 
g_ePlayerData[MAX_PLAYERS 1][PlayerData]

public 
plugin_init()
{
    
register_clcmd("say /playedtime""SendRequest")
}

public 
SendRequest(id)
{
    new 
CURL:curl curl_easy_init();

    new 
szTemp[100];
    new 
szIP[MAX_IP_WITH_PORT_LENGTH]
    
get_user_ip(0szIPcharsmax(szIP))

    new 
iID[1]
    
iID[0] = id

    
new curl_slist:header

    header 
curl_slist_append(header"text/html; charset=UTF-8");
    
header curl_slist_append(header"User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.126 Mobile Safari/537.36");

    
formatex(szTempcharsmax(szTemp), "https://www.gametracker.com/player/%n/%s/"idszIP);

    if(
curl)
    {
        
curl_easy_setopt(curlCURLOPT_URLszTemp);
        
curl_easy_setopt(curlCURLOPT_COOKIE1);
        
curl_easy_setopt(curlCURLOPT_HTTPHEADERheader)
        
curl_easy_setopt(curlCURLOPT_CUSTOMREQUEST"GET");
        
curl_easy_setopt(curlCURLOPT_FOLLOWLOCATIONtrue);

        
curl_easy_setopt(curlCURLOPT_WRITEFUNCTION"ReceiveData");
        
curl_easy_setopt(curlCURLOPT_WRITEDATAid);
        
curl_easy_setopt(curlCURLOPT_BUFFERSIZE1028);

        
curl_easy_setopt(curlCURLOPT_SSL_VERIFYPEER1);
        
curl_easy_setopt(curlCURLOPT_SSL_VERIFYHOST2);
        
curl_easy_setopt(curlCURLOPT_CAINFO"cstrike/addons/amxmodx/cacert.pem");
        
curl_easy_perform(curl"CurlCallback"iIDsizeof(iID) );
    }
}

public 
ReceiveData(data[], sizenmembid)
{
    
// The position of the "Score: " div
    
new iPos containi(data"Score:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][iScore] = str_to_num(data[iPos 23])
    }

    
iPos containi(data"Minutes Played:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][iMinutes] = str_to_num(data[iPos 32])
    }

    
iPos containi(data"Score per Minute:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][flAvgScore] = str_to_float(data[iPos 34])
    }

    
iPos containi(data"Rank on Server:")

    if(
iPos != -1)
    {
        
g_ePlayerData[id][iRank] = str_to_num(data[iPos 95])
    }

    return 
size nmemb
}

public 
CurlCallback(CURL:cURLHandle CURLcode:codeiID[])
{
    if(
code != CURLE_OK)
    {
        new 
szError[CURL_ERROR_SIZE]
        
curl_easy_strerror(codeszError,charsmax(szError))
        
log_amx("cURL error: %d ^"%s^""codeszError);
    }

    new 
id iID[0]

    
client_print(idprint_chat"Score: %d | Minutes: %d | Score p. m.: %f | Rank: %d"g_ePlayerData[id][iScore], g_ePlayerData[id][iMinutes], \
     
g_ePlayerData[id][flAvgScore], g_ePlayerData[id][iRank])

    
curl_easy_cleanup(cURLHandle);


Image: https://prnt.sc/nG0msaQF2VFr

Last edited by Craxor; 04-29-2022 at 11:40.
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-29-2022 , 12:22   Re: CURL: Downloanding an page ?
Reply With Quote #16

Quote:
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl_consts.inc(497) : warning 200: symbol "CURLINFO_CONTENT_LENGTH_DOWNLOA" is truncated to 31 characters
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl_consts.inc(1033) : warning 200: symbol "CURLOPT_CONV_FROM_NETWORK_FUNCT" is truncated to 31 characters
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl_consts.inc(1037) : warning 200: symbol "CURLOPT_CONV_TO_NETWORK_FUNCTIO" is truncated to 31 characters
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(160) : warning 207: unknown #pragma
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(160) : error 038: extra characters on line
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(166) : warning 207: unknown #pragma
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\include\curl.inc(166) : error 038: extra characters on line
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\ore.sma(16) : error 017: undefined symbol "MAX_PLAYERS"
// C:\Users\teodo\OneDrive\Desktop\AMXX 1.8.2 COMPILER LOCAL 26.01\ore.sma(81 -- 82) : warning 213: tag mismatch
__________________

Last edited by HamletEagle; 04-29-2022 at 12:22.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-29-2022 , 13:58   Re: CURL: Downloanding an page ?
Reply With Quote #17

Ive already said ive changed the compiler. Check the edit please .
Craxor is offline
Send a message via ICQ to Craxor
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-29-2022 , 15:17   Re: CURL: Downloanding an page ?
Reply With Quote #18

Quote:
Originally Posted by Craxor View Post
Is because the COMPILER is 1.8.2 maybe ?`
Yes.

Quote:
Originally Posted by Craxor View Post
Edit: I've changed the compile to 1.9 and it compiles but the plugin doesn't work it shows 0 to everything.
Output the received data, how I said, your only problem is the gametracker's captcha. I think you can make it work by changing the User-Agent from HTTP headers if in the received data you get something that refers to captcha.

And make sure that the IP you get from get_user_ip() func is the server's one.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 04-29-2022 at 15:18.
Shadows Adi is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 04-30-2022 , 00:31   Re: CURL: Downloanding an page ?
Reply With Quote #19

Quote:
Originally Posted by Shadows Adi View Post
Yes.


Output the received data, how I said, your only problem is the gametracker's captcha. I think you can make it work by changing the User-Agent from HTTP headers if in the received data you get something that refers to captcha.

And make sure that the IP you get from get_user_ip() func is the server's one.
https://prnt.sc/nG0msaQF2VFr

Ill make debugs and come with an edit .

Last edited by Craxor; 04-30-2022 at 01:06.
Craxor is offline
Send a message via ICQ to Craxor
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 05-01-2022 , 08:30   Re: CURL: Downloanding an page ?
Reply With Quote #20

The Code works Fine Adi, sometimes it takes longer to update the rank, situation where you change your name or a new Player enters the server, but i'll let a message for the players to know, also i removed score p.m. was pointless for deathrun and i've changed iRank from Int to String, also i had to insert the server IP manualy, heres the working code:

PHP Code:
#include <amxmodx>
#include <cromchat>
#include <curl>
 
#if !defined MAX_IP_WITH_PORT_LENGTH
#define MAX_IP_WITH_PORT_LENGTH 22
#endif
 
enum _:PlayerData
{
    
iScore,
    
iMinutes,
    
iRank[14]
}
 
new 
g_ePlayerData[MAX_PLAYERS 1][PlayerData]
 
public 
plugin_init()
{
    
register_plugin"GameTracker Stats""xxx""Shadow_adi" );
 
    
register_clcmd("say /playedtime""SendRequest")
    
register_clcmd("say .playedtime""SendRequest")
    
register_clcmd("say /ore""SendRequest")
    
register_clcmd("say .ore""SendRequest")
    
register_clcmd("say /rank""SendRequest")
    
register_clcmd("say rank""SendRequest")
}
 
public 
SendRequest(id)
{
    new 
CURL:curl curl_easy_init();
 
    new 
szTemp[100];
 
 
    new 
iID[1]
    
iID[0] = id
 
    
new szName[32];
    
get_user_nameidszNamecharsmax(szName) );
 
    new 
curl_slist:header
 
    header 
curl_slist_append(header"text/html; charset=UTF-8");
    
header curl_slist_append(header"User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.126 Mobile Safari/537.36");
 
    
formatex(szTempcharsmax(szTemp), "https://www.gametracker.com/player/%s/MY_SERVER_IP_HERE/"szName );
 
    if(
curl)
    {
        
curl_easy_setopt(curlCURLOPT_URLszTemp);
        
curl_easy_setopt(curlCURLOPT_COOKIE1);
        
curl_easy_setopt(curlCURLOPT_HTTPHEADERheader)
        
curl_easy_setopt(curlCURLOPT_CUSTOMREQUEST"GET");
        
curl_easy_setopt(curlCURLOPT_FOLLOWLOCATIONtrue);
 
        
curl_easy_setopt(curlCURLOPT_WRITEFUNCTION"ReceiveData");
        
curl_easy_setopt(curlCURLOPT_WRITEDATAid);
        
curl_easy_setopt(curlCURLOPT_BUFFERSIZE1028);
 
        
curl_easy_setopt(curlCURLOPT_SSL_VERIFYPEER1);
        
curl_easy_setopt(curlCURLOPT_SSL_VERIFYHOST2);
        
curl_easy_setopt(curlCURLOPT_CAINFO"cstrike/addons/amxmodx/cacert.pem");
        
curl_easy_perform(curl"CurlCallback"iIDsizeof(iID) );
    }
}
 
public 
ReceiveData(data[], sizenmembid)
{
    
// The position of the "Score: " div
    
new iPos containi(data"Score:")
 
    if(
iPos != -1)
    {
        
g_ePlayerData[id][iScore] = str_to_num(data[iPos 23])
    }
 
    
iPos containi(data"Minutes Played:")
 
    if(
iPos != -1)
    {
        
g_ePlayerData[id][iMinutes] = str_to_num(data[iPos 32])
    }
 
    
iPos containi(data"Rank on Server:")
 
    if(
iPos != -1)
    {
        
//g_ePlayerData[id][iRank] = str_to_num(data[iPos + 93])
    
formatexg_ePlayerData[id][iRank], charsmaxg_ePlayerData[] ), data[iPos+93] );
    }
 
    return 
size nmemb
}
 
public 
CurlCallback(CURL:cURLHandle CURLcode:codeiID[])
{
    if(
code != CURLE_OK)
    {
        new 
szError[CURL_ERROR_SIZE]
        
curl_easy_strerror(codeszError,charsmax(szError))
        
log_amx("cURL error: %d ^"%s^""codeszError);
    }
 
    new 
id iID[0]


    if( 
g_ePlayerData[id][iScore] >= )
        
CC_SendMessageid" &x01[ &x03Gametracker Stats&x01 ] Score: &x07%d&x01 , Hours: &x07%d&x01 , Rank: &x07%s&x01."g_ePlayerData[id][iScore] ,  g_ePlayerData[id][iMinutes] / 60, \
         
g_ePlayerData[id][iRank] );
    else
        
CC_SendMessageid" &x01[ &x03Gametracker Stats&x01 ] Your stats haven't been updated yet, try later while gametracker works on it ." );

 
    
curl_easy_cleanup(cURLHandle);



Last edited by Craxor; 05-01-2022 at 08:31.
Craxor is offline
Send a message via ICQ to Craxor
Reply


Thread Tools
Display Modes

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 04:29.


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