t8-mod/source/proxy-dll/demonware/services/bdObjectStore.cpp

169 lines
6.6 KiB
C++
Raw Normal View History

Squashed commit of the following: commit f44d146e4ac906ff898e8968c6857fd2280f6d20 Author: project-bo4 <127137346+project-bo4@users.noreply.github.com> Date: Thu May 11 13:39:29 2023 -0700 remove lpc package from repository commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu May 11 13:06:13 2023 -0700 generic improvements + added identity configuration + objectstore improvements + added battlenet 'US' servers to blocklist + some other minor improvements commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7 Author: project-bo4 <themanwithantidote@gmail.com> Date: Sat Mar 25 16:32:52 2023 -0700 lpc improvements + fix lpc issue with foreign languages(non-english) not being considered in listing + check lpc files pre-start and warn user if missing any of core items commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu Mar 23 12:45:56 2023 -0700 demonware improvements + handle object store uploadUserObject + silence bdUNK125 commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 13:43:56 2023 -0700 forgot to update names commit 217682dfb07b35f7a09399fb2698924bb7fe8b77 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 11:09:18 2023 -0700 upload lpc and update readme commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 10:53:43 2023 -0700 demonware emulator + demonware emulator + platform name and id + xxhash and picoproto - remove g_runframe hook -disable discovery(save time) + improvements to utils + add new resources
2023-05-11 16:50:11 -04:00
#include <std_include.hpp>
#include "../services.hpp"
#include "../objects.hpp"
Squashed commit of the following: commit f44d146e4ac906ff898e8968c6857fd2280f6d20 Author: project-bo4 <127137346+project-bo4@users.noreply.github.com> Date: Thu May 11 13:39:29 2023 -0700 remove lpc package from repository commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu May 11 13:06:13 2023 -0700 generic improvements + added identity configuration + objectstore improvements + added battlenet 'US' servers to blocklist + some other minor improvements commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7 Author: project-bo4 <themanwithantidote@gmail.com> Date: Sat Mar 25 16:32:52 2023 -0700 lpc improvements + fix lpc issue with foreign languages(non-english) not being considered in listing + check lpc files pre-start and warn user if missing any of core items commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu Mar 23 12:45:56 2023 -0700 demonware improvements + handle object store uploadUserObject + silence bdUNK125 commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 13:43:56 2023 -0700 forgot to update names commit 217682dfb07b35f7a09399fb2698924bb7fe8b77 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 11:09:18 2023 -0700 upload lpc and update readme commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 10:53:43 2023 -0700 demonware emulator + demonware emulator + platform name and id + xxhash and picoproto - remove g_runframe hook -disable discovery(save time) + improvements to utils + add new resources
2023-05-11 16:50:11 -04:00
#include <picoproto.h>
Squashed commit of the following: commit f44d146e4ac906ff898e8968c6857fd2280f6d20 Author: project-bo4 <127137346+project-bo4@users.noreply.github.com> Date: Thu May 11 13:39:29 2023 -0700 remove lpc package from repository commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu May 11 13:06:13 2023 -0700 generic improvements + added identity configuration + objectstore improvements + added battlenet 'US' servers to blocklist + some other minor improvements commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7 Author: project-bo4 <themanwithantidote@gmail.com> Date: Sat Mar 25 16:32:52 2023 -0700 lpc improvements + fix lpc issue with foreign languages(non-english) not being considered in listing + check lpc files pre-start and warn user if missing any of core items commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu Mar 23 12:45:56 2023 -0700 demonware improvements + handle object store uploadUserObject + silence bdUNK125 commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 13:43:56 2023 -0700 forgot to update names commit 217682dfb07b35f7a09399fb2698924bb7fe8b77 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 11:09:18 2023 -0700 upload lpc and update readme commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 10:53:43 2023 -0700 demonware emulator + demonware emulator + platform name and id + xxhash and picoproto - remove g_runframe hook -disable discovery(save time) + improvements to utils + add new resources
2023-05-11 16:50:11 -04:00
#include <utils/io.hpp>
#include <utils/cryptography.hpp>
#include <component/platform.hpp>
namespace demonware
{
bdObjectStore::bdObjectStore() : service(193, "bdObjectStore")
{
this->register_task(3, &bdObjectStore::listUserObjects);
this->register_task(18, &bdObjectStore::getUserObjectCounts);
this->register_task(8, &bdObjectStore::getPublisherObject);
this->register_task(9, &bdObjectStore::listPublisherObjectsByCategory);
this->register_task(6, &bdObjectStore::getUserObjectsVectorized);
this->register_task(2, &bdObjectStore::uploadUserObject);
this->register_task(5, &bdObjectStore::getUserObject); // Un-handled; Not used by engine at all
this->register_task(7, &bdObjectStore::uploadUserObjectsVectorized);
this->register_task(16, &bdObjectStore::getPublisherObjectMetadatas); // Un-handled; Not needed if user already has LPC
}
void bdObjectStore::getUserObject(service_server* server, byte_buffer* buffer) const
{
auto reply = server->create_reply(this->task_id(), 20000/*BD_OBJECTSTORE_PROXY_OBJECT_NOT_FOUND*/);
reply->send();
}
void bdObjectStore::getPublisherObject(service_server* server, byte_buffer* buffer) const
{
auto reply = server->create_reply(this->task_id(), 20000/*BD_OBJECTSTORE_PROXY_OBJECT_NOT_FOUND*/);
reply->send();
}
void bdObjectStore::listUserObjects(service_server* server, byte_buffer* buffer) const
{
std::string response_json = generate_user_objects_list_json();
std::string response_buff = serialize_objectstore_structed_buffer(response_json);
auto reply = server->create_structed_reply(this->task_id());
reply->send(response_buff);
}
void bdObjectStore::getUserObjectCounts(service_server* server, byte_buffer* buffer) const
{
std::string response_json = generate_user_objects_count_json();
std::string response_buff = serialize_objectstore_structed_buffer(response_json);
auto reply = server->create_structed_reply(this->task_id());
reply->send(response_buff);
}
void bdObjectStore::listPublisherObjectsByCategory(service_server* server, byte_buffer* buffer) const
{
std::string response_json = generate_publisher_objects_list_json("");
std::string response_buff = serialize_objectstore_structed_buffer(response_json);
auto reply = server->create_structed_reply(this->task_id());
reply->send(response_buff);
}
void bdObjectStore::getUserObjectsVectorized(service_server* server, byte_buffer* buffer) const
{
std::string structed_data;
buffer->read_struct(&structed_data);
picoproto::Message request_buffer;
request_buffer.ParseFromBytes(reinterpret_cast<uint8_t*>(structed_data.data()), structed_data.size());
std::string str4 = request_buffer.GetString(4);
picoproto::Message nested_buffer;
nested_buffer.ParseFromBytes(reinterpret_cast<uint8_t*>(str4.data()), str4.size());
std::vector<objectID> requested_objects_list;
rapidjson::Document requested_objects_list_json;
requested_objects_list_json.Parse(nested_buffer.GetString(2));
for (rapidjson::SizeType i = 0; i < requested_objects_list_json.Size(); i++) {
requested_objects_list.push_back({ std::format("bnet-{}", platform::bnet_get_userid())/*requested_objects_list_json[i]["owner"].GetString()*/, requested_objects_list_json[i]["name"].GetString() });
}
std::string response_json = deliver_user_objects_vectorized_json(requested_objects_list);
std::string response_buff = serialize_objectstore_structed_buffer(response_json);
auto reply = server->create_structed_reply(this->task_id());
reply->send(response_buff);
}
void bdObjectStore::getPublisherObjectMetadatas(service_server* server, byte_buffer* buffer) const
{
auto reply = server->create_structed_reply(this->task_id());
reply->send(""); // Un-handled
}
void bdObjectStore::uploadUserObject(service_server* server, byte_buffer* buffer) const
{
std::string structed_data;
buffer->read_struct(&structed_data);
picoproto::Message request_buffer;
request_buffer.ParseFromBytes(reinterpret_cast<uint8_t*>(structed_data.data()), structed_data.size());
std::string request = request_buffer.GetString(1);
std::string url = request_buffer.GetString(2);
std::string data = request_buffer.GetString(3);
std::string file = utils::string::split(url, '/')[8];
std::string path = get_user_file_path(file);
if (!utils::io::write_file(path, data))
logger::write(logger::LOG_TYPE_DEBUG, "[bdObjectStore::uploadUserObject] error on writing '%s'", file.data());
else
logger::write(logger::LOG_TYPE_DEBUG, "[bdObjectStore::uploadUserObject] saved user file '%s'", file.data());
std::string response_json = construct_file_upload_result_json(file);
std::string response_buff = serialize_objectstore_structed_buffer(response_json);
auto reply = server->create_structed_reply(this->task_id());
reply->send(response_buff);
}
void bdObjectStore::uploadUserObjectsVectorized(service_server* server, byte_buffer* buffer) const
{
std::string structed_data;
buffer->read_struct(&structed_data);
picoproto::Message request_buffer;
request_buffer.ParseFromBytes(reinterpret_cast<uint8_t*>(structed_data.data()), structed_data.size());
std::string request = request_buffer.GetString(1);
std::string payload = request_buffer.GetString(3);
rapidjson::Document vectorized_upload_json;
vectorized_upload_json.Parse(payload.data());
std::vector<std::string> uploaded_objects_list;
const rapidjson::Value& objects = vectorized_upload_json["objects"];
for (rapidjson::SizeType i = 0; i < objects.Size(); i++) // Uses SizeType instead of size_t
{
const rapidjson::Value& content = objects[i]["content"];
const rapidjson::Value& name = objects[i]["metadata"]["name"];
const rapidjson::Value& checksum = objects[i]["metadata"]["checksum"];
std::string data = utils::cryptography::base64::decode(content.GetString());
const auto path = std::format("{}/{}", platform::get_userdata_directory(), name.GetString());
uploaded_objects_list.push_back(name.GetString());
if (!utils::io::write_file(path, data))
logger::write(logger::LOG_TYPE_DEBUG, "[bdObjectStore::uploadUserObjectsVectorized] error on writing '%s'", name.GetString());
else
logger::write(logger::LOG_TYPE_DEBUG, "[bdObjectStore::uploadUserObjectsVectorized] saved user file '%s'", name.GetString());
}
std::string response_json = construct_vectorized_upload_list_json(uploaded_objects_list);
std::string response_buff = serialize_objectstore_structed_buffer(response_json);
auto reply = server->create_structed_reply(this->task_id());
reply->send(response_buff);
}
}