mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix small bug
Fixed bug caused by const char* to const string& conversion, resulting in the request message not always getting sent properly.
This commit is contained in:
parent
0399d753f4
commit
73fe590f99
@ -28,14 +28,15 @@ vector<NetGameServer_t> CPylon::GetServerList(string& outMessage) const
|
||||
nlohmann::json responseJson;
|
||||
CURLINFO status;
|
||||
|
||||
if (!SendRequest("/servers", requestJson, responseJson, outMessage, status, "Server list error"))
|
||||
if (!SendRequest("/servers", requestJson, responseJson,
|
||||
outMessage, status, "Server list error"))
|
||||
{
|
||||
return vecServers;
|
||||
}
|
||||
|
||||
if (!responseJson.contains("servers"))
|
||||
{
|
||||
outMessage = Format("Invalid response with status: %d", static_cast<int>(status));
|
||||
outMessage = Format("Invalid response with status: %d", int(status));
|
||||
return vecServers;
|
||||
}
|
||||
|
||||
@ -313,7 +314,7 @@ bool CPylon::QueryServer(const char* endpoint, const char* request,
|
||||
CURLFormatUrl(finalUrl, hostName, endpoint);
|
||||
|
||||
curl_slist* sList = nullptr;
|
||||
CURL* curl = CURLInitRequest(finalUrl, request, outResponse, sList);
|
||||
CURL* curl = CURLInitRequest(finalUrl.c_str(), request, outResponse, sList);
|
||||
if (!curl)
|
||||
{
|
||||
return false;
|
||||
@ -357,7 +358,7 @@ void CPylon::ExtractError(const nlohmann::json& resultJson, string& outMessage,
|
||||
errorText = "Unknown error with status";
|
||||
}
|
||||
|
||||
outMessage = Format("%s: %d", errorText, static_cast<int>(status));
|
||||
outMessage = Format("%s: %d", errorText, int(status));
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,11 +379,12 @@ void CPylon::ExtractError(const string& response, string& outMessage,
|
||||
}
|
||||
else if (status)
|
||||
{
|
||||
outMessage = Format("Failed comp-server query: %d", static_cast<int>(status));
|
||||
outMessage = Format("Failed comp-server query: %d", int(status));
|
||||
}
|
||||
else
|
||||
{
|
||||
outMessage = Format("Failed to reach comp-server: %s", "connection timed-out");
|
||||
outMessage = Format("Failed to reach comp-server: %s",
|
||||
"connection timed out");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
#ifndef TIER2_CURLUTILS_H
|
||||
#define TIER2_CURLUTILS_H
|
||||
|
||||
size_t CURLWriteStringCallback(char* contents, size_t size, size_t nmemb, void* userp);
|
||||
size_t CURLWriteStringCallback(char* contents, const size_t size, const size_t nmemb, void* userp);
|
||||
|
||||
CURL* CURLInitRequest(const string& remote, const string& request, string& response, curl_slist*& slist);
|
||||
CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist);
|
||||
CURLcode CURLSubmitRequest(CURL* curl, curl_slist*& slist);
|
||||
CURLINFO CURLRetrieveInfo(CURL* curl);
|
||||
|
||||
bool CURLHandleError(CURL* curl, CURLcode res, string& outMessage);
|
||||
void CURLFormatUrl(string& url, const string& host, const string& api);
|
||||
void CURLFormatUrl(string& outUrl, const char* host, const char* api);
|
||||
|
||||
#endif // !TIER2_CURLUTILS_H
|
@ -7,13 +7,13 @@
|
||||
#include "tier1/cvar.h"
|
||||
#include "tier2/curlutils.h"
|
||||
|
||||
size_t CURLWriteStringCallback(char* contents, size_t size, size_t nmemb, void* userp)
|
||||
size_t CURLWriteStringCallback(char* contents, const size_t size, const size_t nmemb, void* userp)
|
||||
{
|
||||
reinterpret_cast<string*>(userp)->append(contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
CURL* CURLInitRequest(const string& remote, const string& request, string& response, curl_slist*& slist)
|
||||
CURL* CURLInitRequest(const char* remote, const char* request, string& outResponse, curl_slist*& slist)
|
||||
{
|
||||
std::function<void(const char*)> fnError = [&](const char* errorMsg)
|
||||
{
|
||||
@ -36,14 +36,14 @@ CURL* CURLInitRequest(const string& remote, const string& request, string& respo
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, remote.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str());
|
||||
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_USE_SSL, CURLUSESSL_ALL);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CURLWriteStringCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &outResponse);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, curl_debug->GetBool());
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
|
||||
@ -89,7 +89,7 @@ bool CURLHandleError(CURL* curl, CURLcode res, string& outMessage)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CURLFormatUrl(string& url, const string& host, const string& api)
|
||||
void CURLFormatUrl(string& outUrl, const char* host, const char* api)
|
||||
{
|
||||
url = Format("%s%s%s", "https://", host.c_str(), api.c_str());
|
||||
outUrl = Format("%s%s%s", "https://", host, api);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user