Skip to content

Commit

Permalink
Merge pull request #7769 from Tilka/gecko_codes
Browse files Browse the repository at this point in the history
Fix Gecko Code downloading
  • Loading branch information
Tilka committed Feb 1, 2019
2 parents a129d60 + 4090c19 commit 363ce67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Source/Core/Common/HttpRequest.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class HttpRequest::Impl final
bool IsValid() const; bool IsValid() const;
void SetCookies(const std::string& cookies); void SetCookies(const std::string& cookies);
void UseIPv4(); void UseIPv4();
void FollowRedirects(long max);
Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload, Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload,
size_t size); size_t size);


Expand Down Expand Up @@ -68,6 +69,11 @@ void HttpRequest::UseIPv4()
m_impl->UseIPv4(); m_impl->UseIPv4();
} }


void HttpRequest::FollowRedirects(long max)
{
m_impl->FollowRedirects(max);
}

HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& headers) HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& headers)
{ {
return m_impl->Fetch(url, Impl::Method::GET, headers, nullptr, 0); return m_impl->Fetch(url, Impl::Method::GET, headers, nullptr, 0);
Expand Down Expand Up @@ -147,6 +153,12 @@ void HttpRequest::Impl::UseIPv4()
curl_easy_setopt(m_curl.get(), CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_easy_setopt(m_curl.get(), CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
} }


void HttpRequest::Impl::FollowRedirects(long max)
{
curl_easy_setopt(m_curl.get(), CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(m_curl.get(), CURLOPT_MAXREDIRS, max);
}

static size_t CurlWriteCallback(char* data, size_t size, size_t nmemb, void* userdata) static size_t CurlWriteCallback(char* data, size_t size, size_t nmemb, void* userdata)
{ {
auto* buffer = static_cast<std::vector<u8>*>(userdata); auto* buffer = static_cast<std::vector<u8>*>(userdata);
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/HttpRequest.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class HttpRequest final


void SetCookies(const std::string& cookies); void SetCookies(const std::string& cookies);
void UseIPv4(); void UseIPv4();
void FollowRedirects(long max = 1);
Response Get(const std::string& url, const Headers& headers = {}); Response Get(const std::string& url, const Headers& headers = {});
Response Post(const std::string& url, const std::vector<u8>& payload, Response Post(const std::string& url, const std::vector<u8>& payload,
const Headers& headers = {}); const Headers& headers = {});
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/Core/GeckoCodeConfig.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
break; break;
} }


std::string endpoint{"https://geckocodes.org/txt.php?txt=" + gameid}; std::string endpoint{"https://www.geckocodes.org/txt.php?txt=" + gameid};
Common::HttpRequest http; Common::HttpRequest http;


// Circumvent high-tech DDOS protection // Circumvent high-tech DDOS protection
http.SetCookies("challenge=BitMitigate.com;"); http.SetCookies("challenge=BitMitigate.com;");


// The server always redirects once to the same location.
http.FollowRedirects(1);

const Common::HttpRequest::Response response = http.Get(endpoint); const Common::HttpRequest::Response response = http.Get(endpoint);
*succeeded = response.has_value(); *succeeded = response.has_value();
if (!response) if (!response)
Expand Down

0 comments on commit 363ce67

Please sign in to comment.