mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-06-03 21:55:00 -06:00
Improve server call and actually use User-Agent header
This commit is contained in:
parent
58c326ef06
commit
aaaa890f10
@ -11,6 +11,13 @@
|
|||||||
#include "common/scm_rev.h"
|
#include "common/scm_rev.h"
|
||||||
|
|
||||||
namespace RetroAchievements {
|
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 {
|
namespace Callbacks {
|
||||||
// This is the function the rc_client will use to read memory for the emulator. we don't need it
|
// 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".
|
// 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) {
|
void* callback_data, rc_client_t* rc_client) {
|
||||||
LOG_DEBUG(RetroAchievements, "Attempting to call server.");
|
LOG_DEBUG(RetroAchievements, "Attempting to call server.");
|
||||||
|
|
||||||
// TODO: Make this a numeric version as per
|
if (std::strstr(request->url, base_url) == nullptr) {
|
||||||
// https://github.com/RetroAchievements/rcheevos/wiki/rc_client-integration#user-agent-header
|
LOG_ERROR(RetroAchievements, "Invalid URL: \"{}\"", request->url);
|
||||||
std::string user_agent = std::string("Azahar/") + Common::g_build_fullname;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
httplib::Client client(base_url);
|
||||||
|
const char* path = &request->url[sizeof(base_url) - 1];
|
||||||
|
|
||||||
// TODO: Should make this async?
|
// 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;
|
httplib::Result result;
|
||||||
if (request->post_data) {
|
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);
|
request->content_type);
|
||||||
} else {
|
} else {
|
||||||
result = client.Get("...");
|
result = client.Get(path, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user