Skip to content

[Amxx Module] Curl (Windows & Linux)

The module is a wrapper around the libcurl library. It supports SSL and allows transfers in non-blocking mode. Functions: All natives do exactly what their C counterparts do, except for some: the function starts a transfer, and when it completes, the callback callbackComplite…

ModuleCounter-Strike 1.6Views:33

Description

The module is a wrapper around the libcurl library. It supports SSL and allows transfers in non-blocking mode.

Functions:
All natives do exactly what their C counterparts do, except for some:

Pawn
native void:curl_easy_perform(const CURL:handle, const callbackComplite[], const data[] = {}, const data_len = 0)

The function starts a transfer, and when the transfer completes, the callback callbackComplite will be called.
You can pass an array of so-called userdata as the third parameter; it will be passed to callbackComplite. The fourth parameter is the size of the array.

If data is set, the callback must have this signature:

Pawn
public compliteCallback(CURL:curl, CURLcode:code, data[])

If it is not set, the signature must be as follows:

Pawn
public compliteCallback(CURL:curl, CURLcode:code)

Author: Polarhigh
Download: GitHub releases
Source code: https://github.com/Polarhigh/AmxxCurl
Examples: https://github.com/Polarhigh/AmxxCurl/tree/master/amx_examples

Some notes and recommendations are below the cut.

General notes:
1) You must NOT call curl_easy_cleanup or other cleanup functions until the transfer has completed!
2) There is currently no way to actually set or get the value of a curl_off_t variable, so the type is converted to cell (a regular amxx cell) for now, but this is not very correct. The values will often be incorrect.
3) Always set the CURLOPT_BUFFERSIZE option. If you use the WRITEFUNCTION callback, pass a buffer size of no more than 1024 as the parameter, otherwise you risk stack errors and even hanging the server. If you get stack errors when using other callbacks, you can define #pragma dynamic 30000 in the plugin.
4) Don't forget that you need to free the memory behind the pointers for curl_slist and curl_httppost with the functions curl_slist_free_all and curl_formfree, respectively.
5) If there are unfinished transfers when the map changes, the server will wait for all transfers to complete, and the callbackComplite callback will be called after plugin_end.

Recommendations:
1) You can use one curl handle several times for the same URL.
2) Use curl_easy_setopt(curl, CURLOPT_VERBOSE, 1) to debug the plugin if you have trouble finding the cause of a problem in it. (By default, debug output goes to the server console; you can define the CURLOPT_DEBUGFUNCTION callback to change the output.)

Related

What is BMOD? BMOD lets amxx programmers use an alternative physics engine (Bullet). A few videos for illustration: https://youtube.com/watch?v=Nn26KkoIGNY https://youtube.com/watch?v=CUmNRsVro1U https://youtube.com/watch?v=vUCIKGlyDBQ https://youtube.com/watch?v=fAJlHJehlI8…