Raised This Month: $7 Target: $400
 1% 

Module: Curl


Post New Thread Reply   
 
Thread Tools Display Modes
PartialCloning
Senior Member
Join Date: Dec 2015
Old 01-25-2017 , 18:53   Re: Module: Curl
Reply With Quote #21

I tested it a while ago it worked for me. Double check and debug your code.
PartialCloning is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 01-26-2017 , 09:24   Re: Module: Curl
Reply With Quote #22

I don't know, I prepared the curlopt the same way as in the PHP script, yet it works in the script but not in the plugin.

Note that this is a HTTPS connection, Discord Webhooks don't seem to support HTTP.
__________________
gabuch2 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-26-2017 , 13:24   Re: Module: Curl
Reply With Quote #23

I tested it a while back with https and it works. Show your code.
__________________
HamletEagle is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 01-30-2017 , 07:07   Re: Module: Curl
Reply With Quote #24

PHP Code:
new JSON:jsontest
new CURL:test 
PHP Code:
jsontest json_create();
json_set_string(jsontest"content", [[string]])
static 
szEncoded[4096];
json_encodejsontestszEncodedcharsmaxszEncoded ) );
test curl_easy_init()
curl_easy_setopt(testCURLOPT_URL"https://discordapp.com/api/webhooks/[redacted]");
curl_easy_setopt(testCURLOPT_POST1);
curl_easy_setopt(testCURLOPT_HEADER"Content-Type: application/json");
curl_easy_setopt(testCURLOPT_POSTFIELDSszEncoded);

log_amx("Enviando: %s"szEncoded)
curl_easy_perform(test"completeCallback"
I'm using Exolent's JSON include.
__________________

Last edited by gabuch2; 01-30-2017 at 07:10.
gabuch2 is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 01-31-2017 , 00:28   Re: Module: Curl
Reply With Quote #25

Here is a full plugin that does use a discord's webhooks:

Compiling with amxx >= 1.9?... See here

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

new const g_szURL[] = "https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}";
new const 
g_iTimeBetweenCalls 30;

new 
g_iLastCallbool:g_bIsWorkingCURL:g_cURLHandlecurl_slist:g_cURLHeadersg_szHostname[129], g_szNetAddress[22];

public 
plugin_init()
{
    
register_plugin("[cURL] Discord !admin Webhook""1.0""Th3-822");

    
register_clcmd("say !admin""cmd_admincall");
}

public 
plugin_cfg()
{
    
// Add a delay to wait for the values for g_szHostname and g_szNetAddress
    
g_iLastCall get_systime();
    
set_task(10.0"plugin_cfg_delayed");
}

public 
plugin_cfg_delayed()
{
    
get_cvar_string("hostname"g_szHostnamecharsmax(g_szHostname));
    
get_cvar_string("net_address"g_szNetAddresscharsmax(g_szNetAddress));
}

public 
plugin_end()
{
    if (
g_cURLHandle)
    {
        
curl_easy_cleanup(g_cURLHandle);
        
g_cURLHandle CURL:0;
    }
    if (
g_cURLHeaders)
    {
        
curl_slist_free_all(g_cURLHeaders);
        
g_cURLHeaders curl_slist:0;
    }
}

// Replace MB Chars with "."
_fixName(name[])
{
    new 
0;
    while (
name[i] != 0)
    {
        if (!(
<= name[i] <= 255))
        {
            
name[i] = '.';
        }
        
i++;
    }
}

public 
cmd_admincall(id)
{
    static 
iCurTime;

    if (!
g_bIsWorking && ((iCurTime get_systime()) - g_iLastCall) > g_iTimeBetweenCalls)
    {
        
g_iLastCall iCurTime;

        static 
szName[32], szAuthId[35], szBuffer[129], JSON:jEmbeds[1], JSON:jEmbedJSON:jWebhook;
        
get_user_name(idszNamecharsmax(szName));
        
get_user_authid(idszAuthIdcharsmax(szAuthId));
        
_fixName(szName);

        
// Create array of embed objects
        
jEmbed json_create();
        
json_set_string(jEmbed"title"g_szHostname);
        
formatex(szBuffercharsmax(szBuffer), "Click to enter on the server: steam://connect/%s"g_szNetAddress);
        
json_set_string(jEmbed"description"szBuffer);
        
jEmbeds[0] = jEmbed;

        
// Create webhook request object
        
jWebhook json_create();
        
formatex(szBuffercharsmax(szBuffer), "@here ^"%s^" <%s> is calling an Admin."szNameszAuthId);
        
json_set_string(jWebhook"content"szBuffer);
        
json_set_array(jWebhook"embeds"jEmbedssizeof(jEmbeds), _JSON_Object);

        
// Send It
        
postJSON(g_szURLjWebhook);
        
json_destroy(jWebhook);
        
// json_destroy(jEmbed); // Destroyed in chain
    
}
    else 
client_print(idprint_chat" ** Admins Can Be Called Once Each %d Seconds **"g_iTimeBetweenCalls);

    return 
PLUGIN_HANDLED;
}

postJSON(const link[], JSON:jObject)
{
    if (!
g_cURLHandle)
    {
        if (!(
g_cURLHandle curl_easy_init()))
        {
            
log_amx("[Fatal Error] Cannot Init cURL Handle.");
            
pause("d");
            return;
        }
        if (!
g_cURLHeaders)
        {
            
// Init g_cURLHeaders with "Content-Type: application/json"
            
g_cURLHeaders curl_slist_append(g_cURLHeaders"Content-Type: application/json");
            
curl_slist_append(g_cURLHeaders"User-Agent: 822_AMXX_PLUGIN/1.0"); // User-Agent
            
curl_slist_append(g_cURLHeaders"Connection: Keep-Alive"); // Keep-Alive
        
}

        
// Static Options
        
curl_easy_setopt(g_cURLHandleCURLOPT_SSL_VERIFYPEER0);
        
curl_easy_setopt(g_cURLHandleCURLOPT_SSL_VERIFYHOST0);
        
curl_easy_setopt(g_cURLHandleCURLOPT_SSLVERSIONCURL_SSLVERSION_TLSv1);
        
curl_easy_setopt(g_cURLHandleCURLOPT_FAILONERROR0);
        
curl_easy_setopt(g_cURLHandleCURLOPT_FOLLOWLOCATION0);
        
curl_easy_setopt(g_cURLHandleCURLOPT_FORBID_REUSE0);
        
curl_easy_setopt(g_cURLHandleCURLOPT_FRESH_CONNECT0);
        
curl_easy_setopt(g_cURLHandleCURLOPT_CONNECTTIMEOUT10);
        
curl_easy_setopt(g_cURLHandleCURLOPT_TIMEOUT10);
        
curl_easy_setopt(g_cURLHandleCURLOPT_HTTPHEADERg_cURLHeaders);
        
curl_easy_setopt(g_cURLHandleCURLOPT_POST1);
    }

    static 
szPostdata[513];
    
json_encode(jObjectszPostdatacharsmax(szPostdata));
    
//log_amx("[DEBUG] POST: %s", szPostdata);

    
curl_easy_setopt(g_cURLHandleCURLOPT_URLlink);
    
curl_easy_setopt(g_cURLHandleCURLOPT_COPYPOSTFIELDSszPostdata);

    
g_bIsWorking true;
    
curl_easy_perform(g_cURLHandle"postJSON_done");
}

public 
postJSON_done(CURL:curlCURLcode:code)
{
    
g_bIsWorking false;
    if (
code == CURLE_OK)
    {
        static 
statusCode;
        
curl_easy_getinfo(curlCURLINFO_RESPONSE_CODEstatusCode);
        if (
statusCode >= 400)
        {
            
log_amx("[Error] HTTP Error: %d"statusCode);
        }
    }
    else
    {
        
log_amx("[Error] cURL Error: %d"code);
        
curl_easy_cleanup(g_cURLHandle);
        
g_cURLHandle CURL:0;
    }

btw, curl_easy_cleanup and curl_slist_free_all should set the pointer to a invalid value to avoid a crash.

Last edited by Th3822; 02-15-2022 at 14:45. Reason: Added link to compiling with 1.9
Th3822 is offline
tenub
Junior Member
Join Date: Aug 2013
Old 08-26-2017 , 00:19   Re: Module: Curl
Reply With Quote #26

Code:
curl_consts.inc(497) : warning 200: symbol "CURLINFO_CONTENT_LENGTH_DOWNLOA" is truncated to 31 characters
curl_consts.inc(1033) : warning 200: symbol "CURLOPT_CONV_FROM_NETWORK_FUNCT" is truncated to 31 characters
curl_consts.inc(1037) : warning 200: symbol "CURLOPT_CONV_TO_NETWORK_FUNCTIO" is truncated to 31 characters
Is there a way to adjust the code to allow the 1.8.2 compiler to compile without problems?
tenub is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 08-27-2017 , 09:50   Re: Module: Curl
Reply With Quote #27

Quote:
Originally Posted by tenub View Post
Code:
curl_consts.inc(497) : warning 200: symbol "CURLINFO_CONTENT_LENGTH_DOWNLOA" is truncated to 31 characters
curl_consts.inc(1033) : warning 200: symbol "CURLOPT_CONV_FROM_NETWORK_FUNCT" is truncated to 31 characters
curl_consts.inc(1037) : warning 200: symbol "CURLOPT_CONV_TO_NETWORK_FUNCTIO" is truncated to 31 characters
Is there a way to adjust the code to allow the 1.8.2 compiler to compile without problems?
Those are only warnings, you can compile it and use it fine, just ignore them.
Th3822 is offline
zreNET
New Member
Join Date: Mar 2018
Old 03-24-2018 , 01:08   Re: Module: Curl
Reply With Quote #28

I can not install curl in my server, please help me.

Code:
[SO LOADER] Loaded: libcrypto.so.1.0.0
[SO LOADER] Loaded: libssl.so.1.0.0
L 03/24/2018 - 11:52:25: [AMXX] Module "cstrike/addons/amxmodx/modules/curl_amxx_i386.so" failed to load (cstrike/addons/amxmodx/modules/curl_amxx_i386.so: undefined symbol: pthread_create)
L 03/24/2018 - 11:52:25: Error:
L 03/24/2018 - 11:52:25: [AMXX] Module is not a valid library (file "cstrike/addons/amxmodx/modules/curl_amxx_i386.so")
Code:
Linux hub 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
zreNET is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 10-05-2018 , 08:59   Re: Module: Curl
Reply With Quote #29

I don't think this module is being maintained by the author anymore, however, as I'm completely clueless when it comes to module coding and C/C++ in general, I'd be extremely thankful if someone could lend me a hand in fixing the issues I've found with it:
https://github.com/Polarhigh/AmxxCurl/issues

The latest issue makes this module completely unusable for me and I don't know where to even begin debugging it. Perhaps it's also related to the first one, but I couldn't tell.

EDIT: I contacted the author and he has since fixed the issue

Last edited by Kushfield; 10-07-2018 at 13:50.
Kushfield is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 01-13-2019 , 21:13   Re: Module: Curl
Reply With Quote #30

Just to let everyone here know, this module has received some improvements. Most importantly:
  • Several causes for crashes/freezes have been fixed
  • SoLoader (+ separate libssl and libcrypto libraries) is no longer required
  • Compatibility with up-to-date ReHLDS has been added
https://github.com/Polarhigh/AmxxCurl/releases
Kushfield is offline
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 00:31.


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