Raised This Month: $ Target: $400
 0% 

CURL Help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2021 , 19:53   Re: CURL Help
Reply With Quote #10

No need to write to a local file
PHP Code:

#include <amxmodx>
#include <curl>

#define CURL_BUFFER_SIZE 4096

new g_iNewVersion;

public 
plugin_init()
{
    
register_plugin("CURL Test""1.0""-");
    
    
IsUpgradeNeeded997 );
    
//IsUpgradeNeeded( 998 );
}

public 
IsUpgradeNeedediCurrentVersion )
{
    new 
szCURL_url[128]
    new 
CURL:cURLHandle
    
new data[8]
    
    
num_to_striCurrentVersion data charsmaxdata ) );
    
    
copy(szCURL_urlcharsmax(szCURL_url), "https://lexzor.warface.ro/AutoUpdate/Test/version.txt")
    
    
cURLHandle curl_easy_init()
    
    if(
cURLHandle)
    {
        
curl_easy_setopt(cURLHandleCURLOPT_BUFFERSIZECURL_BUFFER_SIZE)
        
curl_easy_setopt(cURLHandleCURLOPT_URLszCURL_url)
        
curl_easy_setopt(cURLHandleCURLOPT_WRITEDATAdata[0])
        
curl_easy_setopt(cURLHandleCURLOPT_WRITEFUNCTION"WriteFunction" )
        
curl_easy_perform(cURLHandle"CurlCallback"datasizeof(data))
    }
}

public 
WriteFunction (data[], sizenmembfile)
{
    new 
actual_size size nmemb;
    
    
g_iNewVersion str_to_numdata );
    
    return 
actual_size
}

public 
CurlCallback(CURL:curlCURLcode:codedata[])
{
    if(
code == CURLE_WRITE_ERROR)
    {
        
server_print("transfer aborted")
    }
    else
    {
        
server_print("curl complete")
    
        new 
iCurrentVersion str_to_numdata );
    
        
server_print"Upgrade %s needed [Is %d > %d ?]" , ( g_iNewVersion iCurrentVersion ) ? "is" "not" g_iNewVersion iCurrentVersion );
    }
    
    
curl_easy_cleanup(curl)

IsUpgradeNeeded( 997 );
Output:
Code:
Upgrade is needed [998 > 997]
IsUpgradeNeeded( 998 );
Output:
Code:
Upgrade not needed [Is 998 > 998 ?]
__________________

Last edited by Bugsy; 05-13-2021 at 19:56.
Bugsy 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 02:29.


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