mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 23:59:27 +01:00
Added ResolveHash to AchievementManager
Added the ResolveHash method to AchievementManager. This is a blocking function to send a hash string to the RetroAchievements server to verify it and get a game ID back.
This commit is contained in:
parent
31d2dedcb1
commit
67ab4d2473
@ -4,6 +4,10 @@
|
||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||
|
||||
#include "Core/AchievementManager.h"
|
||||
|
||||
#include <array>
|
||||
#include <rcheevos/include/rc_hash.h>
|
||||
|
||||
#include "Common/HttpRequest.h"
|
||||
#include "Common/WorkQueueThread.h"
|
||||
#include "Config/AchievementSettings.h"
|
||||
@ -71,6 +75,23 @@ AchievementManager::ResponseType AchievementManager::VerifyCredentials(const std
|
||||
return r_type;
|
||||
}
|
||||
|
||||
AchievementManager::ResponseType
|
||||
AchievementManager::ResolveHash(std::array<char, HASH_LENGTH> game_hash)
|
||||
{
|
||||
rc_api_resolve_hash_response_t hash_data{};
|
||||
std::string username = Config::Get(Config::RA_USERNAME);
|
||||
std::string api_token = Config::Get(Config::RA_API_TOKEN);
|
||||
rc_api_resolve_hash_request_t resolve_hash_request = {
|
||||
.username = username.c_str(), .api_token = api_token.c_str(), .game_hash = game_hash.data()};
|
||||
ResponseType r_type = Request<rc_api_resolve_hash_request_t, rc_api_resolve_hash_response_t>(
|
||||
resolve_hash_request, &hash_data, rc_api_init_resolve_hash_request,
|
||||
rc_api_process_resolve_hash_response);
|
||||
if (r_type == ResponseType::SUCCESS)
|
||||
m_game_id = hash_data.game_id;
|
||||
rc_api_destroy_resolve_hash_response(&hash_data);
|
||||
return r_type;
|
||||
}
|
||||
|
||||
// Every RetroAchievements API call, with only a partial exception for fetch_image, follows
|
||||
// the same design pattern (here, X is the name of the call):
|
||||
// Create a specific rc_api_X_request_t struct and populate with the necessary values
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <rcheevos/include/rc_api_runtime.h>
|
||||
#include <rcheevos/include/rc_api_user.h>
|
||||
#include <rcheevos/include/rc_runtime.h>
|
||||
|
||||
@ -38,7 +39,10 @@ public:
|
||||
private:
|
||||
AchievementManager() = default;
|
||||
|
||||
static constexpr int HASH_LENGTH = 33;
|
||||
|
||||
ResponseType VerifyCredentials(const std::string& password);
|
||||
ResponseType ResolveHash(std::array<char, HASH_LENGTH> game_hash);
|
||||
|
||||
template <typename RcRequest, typename RcResponse>
|
||||
ResponseType Request(RcRequest rc_request, RcResponse* rc_response,
|
||||
@ -47,7 +51,10 @@ private:
|
||||
|
||||
rc_runtime_t m_runtime{};
|
||||
bool m_is_runtime_initialized = false;
|
||||
unsigned int m_game_id = 0;
|
||||
rc_api_login_response_t m_login_data{};
|
||||
|
||||
|
||||
Common::WorkQueueThread<std::function<void()>> m_queue;
|
||||
}; // class AchievementManager
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user