mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-06-04 06:05:00 -06:00
Run clang-format
This commit is contained in:
parent
0e5d0a3418
commit
d207e80a51
@ -210,9 +210,10 @@ void ConfigureGeneral::RetranslateUI() {
|
|||||||
void ConfigureGeneral::RetroAchievementsLogIn() {
|
void ConfigureGeneral::RetroAchievementsLogIn() {
|
||||||
#ifdef ENABLE_RETROACHIEVEMENTS
|
#ifdef ENABLE_RETROACHIEVEMENTS
|
||||||
std::string username = ui->retroachievements_username_input->text().toStdString(),
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -137,7 +137,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
|
|||||||
CLS(Movie) \
|
CLS(Movie) \
|
||||||
CLS(Loader) \
|
CLS(Loader) \
|
||||||
CLS(WebService) \
|
CLS(WebService) \
|
||||||
CLS(RPC_Server) \
|
CLS(RPC_Server) \
|
||||||
CLS(RetroAchievements)
|
CLS(RetroAchievements)
|
||||||
|
|
||||||
// GetClassName is a macro defined by Windows.h, grrr...
|
// GetClassName is a macro defined by Windows.h, grrr...
|
||||||
|
|||||||
@ -663,11 +663,11 @@ const Cheats::CheatEngine& System::CheatEngine() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_RETROACHIEVEMENTS
|
#ifdef ENABLE_RETROACHIEVEMENTS
|
||||||
RetroAchievements::Client &System::RetroAchievementsClient() {
|
RetroAchievements::Client& System::RetroAchievementsClient() {
|
||||||
return *retroachievements_client;
|
return *retroachievements_client;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RetroAchievements::Client &System::RetroAchievementsClient() const {
|
const RetroAchievements::Client& System::RetroAchievementsClient() const {
|
||||||
return *retroachievements_client;
|
return *retroachievements_client;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -285,10 +285,10 @@ public:
|
|||||||
|
|
||||||
#ifdef ENABLE_RETROACHIEVEMENTS
|
#ifdef ENABLE_RETROACHIEVEMENTS
|
||||||
// Gets a reference to the RetroAchievements client
|
// Gets a reference to the RetroAchievements client
|
||||||
[[nodiscard]] RetroAchievements::Client &RetroAchievementsClient();
|
[[nodiscard]] RetroAchievements::Client& RetroAchievementsClient();
|
||||||
|
|
||||||
// Gets a const reference to the RetroAchievements client
|
// Gets a const reference to the RetroAchievements client
|
||||||
[[nodiscard]] const RetroAchievements::Client &RetroAchievementsClient() const;
|
[[nodiscard]] const RetroAchievements::Client& RetroAchievementsClient() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Gets a reference to the custom texture cache system
|
/// Gets a reference to the custom texture cache system
|
||||||
|
|||||||
@ -10,93 +10,97 @@
|
|||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/scm_rev.h"
|
#include "common/scm_rev.h"
|
||||||
|
|
||||||
namespace RetroAchievements
|
namespace RetroAchievements {
|
||||||
{
|
|
||||||
namespace Callbacks {
|
namespace Callbacks {
|
||||||
// This is the function the rc_client will use to read memory for the emulator. we don't need it yet,
|
// This is the function the rc_client will use to read memory for the emulator. we don't need it
|
||||||
// so just provide a dummy function that returns "no memory read".
|
// 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)
|
static uint32_t read_memory(uint32_t address, uint8_t* buffer, uint32_t num_bytes,
|
||||||
{
|
rc_client_t* client) {
|
||||||
// TODO: implement later
|
// TODO: implement later
|
||||||
LOG_DEBUG(RetroAchievements, "Attempting to read memory.");
|
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)
|
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.");
|
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: 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: 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(request->url);
|
||||||
httplib::Client client("https://retroachievements.org");
|
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), request->content_type);
|
result = client.Post("/dorequest.php", request->post_data, std::strlen(request->post_data),
|
||||||
} else {
|
request->content_type);
|
||||||
result = client.Get("...");
|
} else {
|
||||||
}
|
result = client.Get("...");
|
||||||
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
LOG_DEBUG(RetroAchievements, "Status: {}", result->status);
|
LOG_DEBUG(RetroAchievements, "Status: {}", result->status);
|
||||||
LOG_DEBUG(RetroAchievements, "Body: {}", result->body);
|
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 };
|
rc_api_server_response_t server_response = {.body = result->body.c_str(),
|
||||||
callback(&server_response, callback_data);
|
.body_length = result->body.length(),
|
||||||
} else {
|
.http_status_code = result->status};
|
||||||
LOG_DEBUG(RetroAchievements, "HTTP error {}", result.error());
|
callback(&server_response, callback_data);
|
||||||
}
|
} else {
|
||||||
|
LOG_DEBUG(RetroAchievements, "HTTP error {}", result.error());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write log messages to the console
|
// Write log messages to the console
|
||||||
static void log_message(const char* message, const rc_client_t* client)
|
static void log_message(const char* message, const rc_client_t* client) {
|
||||||
{
|
LOG_DEBUG(RetroAchievements, "RetroAchievements internal message: \"{}\"", message);
|
||||||
LOG_DEBUG(RetroAchievements, "RetroAchievements internal message: \"{}\"", message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace Callbacks
|
||||||
|
|
||||||
Client::Client(const Core::System& _system) : system{_system} {}
|
Client::Client(const Core::System& _system) : system{_system} {}
|
||||||
|
|
||||||
Client::~Client() {
|
Client::~Client() {
|
||||||
if (rc_client) {
|
if (rc_client) {
|
||||||
rc_client_destroy(rc_client);
|
rc_client_destroy(rc_client);
|
||||||
rc_client = NULL;
|
rc_client = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::Initialize() {
|
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 = 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_enable_logging(rc_client, RC_CLIENT_LOG_LEVEL_VERBOSE, Callbacks::log_message);
|
||||||
rc_client_set_hardcore_enabled(rc_client, 0);
|
rc_client_set_hardcore_enabled(rc_client, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void login_callback(int result, const char* error_message, rc_client_t* client, void* userdata)
|
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 not successful, just report the error and bail.
|
||||||
if (result != RC_OK)
|
if (result != RC_OK) {
|
||||||
{
|
LOG_ERROR(RetroAchievements, "Login failed.");
|
||||||
LOG_ERROR(RetroAchievements, "Login failed.");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Login was successful. Capture the token for future logins so we don't have to store the password anywhere.
|
// Login was successful. Capture the token for future logins so we don't have to store the
|
||||||
const rc_client_user_t* user = rc_client_get_user_info(client);
|
// password anywhere.
|
||||||
// store_retroachievements_credentials(user->username, user->token);
|
const rc_client_user_t* user = rc_client_get_user_info(client);
|
||||||
|
// store_retroachievements_credentials(user->username, user->token);
|
||||||
|
|
||||||
// Inform user of successful login
|
// Inform user of successful login
|
||||||
LOG_INFO(RetroAchievements, "Logged in as {} ({} points)", user->display_name, user->score);
|
LOG_INFO(RetroAchievements, "Logged in as {} ({} points)", user->display_name, user->score);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::LogInUser(const char* username, const char* password) {
|
||||||
void Client::LogInUser(const char* username, const char* password)
|
rc_client_begin_login_with_password(rc_client, username, password, login_callback, NULL);
|
||||||
{
|
|
||||||
rc_client_begin_login_with_password(rc_client, username, password, login_callback, NULL);
|
|
||||||
}
|
}
|
||||||
} // namespace RetroAchievements
|
} // namespace RetroAchievements
|
||||||
|
|||||||
@ -6,18 +6,18 @@ class System;
|
|||||||
|
|
||||||
struct rc_client_t;
|
struct rc_client_t;
|
||||||
|
|
||||||
namespace RetroAchievements
|
namespace RetroAchievements {
|
||||||
{
|
class Client {
|
||||||
class Client {
|
public:
|
||||||
public:
|
explicit Client(const Core::System& system);
|
||||||
explicit Client(const Core::System& system);
|
~Client();
|
||||||
~Client();
|
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
void LogInUser(const char* username, const char* password);
|
void LogInUser(const char* username, const char* password);
|
||||||
private:
|
|
||||||
const Core::System& system;
|
private:
|
||||||
rc_client_t* rc_client = nullptr;
|
const Core::System& system;
|
||||||
};
|
rc_client_t* rc_client = nullptr;
|
||||||
|
};
|
||||||
} // namespace RetroAchievements
|
} // namespace RetroAchievements
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user