only send necessary data

This commit is contained in:
m 2023-01-02 10:39:34 -06:00
parent 58d8b085ac
commit 8185fd550c
2 changed files with 33 additions and 31 deletions

View File

@ -239,27 +239,27 @@ namespace demonware
};
class bdMarketingMessage final : public bdTaskResult
{
public:
uint64_t m_messageID;
std::string m_languageCode;
std::string m_content;
std::string m_metadata;
{
public:
uint64_t m_messageID;
std::string m_languageCode;
std::string m_content;
std::string m_metadata;
void serialize(byte_buffer* buffer) override
{
buffer->write_uint64(this->m_messageID);
buffer->write_string(this->m_languageCode);
buffer->write_blob(this->m_content);
buffer->write_blob(this->m_metadata);
}
void serialize(byte_buffer* buffer) override
{
buffer->write_uint64(this->m_messageID);
buffer->write_string(this->m_languageCode);
buffer->write_blob(this->m_content);
buffer->write_blob(this->m_metadata);
}
void deserialize(byte_buffer* buffer) override
{
buffer->read_uint64(&this->m_messageID);
buffer->read_string(&this->m_languageCode);
buffer->read_blob(&this->m_content);
buffer->read_blob(&this->m_metadata);
}
};
void deserialize(byte_buffer* buffer) override
{
buffer->read_uint64(&this->m_messageID);
buffer->read_string(&this->m_languageCode);
buffer->read_blob(&this->m_content);
buffer->read_blob(&this->m_metadata);
}
};
}

View File

@ -1,4 +1,5 @@
#include <std_include.hpp>
#include <utils/http.hpp>
#include "../services.hpp"
@ -13,40 +14,41 @@ namespace demonware
void bdMarketingComms::getMessages(service_server* server, byte_buffer* /*buffer*/) const
{
auto motd_content = utils::http::get_data("https://h1.gg/data/motd.json");
auto motd = new bdMarketingMessage;
auto reply = server->create_reply(this->task_id());
const auto motd_content = utils::http::get_data("https://h1.gg/data/motd.json");
if (motd_content.has_value())
{
const auto motd = new bdMarketingMessage;
motd->m_messageID = 1;
motd->m_languageCode = "en-US";
motd->m_content = motd_content.value().buffer.data();
motd->m_metadata = "{}";
reply->add(motd);
}
auto featured_content = utils::http::get_data("https://h1.gg/data/featured.json");
auto featured = new bdMarketingMessage;
const auto featured_content = utils::http::get_data("https://h1.gg/data/featured.json");
if (featured_content.has_value())
{
const auto featured = new bdMarketingMessage;
featured->m_messageID = 2;
featured->m_languageCode = "en-US";
featured->m_content = featured_content.value().buffer.data();
featured->m_metadata = "{}";
reply->add(featured);
}
auto featured2_content = utils::http::get_data("https://h1.gg/data/featured2.json");
auto featured2 = new bdMarketingMessage;
const auto featured2_content = utils::http::get_data("https://h1.gg/data/featured2.json");
if (featured2_content.has_value())
{
const auto featured2 = new bdMarketingMessage;
featured2->m_messageID = 3;
featured2->m_languageCode = "en-US";
featured2->m_content = featured2_content.value().buffer.data();
featured2->m_metadata = "{}";
reply->add(featured2);
}
auto reply = server->create_reply(this->task_id());
reply->add(motd);
reply->add(featured);
reply->add(featured2);
reply->send();
}