feat(Api): Implemented SCUI Api (#712)

* feat(Api): Async joining via rid joiner
* feat(cmake): disable cpr tests

Co-authored-by: Yimura <24669514+Yimura@users.noreply.github.com>
This commit is contained in:
Bugisoft
2022-12-17 17:24:45 +01:00
committed by GitHub
parent 792d765ffa
commit 551c165367
9 changed files with 148 additions and 4 deletions

View File

@ -0,0 +1,63 @@
#include "api_service.hpp"
#include "pointers.hpp"
namespace big
{
api_service::api_service()
{
g_api_service = this;
}
api_service::~api_service()
{
g_api_service = nullptr;
}
bool api_service::get_rid_from_username(std::string_view username, uint64_t& result)
{
cpr::Response response = cpr::Post(
cpr::Url{ "https://scui.rockstargames.com/api/friend/accountsearch" },
cpr::Header{ {"Authorization", AUTHORIZATION_TICKET) }, { "X-Requested-With", "XMLHttpRequest"}},
cpr::Body{ { std::format("searchNickname={}", username) } });
if (response.status_code == 200)
{
nlohmann::json obj = nlohmann::json::parse(response.text);
if (obj["Total"] > 0 && username.compare(obj["Accounts"].at(0)["Nickname"]) == 0)
{
result = obj["Accounts"].at(0)["RockstarId"];
return true;
}
}
return false;
}
bool api_service::get_username_from_rid(uint64_t rid, std::string& result)
{
cpr::Response response = cpr::Post(
cpr::Url{ "https://scui.rockstargames.com/api/friend/getprofile" },
cpr::Header{ {"Authorization", AUTHORIZATION_TICKET) }, { "X-Requested-With", "XMLHttpRequest"}, {"Content-Type", "application/json"} },
cpr::Body{ { std::format(R"({{"RockstarId":"{}"}})", rid) } });
if (response.status_code == 200)
{
nlohmann::json obj = nlohmann::json::parse(response.text);
result = obj["Accounts"].at(0)["RockstarAccount"]["Name"];
return true;
}
return false;
}
bool api_service::send_socialclub_message(uint64_t rid, std::string_view message)
{
cpr::Response response = cpr::Post(
cpr::Url{ "https://scui.rockstargames.com/api/messaging/sendmessage" },
cpr::Header{ {"Authorization", AUTHORIZATION_TICKET) }, { "X-Requested-With", "XMLHttpRequest"}, {"Content-Type", "application/json"} },
cpr::Body{ { std::format(R"({{"env":"prod","title":"gta5","version":11,"recipientRockstarId":"{}","messageText":"{}"}})", rid, message) } });
return response.status_code == 200;
}
}

View File

@ -0,0 +1,30 @@
#pragma once
#include "pointers.hpp"
#include <cpr/cpr.h>
#define AUTHORIZATION_TICKET std::format("SCAUTH val=\"{}\"", get_ticket()
namespace big
{
class api_service
{
public:
api_service();
~api_service();
// Returns true if an valid profile matching his username has been found
bool get_rid_from_username(std::string_view username, uint64_t& result);
// Returns true if an valid profile matching his rid has been found
bool get_username_from_rid(uint64_t rid, std::string& result);
// Returns true if the message has been successfully sended to the target
bool send_socialclub_message(uint64_t rid, std::string_view message);
private:
inline std::string get_ticket()
{
return g_pointers->m_sc_info->m_ticket;
}
};
inline api_service* g_api_service;
}