Finish fixing classes not saving

This commit is contained in:
Federico Cecchetto 2022-03-02 21:06:15 +01:00
parent a45745f6f7
commit 7523dee884
2 changed files with 77 additions and 67 deletions

View File

@ -141,4 +141,33 @@ namespace demonware
buffer->read_string(&this->timezone); buffer->read_string(&this->timezone);
} }
}; };
// made up name
class bdFile final : public bdTaskResult
{
public:
uint64_t owner_id;
std::string platform;
std::string filename;
uint32_t unk;
std::string data;
void serialize(byte_buffer* buffer) override
{
buffer->write_uint64(this->owner_id);
buffer->write_string(this->platform);
buffer->write_string(this->filename);
buffer->write_uint32(this->unk);
buffer->write_blob(this->data);
}
void deserialize(byte_buffer* buffer) override
{
buffer->read_uint64(&this->owner_id);
buffer->read_string(&this->platform);
buffer->read_string(&this->filename);
buffer->read_uint32(&this->unk);
buffer->read_blob(&this->data);
}
};
} }

View File

@ -147,62 +147,31 @@ namespace demonware
utils::io::write_file("demonware/bdStorage/set_user_file", buffer->get_buffer()); utils::io::write_file("demonware/bdStorage/set_user_file", buffer->get_buffer());
#endif #endif
auto reply = server->create_reply(this->task_id());
uint64_t owner; uint64_t owner;
uint32_t numfiles;
std::string game, platform;
buffer->read_string(&game);
buffer->read_uint64(&owner);
buffer->read_string(&platform);
buffer->read_uint32(&numfiles);
auto reply = server->create_reply(this->task_id());
for (uint32_t i = 0; i < numfiles; i++)
{ {
bool priv;
uint32_t unk32_0;
uint32_t unk32_1;
std::string game, platform, filename, data;
buffer->read_string(&game);
buffer->read_uint64(&owner);
buffer->read_string(&platform);
buffer->read_uint32(&unk32_0);
buffer->read_string(&filename);
buffer->read_blob(&data);
buffer->read_uint32(&unk32_1);
buffer->read_bool(&priv);
const auto path = get_user_file_path(filename);
utils::io::write_file(path, data);
#ifdef DEBUG
printf("[DW]: [bdStorage]: set user file: %s\n", filename.data());
#endif
auto* info = new bdFileInfo;
info->file_id = *reinterpret_cast<const uint64_t*>(utils::cryptography::sha1::compute(filename).data());
info->filename = filename;
info->create_time = uint32_t(time(nullptr));
info->modified_time = info->create_time;
info->file_size = uint32_t(data.size());
info->owner_id = uint64_t(owner);
info->priv = priv;
reply->add(info);
}
{
bool priv;
uint32_t unk32_0;
std::string filename, data; std::string filename, data;
uint32_t unk;
bool priv;
buffer->read_string(&filename); buffer->read_string(&filename);
buffer->read_blob(&data); buffer->read_blob(&data);
buffer->read_uint32(&unk32_0); buffer->read_uint32(&unk);
buffer->read_bool(&priv); buffer->read_bool(&priv);
const auto path = get_user_file_path(filename); const auto path = get_user_file_path(filename);
utils::io::write_file(path, data); utils::io::write_file(path, data);
#ifdef DEBUG
printf("[DW]: [bdStorage]: set user file: %s\n", filename.data());
#endif
auto* info = new bdFileInfo; auto* info = new bdFileInfo;
info->file_id = *reinterpret_cast<const uint64_t*>(utils::cryptography::sha1::compute(filename).data()); info->file_id = *reinterpret_cast<const uint64_t*>(utils::cryptography::sha1::compute(filename).data());
@ -213,6 +182,10 @@ namespace demonware
info->owner_id = uint64_t(owner); info->owner_id = uint64_t(owner);
info->priv = priv; info->priv = priv;
#ifdef DEBUG
printf("[DW]: [bdStorage]: set user file: %s\n", filename.data());
#endif
reply->add(info); reply->add(info);
} }
@ -226,10 +199,9 @@ namespace demonware
#endif #endif
uint32_t unk32_0; uint32_t unk32_0;
uint32_t unk32_1; uint32_t numfiles, count = 0;
uint64_t owner; uint64_t owner;
std::string game, filename, filename2, std::string game, platform;
platform, data, data2;
buffer->read_string(&game); buffer->read_string(&game);
buffer->read_uint32(&unk32_0); buffer->read_uint32(&unk32_0);
@ -237,30 +209,39 @@ namespace demonware
buffer->read_string(&platform); buffer->read_string(&platform);
buffer->read_uint64(&owner); buffer->read_uint64(&owner);
buffer->read_string(&platform); buffer->read_string(&platform);
buffer->read_uint32(&unk32_1); buffer->read_uint32(&numfiles);
buffer->read_string(&filename);
buffer->read_string(&filename2);
#ifdef DEBUG auto reply = server->create_reply(this->task_id());
printf("[DW]: [bdStorage]: get user file: %s, %s, %s\n", game.data(), filename.data(), platform.data());
#endif
#ifdef DEBUG for (uint32_t i = 0; i < numfiles; i++)
printf("[DW]: [bdStorage]: get user file: %s, %s, %s\n", game.data(), filename2.data(), platform.data());
#endif
const auto path = get_user_file_path(filename);
const auto path2 = get_user_file_path(filename2);
if (utils::io::read_file(path, &data) && utils::io::read_file(path2, &data2))
{ {
// TODO: find out what the response should be for 2 files std::string filename, data;
// auto reply = server->create_reply(this->task_id()); buffer->read_string(&filename);
// reply->add(new bdFileData(data));
// reply->add(new bdFileData(data2));
// reply->send();
server->create_reply(this->task_id(), game::BD_NO_FILE)->send(); const auto path = get_user_file_path(filename);
if (!utils::io::read_file(path, &data))
{
continue;
}
auto response = new bdFile;
response->owner_id = owner;
response->unk = 0;
response->platform = platform;
response->filename = filename;
response->data = data;
reply->add(response);
++count;
#ifdef DEBUG
printf("[DW]: [bdStorage]: get user file: %s, %s, %s\n", game.data(), filename.data(), platform.data());
#endif
}
if (count == numfiles)
{
reply->send();
} }
else else
{ {