2022-12-17 17:24:45 +01:00
|
|
|
#include "api_service.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
|
2022-12-17 17:24:45 +01:00
|
|
|
#include "pointers.hpp"
|
2022-12-22 11:49:34 +01:00
|
|
|
#include "services/creator_storage/creator_storage_service.hpp"
|
2022-12-17 17:24:45 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
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)}});
|
2022-12-17 17:24:45 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
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)}});
|
2022-12-17 17:24:45 +01:00
|
|
|
|
2022-12-22 11:49:34 +01:00
|
|
|
if (response.status_code == 200)
|
2022-12-17 17:24:45 +01:00
|
|
|
{
|
|
|
|
nlohmann::json obj = nlohmann::json::parse(response.text);
|
2023-03-01 21:27:15 +00:00
|
|
|
result = obj["Accounts"].at(0)["RockstarAccount"]["Name"];
|
2022-12-17 17:24:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-22 11:49:34 +01:00
|
|
|
// Ratelimit: 10 per Minute, if exceeded than 5 min cooldown
|
2022-12-17 17:24:45 +01:00
|
|
|
bool api_service::send_socialclub_message(uint64_t rid, std::string_view message)
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
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)}});
|
2022-12-17 17:24:45 +01:00
|
|
|
|
|
|
|
return response.status_code == 200;
|
|
|
|
}
|
2022-12-22 11:49:34 +01:00
|
|
|
|
2023-01-03 11:35:11 +01:00
|
|
|
bool api_service::get_job_details(std::string_view content_id, nlohmann::json& result)
|
2022-12-22 11:49:34 +01:00
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
cpr::Response response = cpr::Get(cpr::Url{"https://scapi.rockstargames.com/ugc/mission/details"},
|
|
|
|
cpr::Header{{"X-AMC", "true"}, {"X-Requested-With", "XMLHttpRequest"}},
|
|
|
|
cpr::Parameters{{"title", "gtav"}, {"contentId", content_id.data()}});
|
2022-12-22 11:49:34 +01:00
|
|
|
|
|
|
|
result = nlohmann::json::parse(response.text);
|
|
|
|
|
|
|
|
return response.status_code == 200;
|
|
|
|
}
|
|
|
|
|
2023-01-03 11:35:11 +01:00
|
|
|
bool api_service::download_job_metadata(std::string_view content_id, int f1, int f0, int lang)
|
2022-12-22 11:49:34 +01:00
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
cpr::Response response = cpr::Get(cpr::Url{std::format("https://prod.cloud.rockstargames.com/ugc/gta5mission/{}/{}_{}_{}.json",
|
|
|
|
content_id,
|
|
|
|
f1,
|
|
|
|
f0,
|
|
|
|
languages.at(lang))});
|
2023-01-03 11:35:11 +01:00
|
|
|
|
|
|
|
if (response.status_code == 200)
|
2022-12-22 11:49:34 +01:00
|
|
|
{
|
2023-01-03 11:35:11 +01:00
|
|
|
std::ofstream of = creator_storage_service::create_file(std::string(content_id) + ".json");
|
2023-03-01 21:27:15 +00:00
|
|
|
cpr::Response r = cpr::Download(of, response.url);
|
2023-01-03 11:35:11 +01:00
|
|
|
|
|
|
|
return true;
|
2022-12-22 11:49:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-17 17:24:45 +01:00
|
|
|
}
|