diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index 35956b4e1..e770ea233 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -210,9 +210,10 @@ void ConfigureGeneral::RetranslateUI() { void ConfigureGeneral::RetroAchievementsLogIn() { #ifdef ENABLE_RETROACHIEVEMENTS std::string username = ui->retroachievements_username_input->text().toStdString(), - password = ui->retroachievements_password_input->text().toStdString(); + password = ui->retroachievements_password_input->text().toStdString(); - Core::System::GetInstance().RetroAchievementsClient().LogInUser(username.c_str(), password.c_str()); + Core::System::GetInstance().RetroAchievementsClient().LogInUser(username.c_str(), + password.c_str()); #endif } diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index e4710c91f..c951a5b1c 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp @@ -137,7 +137,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { CLS(Movie) \ CLS(Loader) \ CLS(WebService) \ - CLS(RPC_Server) \ + CLS(RPC_Server) \ CLS(RetroAchievements) // GetClassName is a macro defined by Windows.h, grrr... diff --git a/src/core/core.cpp b/src/core/core.cpp index 707e859af..e55eeb77b 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -663,11 +663,11 @@ const Cheats::CheatEngine& System::CheatEngine() const { } #ifdef ENABLE_RETROACHIEVEMENTS -RetroAchievements::Client &System::RetroAchievementsClient() { +RetroAchievements::Client& System::RetroAchievementsClient() { return *retroachievements_client; } -const RetroAchievements::Client &System::RetroAchievementsClient() const { +const RetroAchievements::Client& System::RetroAchievementsClient() const { return *retroachievements_client; } #endif diff --git a/src/core/core.h b/src/core/core.h index b261a1a88..73c520836 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -285,10 +285,10 @@ public: #ifdef ENABLE_RETROACHIEVEMENTS // Gets a reference to the RetroAchievements client - [[nodiscard]] RetroAchievements::Client &RetroAchievementsClient(); + [[nodiscard]] RetroAchievements::Client& RetroAchievementsClient(); // Gets a const reference to the RetroAchievements client - [[nodiscard]] const RetroAchievements::Client &RetroAchievementsClient() const; + [[nodiscard]] const RetroAchievements::Client& RetroAchievementsClient() const; #endif /// Gets a reference to the custom texture cache system diff --git a/src/retroachievements/client.cpp b/src/retroachievements/client.cpp index 748512967..fe51db989 100644 --- a/src/retroachievements/client.cpp +++ b/src/retroachievements/client.cpp @@ -10,93 +10,97 @@ #include "common/logging/log.h" #include "common/scm_rev.h" -namespace RetroAchievements -{ +namespace RetroAchievements { 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". -static uint32_t read_memory(uint32_t address, uint8_t* buffer, uint32_t num_bytes, rc_client_t* client) -{ - // TODO: implement later - LOG_DEBUG(RetroAchievements, "Attempting to read memory."); +// 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". +static uint32_t read_memory(uint32_t address, uint8_t* buffer, uint32_t num_bytes, + rc_client_t* client) { + // TODO: implement later + LOG_DEBUG(RetroAchievements, "Attempting to read memory."); - return 0; + return 0; } -static void server_call(const rc_api_request_t* request, rc_client_server_callback_t callback, void* callback_data, rc_client_t* rc_client) -{ - LOG_DEBUG(RetroAchievements, "Attempting to call server."); +static void server_call(const rc_api_request_t* request, rc_client_server_callback_t callback, + void* callback_data, rc_client_t* rc_client) { + LOG_DEBUG(RetroAchievements, "Attempting to call server."); - std::string user_agent = std::string("Azahar/") + Common::g_build_fullname; // 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; // TODO: Make this a numeric version as per + // https://github.com/RetroAchievements/rcheevos/wiki/rc_client-integration#user-agent-header - // 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. + // 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::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), request->content_type); - } else { - result = client.Get("..."); - } + httplib::Result result; + if (request->post_data) { + result = client.Post("/dorequest.php", request->post_data, std::strlen(request->post_data), + request->content_type); + } else { + result = client.Get("..."); + } - if (result) { - LOG_DEBUG(RetroAchievements, "Status: {}", result->status); - LOG_DEBUG(RetroAchievements, "Body: {}", result->body); + if (result) { + LOG_DEBUG(RetroAchievements, "Status: {}", result->status); + LOG_DEBUG(RetroAchievements, "Body: {}", result->body); - rc_api_server_response_t server_response = { .body = result->body.c_str(), .body_length = result->body.length(), .http_status_code = result->status }; - callback(&server_response, callback_data); - } else { - LOG_DEBUG(RetroAchievements, "HTTP error {}", result.error()); - } + rc_api_server_response_t server_response = {.body = result->body.c_str(), + .body_length = result->body.length(), + .http_status_code = result->status}; + callback(&server_response, callback_data); + } else { + LOG_DEBUG(RetroAchievements, "HTTP error {}", result.error()); + } } // Write log messages to the console -static void log_message(const char* message, const rc_client_t* client) -{ - LOG_DEBUG(RetroAchievements, "RetroAchievements internal message: \"{}\"", message); -} +static void log_message(const char* message, const rc_client_t* client) { + LOG_DEBUG(RetroAchievements, "RetroAchievements internal message: \"{}\"", message); } +} // namespace Callbacks Client::Client(const Core::System& _system) : system{_system} {} Client::~Client() { - if (rc_client) { - rc_client_destroy(rc_client); - rc_client = NULL; - } + if (rc_client) { + rc_client_destroy(rc_client); + rc_client = NULL; + } } void Client::Initialize() { - LOG_DEBUG(RetroAchievements, "Initializing RetroAchievements client."); + LOG_DEBUG(RetroAchievements, "Initializing RetroAchievements client."); - rc_client = rc_client_create(Callbacks::read_memory, Callbacks::server_call); - rc_client_enable_logging(rc_client, RC_CLIENT_LOG_LEVEL_VERBOSE, Callbacks::log_message); - rc_client_set_hardcore_enabled(rc_client, 0); + rc_client = rc_client_create(Callbacks::read_memory, Callbacks::server_call); + rc_client_enable_logging(rc_client, RC_CLIENT_LOG_LEVEL_VERBOSE, Callbacks::log_message); + rc_client_set_hardcore_enabled(rc_client, 0); } -static void login_callback(int result, const char* error_message, rc_client_t* client, void* userdata) -{ - // If not successful, just report the error and bail. - if (result != RC_OK) - { - LOG_ERROR(RetroAchievements, "Login failed."); - return; - } +static void login_callback(int result, const char* error_message, rc_client_t* client, + void* userdata) { + // If not successful, just report the error and bail. + if (result != RC_OK) { + LOG_ERROR(RetroAchievements, "Login failed."); + return; + } - // Login was successful. Capture the token for future logins so we don't have to store the password anywhere. - const rc_client_user_t* user = rc_client_get_user_info(client); - // store_retroachievements_credentials(user->username, user->token); + // Login was successful. Capture the token for future logins so we don't have to store the + // password anywhere. + const rc_client_user_t* user = rc_client_get_user_info(client); + // store_retroachievements_credentials(user->username, user->token); - // Inform user of successful login - LOG_INFO(RetroAchievements, "Logged in as {} ({} points)", user->display_name, user->score); + // Inform user of successful login + LOG_INFO(RetroAchievements, "Logged in as {} ({} points)", user->display_name, user->score); } - -void Client::LogInUser(const char* username, const char* password) -{ - rc_client_begin_login_with_password(rc_client, username, password, login_callback, NULL); +void Client::LogInUser(const char* username, const char* password) { + rc_client_begin_login_with_password(rc_client, username, password, login_callback, NULL); } } // namespace RetroAchievements diff --git a/src/retroachievements/client.h b/src/retroachievements/client.h index 7e5dbd9f3..c8005b7e6 100644 --- a/src/retroachievements/client.h +++ b/src/retroachievements/client.h @@ -6,18 +6,18 @@ class System; struct rc_client_t; -namespace RetroAchievements -{ - class Client { - public: - explicit Client(const Core::System& system); - ~Client(); +namespace RetroAchievements { +class Client { +public: + explicit Client(const Core::System& system); + ~Client(); - void Initialize(); + void Initialize(); - void LogInUser(const char* username, const char* password); - private: - const Core::System& system; - rc_client_t* rc_client = nullptr; - }; + void LogInUser(const char* username, const char* password); + +private: + const Core::System& system; + rc_client_t* rc_client = nullptr; +}; } // namespace RetroAchievements