Merge pull request #12580 from LillyJadeKatrin/retroachievements-bugfix
Add user agent to headers for all RetroAchievements server calls
This commit is contained in:
commit
c04460d88b
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
|
#define EMULATOR_NAME "Dolphin"
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define BUILD_TYPE_STR "Debug "
|
#define BUILD_TYPE_STR "Debug "
|
||||||
#elif defined DEBUGFAST
|
#elif defined DEBUGFAST
|
||||||
|
@ -19,10 +21,10 @@ namespace Common
|
||||||
|
|
||||||
const std::string& GetScmRevStr()
|
const std::string& GetScmRevStr()
|
||||||
{
|
{
|
||||||
static const std::string scm_rev_str = "Dolphin "
|
static const std::string scm_rev_str = EMULATOR_NAME " "
|
||||||
// Note this macro can be empty if the master branch does not exist.
|
// Note this macro can be empty if the master branch does not exist.
|
||||||
#if 1 - SCM_COMMITS_AHEAD_MASTER - 1 != 0
|
#if 1 - SCM_COMMITS_AHEAD_MASTER - 1 != 0
|
||||||
"[" SCM_BRANCH_STR "] "
|
"[" SCM_BRANCH_STR "] "
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __INTEL_COMPILER
|
#ifdef __INTEL_COMPILER
|
||||||
|
@ -51,6 +53,12 @@ const std::string& GetScmBranchStr()
|
||||||
return scm_branch_str;
|
return scm_branch_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& GetUserAgentStr()
|
||||||
|
{
|
||||||
|
static const std::string user_agent_str = EMULATOR_NAME "/" SCM_DESC_STR;
|
||||||
|
return user_agent_str;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& GetScmDistributorStr()
|
const std::string& GetScmDistributorStr()
|
||||||
{
|
{
|
||||||
static const std::string scm_distributor_str = SCM_DISTRIBUTOR_STR;
|
static const std::string scm_distributor_str = SCM_DISTRIBUTOR_STR;
|
||||||
|
|
|
@ -11,6 +11,7 @@ const std::string& GetScmDescStr();
|
||||||
const std::string& GetScmBranchStr();
|
const std::string& GetScmBranchStr();
|
||||||
const std::string& GetScmRevStr();
|
const std::string& GetScmRevStr();
|
||||||
const std::string& GetScmRevGitStr();
|
const std::string& GetScmRevGitStr();
|
||||||
|
const std::string& GetUserAgentStr();
|
||||||
const std::string& GetScmDistributorStr();
|
const std::string& GetScmDistributorStr();
|
||||||
const std::string& GetScmUpdateTrackStr();
|
const std::string& GetScmUpdateTrackStr();
|
||||||
const std::string& GetNetplayDolphinVer();
|
const std::string& GetNetplayDolphinVer();
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "Common/Image.h"
|
#include "Common/Image.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/ScopeGuard.h"
|
#include "Common/ScopeGuard.h"
|
||||||
|
#include "Common/Version.h"
|
||||||
#include "Common/WorkQueueThread.h"
|
#include "Common/WorkQueueThread.h"
|
||||||
#include "Core/Config/AchievementSettings.h"
|
#include "Core/Config/AchievementSettings.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
|
@ -29,6 +30,9 @@
|
||||||
#include "VideoCommon/OnScreenDisplay.h"
|
#include "VideoCommon/OnScreenDisplay.h"
|
||||||
#include "VideoCommon/VideoEvents.h"
|
#include "VideoCommon/VideoEvents.h"
|
||||||
|
|
||||||
|
static const Common::HttpRequest::Headers USER_AGENT_HEADER = {
|
||||||
|
{"User-Agent", Common::GetUserAgentStr()}};
|
||||||
|
|
||||||
AchievementManager& AchievementManager::GetInstance()
|
AchievementManager& AchievementManager::GetInstance()
|
||||||
{
|
{
|
||||||
static AchievementManager s_instance;
|
static AchievementManager s_instance;
|
||||||
|
@ -848,42 +852,39 @@ void AchievementManager::Request(const rc_api_request_t* request,
|
||||||
{
|
{
|
||||||
std::string url = request->url;
|
std::string url = request->url;
|
||||||
std::string post_data = request->post_data;
|
std::string post_data = request->post_data;
|
||||||
AchievementManager::GetInstance().m_queue.EmplaceItem([url = std::move(url),
|
AchievementManager::GetInstance().m_queue.EmplaceItem(
|
||||||
post_data = std::move(post_data),
|
[url = std::move(url), post_data = std::move(post_data), callback = std::move(callback),
|
||||||
callback = std::move(callback),
|
callback_data = std::move(callback_data)] {
|
||||||
callback_data = std::move(callback_data)] {
|
Common::HttpRequest http_request;
|
||||||
const Common::HttpRequest::Headers USER_AGENT_HEADER = {{"User-Agent", "Dolphin/Placeholder"}};
|
Common::HttpRequest::Response http_response;
|
||||||
|
if (!post_data.empty())
|
||||||
|
{
|
||||||
|
http_response = http_request.Post(url, post_data, USER_AGENT_HEADER,
|
||||||
|
Common::HttpRequest::AllowedReturnCodes::All);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
http_response = http_request.Get(url, USER_AGENT_HEADER,
|
||||||
|
Common::HttpRequest::AllowedReturnCodes::All);
|
||||||
|
}
|
||||||
|
|
||||||
Common::HttpRequest http_request;
|
rc_api_server_response_t server_response;
|
||||||
Common::HttpRequest::Response http_response;
|
if (http_response.has_value() && http_response->size() > 0)
|
||||||
if (!post_data.empty())
|
{
|
||||||
{
|
server_response.body = reinterpret_cast<const char*>(http_response->data());
|
||||||
http_response = http_request.Post(url, post_data, USER_AGENT_HEADER,
|
server_response.body_length = http_response->size();
|
||||||
Common::HttpRequest::AllowedReturnCodes::All);
|
server_response.http_status_code = http_request.GetLastResponseCode();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
http_response =
|
constexpr char error_message[] = "Failed HTTP request.";
|
||||||
http_request.Get(url, USER_AGENT_HEADER, Common::HttpRequest::AllowedReturnCodes::All);
|
server_response.body = error_message;
|
||||||
}
|
server_response.body_length = sizeof(error_message);
|
||||||
|
server_response.http_status_code = RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
rc_api_server_response_t server_response;
|
callback(&server_response, callback_data);
|
||||||
if (http_response.has_value() && http_response->size() > 0)
|
});
|
||||||
{
|
|
||||||
server_response.body = reinterpret_cast<const char*>(http_response->data());
|
|
||||||
server_response.body_length = http_response->size();
|
|
||||||
server_response.http_status_code = http_request.GetLastResponseCode();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
constexpr char error_message[] = "Failed HTTP request.";
|
|
||||||
server_response.body = error_message;
|
|
||||||
server_response.body_length = sizeof(error_message);
|
|
||||||
server_response.http_status_code = RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(&server_response, callback_data);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 AchievementManager::MemoryPeeker(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client)
|
u32 AchievementManager::MemoryPeeker(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client)
|
||||||
|
@ -939,7 +940,8 @@ void AchievementManager::FetchBadge(AchievementManager::Badge* badge, u32 badge_
|
||||||
ERROR_LOG_FMT(ACHIEVEMENTS, "Invalid request for image {}.", name_to_fetch);
|
ERROR_LOG_FMT(ACHIEVEMENTS, "Invalid request for image {}.", name_to_fetch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto http_response = http_request.Get(api_request.url);
|
auto http_response = http_request.Get(api_request.url, USER_AGENT_HEADER,
|
||||||
|
Common::HttpRequest::AllowedReturnCodes::All);
|
||||||
if (http_response.has_value() && http_response->size() <= 0)
|
if (http_response.has_value() && http_response->size() <= 0)
|
||||||
{
|
{
|
||||||
WARN_LOG_FMT(ACHIEVEMENTS, "RetroAchievements connection failed on image request.\n URL: {}",
|
WARN_LOG_FMT(ACHIEVEMENTS, "RetroAchievements connection failed on image request.\n URL: {}",
|
||||||
|
|
Loading…
Reference in New Issue