Merge pull request #7008 from spycrab/ddos_sux
Fix "Download Codes" hitting DDOS protection
This commit is contained in:
commit
00d91db2ec
|
@ -28,6 +28,7 @@ public:
|
|||
explicit Impl(std::chrono::milliseconds timeout_ms, ProgressCallback callback);
|
||||
|
||||
bool IsValid() const;
|
||||
void SetCookies(const std::string& cookies);
|
||||
Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload,
|
||||
size_t size);
|
||||
|
||||
|
@ -56,6 +57,11 @@ bool HttpRequest::IsValid() const
|
|||
return m_impl->IsValid();
|
||||
}
|
||||
|
||||
void HttpRequest::SetCookies(const std::string& cookies)
|
||||
{
|
||||
m_impl->SetCookies(cookies);
|
||||
}
|
||||
|
||||
HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& headers)
|
||||
{
|
||||
return m_impl->Fetch(url, Impl::Method::GET, headers, nullptr, 0);
|
||||
|
@ -125,6 +131,11 @@ bool HttpRequest::Impl::IsValid() const
|
|||
return m_curl != nullptr;
|
||||
}
|
||||
|
||||
void HttpRequest::Impl::SetCookies(const std::string& cookies)
|
||||
{
|
||||
curl_easy_setopt(m_curl.get(), CURLOPT_COOKIE, cookies.c_str());
|
||||
}
|
||||
|
||||
static size_t CurlWriteCallback(char* data, size_t size, size_t nmemb, void* userdata)
|
||||
{
|
||||
auto* buffer = static_cast<std::vector<u8>*>(userdata);
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
|
||||
using Response = std::optional<std::vector<u8>>;
|
||||
using Headers = std::map<std::string, std::optional<std::string>>;
|
||||
|
||||
void SetCookies(const std::string& cookies);
|
||||
Response Get(const std::string& url, const Headers& headers = {});
|
||||
Response Post(const std::string& url, const std::vector<u8>& payload,
|
||||
const Headers& headers = {});
|
||||
|
|
|
@ -32,6 +32,10 @@ std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
|
|||
|
||||
std::string endpoint{"http://geckocodes.org/txt.php?txt=" + gameid};
|
||||
Common::HttpRequest http;
|
||||
|
||||
// Circumvent high-tech DDOS protection
|
||||
http.SetCookies("challenge=BitMitigate.com;");
|
||||
|
||||
const Common::HttpRequest::Response response = http.Get(endpoint);
|
||||
*succeeded = response.has_value();
|
||||
if (!response)
|
||||
|
|
Loading…
Reference in New Issue