Jump to content
Sign in to follow this  
Bashelion

Questions about the extension

Recommended Posts

Hi everyone!
English is not my native language, so I use my little knowledge and Google translator
I have 2 questions about arma3 extensions:
1) BE always blocks my extensions, even if you take those that are given on the wiki. 
At the same time, he warns that he can launch the extension if it does not stop the game process.
But apparently it doesn't work that way.
Is it possible to do something about this without entering(including) the extension in the whitelist?
I'm going to use this extension only on the server.
2) My extension makes a request using libCURL, but during the request, the game hangs(stop) for 2-5 seconds.
I read that it's kind of possible to solve this with callbacks. I saw an example on the wiki.
But my knowledge of C++ is not so good, could you help me adapt my sample code for a callback.
At the same time, so that it works the same as the usual RVExtensionArgs function, returning [result, returncode, errorcode] or [result, returncode].

 

Shortly example my code:

Spoiler

extern "C" {
    __declspec (dllexport) void __stdcall RVExtension(char* output, int outputSize, const char* function);
    __declspec (dllexport) int __stdcall RVExtensionArgs(char* output, int outputSize, const char* function, const char** args, int argsCnt);
}
void __stdcall RVExtension(char* output, int outputSize, const char* function) {
    strncpy_s(output, outputSize, "it work!", _TRUNCATE);
}

int curl_POST(const char* port, const char* json, char* output, int outputSize) {
    CURL* curl = nullptr;
    CURLcode res;
    static const char* postthis = json;
    std::string comment;

    curl = curl_easy_init();
    if (curl) {
        std::string prt = std::regex_replace(port, std::regex("\""), "\0");
        curl_easy_setopt(curl, CURLOPT_URL, prt);
        curl_easy_setopt(curl, CURLOPT_POST, 1);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));

        res = curl_easy_perform(curl);
		
        if (res != CURLE_OK) {
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));
            strncpy_s(output, outputSize, curl_easy_strerror(res), _TRUNCATE);
            return 1002;
        }
        curl_easy_cleanup(curl);
        comment = "OK";
        strncpy_s(output, outputSize, comment.c_str(), _TRUNCATE);
        return 1000;
    }
    else {
        comment = "example comment";
        strncpy_s(output, outputSize, comment.c_str(), _TRUNCATE);
        return 1003;
    }
}
//--- name callExtension [function, args]
int __stdcall RVExtensionArgs(char* output, int outputSize, const char* req, const char** args, int argsCnt)
{
    int status;
    status = curl_POST(args[0], args[1], output, outputSize);
    return status;
}

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×