mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-07 21:49:01 -06:00

Added AchievementManager class. Upon startup (currently only in DolphinQt), logs into RetroAchievements with the login credentials stored in achievements.ini. Co-authored-by: AdmiralCurtiss <AdmiralCurtiss@users.noreply.github.com>
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
// Copyright 2023 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
|
|
#include <rcheevos/include/rc_api_user.h>
|
|
#include <rcheevos/include/rc_runtime.h>
|
|
|
|
#include "Common/Event.h"
|
|
#include "Common/WorkQueueThread.h"
|
|
|
|
class AchievementManager
|
|
{
|
|
public:
|
|
enum class ResponseType
|
|
{
|
|
SUCCESS,
|
|
INVALID_CREDENTIALS,
|
|
CONNECTION_FAILED,
|
|
UNKNOWN_FAILURE
|
|
};
|
|
using LoginCallback = std::function<void(ResponseType)>;
|
|
|
|
static AchievementManager* GetInstance();
|
|
void Init();
|
|
ResponseType Login(const std::string& password);
|
|
void LoginAsync(const std::string& password, const LoginCallback& callback);
|
|
bool IsLoggedIn() const;
|
|
void Logout();
|
|
void Shutdown();
|
|
|
|
private:
|
|
AchievementManager() = default;
|
|
|
|
ResponseType VerifyCredentials(const std::string& password);
|
|
|
|
template <typename RcRequest, typename RcResponse>
|
|
ResponseType Request(RcRequest rc_request, RcResponse* rc_response,
|
|
const std::function<int(rc_api_request_t*, const RcRequest*)>& init_request,
|
|
const std::function<int(RcResponse*, const char*)>& process_response);
|
|
|
|
rc_runtime_t m_runtime{};
|
|
bool m_is_runtime_initialized = false;
|
|
rc_api_login_response_t m_login_data{};
|
|
Common::WorkQueueThread<std::function<void()>> m_queue;
|
|
}; // class AchievementManager
|
|
|
|
#endif // USE_RETRO_ACHIEVEMENTS
|