From 66b8731bdb48247cecb5f1f38d65990ddb74a435 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Sat, 15 Apr 2023 11:27:39 -0400 Subject: [PATCH] Added PingRichPresence to AchievementManager PingRichPresence makes a "ping" API request to the RetroAchievements website with the provided RichPresence string parameter. While there has been talk about tying ping in with session, in its current state the primary purpose of ping is to send the player's Rich Presence to the website. --- Source/Core/Core/AchievementManager.cpp | 16 ++++++++++++++++ Source/Core/Core/AchievementManager.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index 8397338b04..bf714c6a17 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -401,6 +401,22 @@ AchievementManager::ResponseType AchievementManager::SubmitLeaderboard(Achieveme return r_type; } +AchievementManager::ResponseType +AchievementManager::PingRichPresence(const RichPresence& rich_presence) +{ + std::string username = Config::Get(Config::RA_USERNAME); + std::string api_token = Config::Get(Config::RA_API_TOKEN); + rc_api_ping_request_t ping_request = {.username = username.c_str(), + .api_token = api_token.c_str(), + .game_id = m_game_id, + .rich_presence = rich_presence.data()}; + rc_api_ping_response_t ping_response = {}; + ResponseType r_type = Request( + ping_request, &ping_response, rc_api_init_ping_request, rc_api_process_ping_response); + rc_api_destroy_ping_response(&ping_response); + 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 diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h index c68a141c63..2412e74587 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -19,6 +19,8 @@ #include "Common/WorkQueueThread.h" using AchievementId = u32; +constexpr size_t RP_SIZE = 256; +using RichPresence = std::array; class AchievementManager { @@ -65,6 +67,8 @@ private: ResponseType AwardAchievement(AchievementId achievement_id); ResponseType SubmitLeaderboard(AchievementId leaderboard_id, int value); + ResponseType PingRichPresence(const RichPresence& rich_presence); + template ResponseType Request(RcRequest rc_request, RcResponse* rc_response, const std::function& init_request,