From aaaa890f10a83cc9ca619c875c065dae710dfeb8 Mon Sep 17 00:00:00 2001 From: Chase Harkcom Date: Thu, 19 Feb 2026 11:44:54 -0700 Subject: [PATCH] Improve server call and actually use User-Agent header --- src/retroachievements/client.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/retroachievements/client.cpp b/src/retroachievements/client.cpp index f162c8313..43588b996 100644 --- a/src/retroachievements/client.cpp +++ b/src/retroachievements/client.cpp @@ -11,6 +11,13 @@ #include "common/scm_rev.h" namespace RetroAchievements { +static const char base_url[] = "https://retroachievements.org"; + +// TODO: Make this use a numeric version as per +// https://github.com/RetroAchievements/rcheevos/wiki/rc_client-integration#user-agent-header +static const std::string user_agent = std::string("Azahar/") + Common::g_build_fullname; +static const httplib::Headers headers = httplib::Headers({{"User-Agent", user_agent}}); + namespace Callbacks { // This is the function the rc_client will use to read memory for the emulator. we don't need it // yet, so just provide a dummy function that returns "no memory read". @@ -26,23 +33,21 @@ static void server_call(const rc_api_request_t* request, rc_client_server_callba void* callback_data, rc_client_t* rc_client) { LOG_DEBUG(RetroAchievements, "Attempting to call server."); - // TODO: Make this a numeric version as per - // https://github.com/RetroAchievements/rcheevos/wiki/rc_client-integration#user-agent-header - std::string user_agent = std::string("Azahar/") + Common::g_build_fullname; + if (std::strstr(request->url, base_url) == nullptr) { + LOG_ERROR(RetroAchievements, "Invalid URL: \"{}\"", request->url); + return; + } + + httplib::Client client(base_url); + const char* path = &request->url[sizeof(base_url) - 1]; // TODO: Should make this async? - // TODO: Use a persistent client since base URL will maybe be the same? Or instead just need to - // parse the URL into scheme-host-port and path. - - // httplib::Client client(request->url); - httplib::Client client("https://retroachievements.org"); - httplib::Result result; if (request->post_data) { - result = client.Post("/dorequest.php", request->post_data, std::strlen(request->post_data), + result = client.Post(path, headers, request->post_data, std::strlen(request->post_data), request->content_type); } else { - result = client.Get("..."); + result = client.Get(path, headers); } if (result) {