Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURL support via scripting. #160

Merged
merged 3 commits into from
Jan 26, 2025
Merged

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Dec 23, 2024

Added a CURL request function to scripting API. Please see updated 'example-script.as' for all details.

To test, spin up a server with the example script and say "CURL test" in chat - this sends a GET request to https://www.rigsofrods.org.

CMakeLists.txt Outdated Show resolved Hide resolved
@Zentro
Copy link
Member

Zentro commented Jan 25, 2025

Everything looks good far so, just be sure to update https://github.com/RigsOfRods/ror-server/wiki/Scripting-reference

Per <angelscript.h> // deprecated since 2022-05-04, 2.36.0
To test, run with 'example-script.as' and say "CURL test" in chat!

The new HTTP(S) request API:
```
    /**
     * Launches a background task, use `curlStatus` callback to monitor progress and receive result.
     * @param displayname The "correlation ID" - the label passed to the callback to identify the transfer.
     * @remark Callback signature: `curlStatus(curlStatusType, int n1, int n2, string displayname, string message)`
     * - CURL_STATUS_PROGRESS: n1 = bytes downloaded, n2 = total bytes, message = empty
     * - CURL_STATUS_SUCCESS: n1 = CURL return code, n2 = HTTP result code, message = payload as string
     * - CURL_STATUS_FAILURE: n1 = CURL return code, n2 = HTTP result code, message = CURL error string
     */
    void curlRequestAsync(std::string url, std::string displayname);
```

The new status reporting callback:
```
    enum curlStatusType
    {
        CURL_STATUS_INVALID,
        CURL_STATUS_PROGRESS,
        CURL_STATUS_SUCCESS,
        CURL_STATUS_FAILURE,
    };

    /**
     * Params `n1`, `n2` and `message` depend on status type :
     * - CURL_STATUS_PROGRESS: n1 = bytes downloaded, n2 = total bytes, message = empty
     * - CURL_STATUS_SUCCESS: n1 = CURL return code, n2 = HTTP result code, message = payload as string
     * - CURL_STATUS_FAILURE: n1 = CURL return code, n2 = HTTP result code, message = CURL error string
     */
    void curlStatus(CurlStatusType type, int n1, int n2, std::string displayname, std::string message);
```
@ohlidalp
Copy link
Member Author

Wiki updated, commits cleaned up.

@ohlidalp ohlidalp merged commit 6f054ac into RigsOfRods:master Jan 26, 2025
3 checks passed
@ohlidalp ohlidalp deleted the servercurl branch January 26, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants