Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/protocol/rornet.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct UserInfo
char clientversion[25]; //!< a version number of the client. For example 1 for RoR 0.35
char clientGUID[40]; //!< the clients GUID
char sessiontype[10]; //!< the requested session type. For example "normal", "bot", "rcon"
char sessionoptions[128]; //!< reserved for future options
char sessiontoken[300]; //!< the session token to verify the client
};

struct VehicleState //!< Formerly `oob_t`
Expand Down
19 changes: 11 additions & 8 deletions source/server/CurlHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ static size_t CurlXferInfoFunc(void* ptr, curl_off_t filesize_B, curl_off_t down
return 0;
}

bool GetUrlAsString(const std::string& url, CURLcode& curl_result, long& response_code, std::string& response_payload)
bool GetUrlAsString(const std::string& url, const std::vector<std::string>& headers, CURLcode& curl_result, long& response_code, std::string& response_payload)
{
std::string response_header;
std::string user_agent = "Rigs of Rods Server";

struct curl_slist* slist;
slist = NULL;
for (const std::string& header : headers)
{
slist = curl_slist_append(slist, header.c_str());
}

CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
Expand All @@ -59,6 +66,7 @@ bool GetUrlAsString(const std::string& url, CURLcode& curl_result, long& respons
#endif // _WIN32
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");
curl_easy_setopt(curl, CURLOPT_USERAGENT, user_agent.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlStringWriteFunc);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, CurlXferInfoFunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_payload);
Expand All @@ -70,12 +78,7 @@ bool GetUrlAsString(const std::string& url, CURLcode& curl_result, long& respons
curl_easy_cleanup(curl);
curl = nullptr;

if (curl_result != CURLE_OK || response_code != 200)
{
return false;
}

return true;
return curl_result == CURLE_OK && response_code == 200;
}

bool CurlRequestThreadFunc(CurlTaskContext context)
Expand All @@ -84,7 +87,7 @@ bool CurlRequestThreadFunc(CurlTaskContext context)
std::string data;
CURLcode curl_result = CURLE_OK;
long http_response = 0;
if (GetUrlAsString(context.ctc_url, /*out:*/curl_result, /*out:*/http_response, /*out:*/data))
if (GetUrlAsString(context.ctc_url, context.ctc_headers, /*out:*/curl_result, /*out:*/http_response, /*out:*/data))
{
context.ctc_script_engine->curlStatus(CURL_STATUS_SUCCESS, (int)curl_result, (int)http_response, context.ctc_displayname, data);
return true;
Expand Down
5 changes: 3 additions & 2 deletions source/server/CurlHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ class ScriptEngine;
#include <curl/easy.h>

#include <string>

#include <vector>

struct CurlTaskContext
{
std::string ctc_displayname;
std::string ctc_url;
std::vector<std::string> ctc_headers;
ScriptEngine* ctc_script_engine;
// Status is reported via new server callback `curlStatus()`
};

bool GetUrlAsString(const std::string& url, CURLcode& curl_result, long& response_code, std::string& response_payload);
bool GetUrlAsString(const std::string& url, const std::vector<std::string>& headers, CURLcode& curl_result, long& response_code, std::string& response_payload);

bool CurlRequestThreadFunc(CurlTaskContext task);

Expand Down
7 changes: 1 addition & 6 deletions source/server/ScriptFileSafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
#ifdef WITH_ANGELSCRIPT

#include "ScriptFileSafe.h"
#include "win32_wrapper.h"
#include <new>
#include <assert.h>
#include <string>
Expand All @@ -32,12 +33,6 @@ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
#include "logger.h"
#include "config.h"

#ifdef _WIN32_WCE
#include <windows.h> // For GetModuleFileName
#ifdef GetObject
#undef GetObject
#endif
#endif

using namespace std;

Expand Down
Loading
Loading