Added StartRASession to AchievementManager

Added a call to the RetroAchievements Start Session API to AchievementManager. This is primarily for client-side activation, so it doesn't return much of value, aside from its success/error information, but I'm storing the return structure in case this changes in the future.
This commit is contained in:
LillyJadeKatrin 2023-04-10 23:56:15 -04:00
parent 67ab4d2473
commit 7e8a770b30
2 changed files with 16 additions and 0 deletions

View File

@ -92,6 +92,20 @@ AchievementManager::ResolveHash(std::array<char, HASH_LENGTH> game_hash)
return r_type;
}
AchievementManager::ResponseType AchievementManager::StartRASession()
{
rc_api_start_session_response_t session_data{};
std::string username = Config::Get(Config::RA_USERNAME);
std::string api_token = Config::Get(Config::RA_API_TOKEN);
rc_api_start_session_request_t start_session_request = {
.username = username.c_str(), .api_token = api_token.c_str(), .game_id = m_game_id};
ResponseType r_type = Request<rc_api_start_session_request_t, rc_api_start_session_response_t>(
start_session_request, &session_data, rc_api_init_start_session_request,
rc_api_process_start_session_response);
rc_api_destroy_start_session_response(&session_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

View File

@ -43,6 +43,7 @@ private:
ResponseType VerifyCredentials(const std::string& password);
ResponseType ResolveHash(std::array<char, HASH_LENGTH> game_hash);
ResponseType StartRASession();
template <typename RcRequest, typename RcResponse>
ResponseType Request(RcRequest rc_request, RcResponse* rc_response,
@ -55,6 +56,7 @@ private:
rc_api_login_response_t m_login_data{};
Common::WorkQueueThread<std::function<void()>> m_queue;
}; // class AchievementManager