Veteran Member
Join Date: Jan 2016
Location: Romania
|
05-01-2022
, 08:30
Re: CURL: Downloanding an page ?
|
#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_name( id, szName, charsmax(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(szTemp, charsmax(szTemp), "https://www.gametracker.com/player/%s/MY_SERVER_IP_HERE/", szName ); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, szTemp); curl_easy_setopt(curl, CURLOPT_COOKIE, 1); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header) curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, "ReceiveData"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, id); curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 1028); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2); curl_easy_setopt(curl, CURLOPT_CAINFO, "cstrike/addons/amxmodx/cacert.pem"); curl_easy_perform(curl, "CurlCallback", iID, sizeof(iID) ); } } public ReceiveData(data[], size, nmemb, id) { // 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]) formatex( g_ePlayerData[id][iRank], charsmax( g_ePlayerData[] ), data[iPos+93] ); } return size * nmemb } public CurlCallback(CURL:cURLHandle , CURLcode:code, iID[]) { if(code != CURLE_OK) { new szError[CURL_ERROR_SIZE] curl_easy_strerror(code, szError,charsmax(szError)) log_amx("cURL error: %d ^"%s^"", code, szError); } new id = iID[0]
if( g_ePlayerData[id][iScore] >= 1 ) CC_SendMessage( id, " &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_SendMessage( id, " &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.
|
|