From 31d92b439f0fa3fb9e565594c730d18e8972e77d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:52:49 +0200 Subject: [PATCH] Move cvars from curlutils.cpp Move it elsewhere so this code can be shared among tools that don't feature the ConVar class. --- r5dev/common/global.cpp | 4 ++++ r5dev/common/global.h | 4 ++++ r5dev/networksystem/pylon.cpp | 3 ++- r5dev/public/tier2/curlutils.h | 7 ++----- r5dev/tier2/curlutils.cpp | 13 +++++-------- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/r5dev/common/global.cpp b/r5dev/common/global.cpp index 44b296da..094fcd33 100644 --- a/r5dev/common/global.cpp +++ b/r5dev/common/global.cpp @@ -239,6 +239,10 @@ ConVar* net_datablock_networkLossForSlowSpeed = nullptr; ConVar* pylon_matchmaking_hostname = nullptr; ConVar* pylon_host_update_interval = nullptr; ConVar* pylon_showdebuginfo = nullptr; + +ConVar* ssl_verify_peer = nullptr; +ConVar* curl_timeout = nullptr; +ConVar* curl_debug = nullptr; //----------------------------------------------------------------------------- // RTECH API | ConVar* rtech_debug = nullptr; diff --git a/r5dev/common/global.h b/r5dev/common/global.h index 3dead3ef..13a5e660 100644 --- a/r5dev/common/global.h +++ b/r5dev/common/global.h @@ -225,6 +225,10 @@ extern ConVar* net_datablock_networkLossForSlowSpeed; extern ConVar* pylon_matchmaking_hostname; extern ConVar* pylon_host_update_interval; extern ConVar* pylon_showdebuginfo; + +extern ConVar* ssl_verify_peer; +extern ConVar* curl_timeout; +extern ConVar* curl_debug; //------------------------------------------------------------------------- // RTECH API | extern ConVar* rtech_debug; diff --git a/r5dev/networksystem/pylon.cpp b/r5dev/networksystem/pylon.cpp index 0c8b91ce..0ce2823f 100644 --- a/r5dev/networksystem/pylon.cpp +++ b/r5dev/networksystem/pylon.cpp @@ -362,7 +362,8 @@ bool CPylon::QueryServer(const char* endpoint, const char* request, CURLFormatUrl(finalUrl, hostName, endpoint); curl_slist* sList = nullptr; - CURL* curl = CURLInitRequest(finalUrl.c_str(), request, outResponse, sList); + CURL* curl = CURLInitRequest(finalUrl.c_str(), request, outResponse, sList, + curl_timeout->GetInt(), ssl_verify_peer->GetBool(), curl_debug->GetBool()); if (!curl) { return false; diff --git a/r5dev/public/tier2/curlutils.h b/r5dev/public/tier2/curlutils.h index 5d1f1cfb..1a1722ee 100644 --- a/r5dev/public/tier2/curlutils.h +++ b/r5dev/public/tier2/curlutils.h @@ -1,13 +1,10 @@ #ifndef TIER2_CURLUTILS_H #define TIER2_CURLUTILS_H -extern ConVar* ssl_verify_peer; -extern ConVar* curl_timeout; -extern ConVar* curl_debug; - size_t CURLWriteStringCallback(char* contents, const size_t size, const size_t nmemb, void* userp); -CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist); +CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist, + const int timeOut, const bool verifyPeer, const bool debug, const void* writeFunction = CURLWriteStringCallback); CURLcode CURLSubmitRequest(CURL* curl, curl_slist*& slist); CURLINFO CURLRetrieveInfo(CURL* curl); diff --git a/r5dev/tier2/curlutils.cpp b/r5dev/tier2/curlutils.cpp index c8a31d83..fa99d13c 100644 --- a/r5dev/tier2/curlutils.cpp +++ b/r5dev/tier2/curlutils.cpp @@ -6,17 +6,14 @@ #include "tier1/cvar.h" #include "tier2/curlutils.h" -ConVar* ssl_verify_peer = nullptr; -ConVar* curl_timeout = nullptr; -ConVar* curl_debug = nullptr; - size_t CURLWriteStringCallback(char* contents, const size_t size, const size_t nmemb, void* userp) { reinterpret_cast(userp)->append(contents, size * nmemb); return size * nmemb; } -CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist) +CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist, + const int timeOut, const bool verifyPeer, const bool debug, const void* writeFunction) { std::function fnError = [&](const char* errorMsg) { @@ -42,16 +39,16 @@ CURL* CURLInitRequest(const char* remote, const char* request, string& outRespon curl_easy_setopt(curl, CURLOPT_URL, remote); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request); curl_easy_setopt(curl, CURLOPT_POST, 1L); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, curl_timeout->GetInt()); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeOut); curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CURLWriteStringCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &outResponse); - curl_easy_setopt(curl, CURLOPT_VERBOSE, curl_debug->GetBool()); + curl_easy_setopt(curl, CURLOPT_VERBOSE, debug); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); - if (!ssl_verify_peer->GetBool()) + if (!verifyPeer) { curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); }