Prepare distributing profile infos

This commit is contained in:
momo5502 2023-04-02 09:10:18 +02:00
parent b32fdd9b73
commit 89103ed672
5 changed files with 141 additions and 27 deletions

View File

@ -215,13 +215,6 @@ namespace party
network::send(query.host, "getInfo", query.challenge);
}
game::netadr_t get_connected_server()
{
constexpr auto local_client_num = 0ull;
const auto address = *reinterpret_cast<uint64_t*>(0x1453D8BB8_g) + (0x25780 * local_client_num) + 0x10;
return *reinterpret_cast<game::netadr_t*>(address);
}
void handle_info_response(const game::netadr_t& target, const network::data_view& data)
{
bool found_query = false;
@ -306,6 +299,13 @@ namespace party
});
}
game::netadr_t get_connected_server()
{
constexpr auto local_client_num = 0ull;
const auto address = *reinterpret_cast<uint64_t*>(0x1453D8BB8_g) + (0x25780 * local_client_num) + 0x10;
return *reinterpret_cast<game::netadr_t*>(address);
}
struct component final : client_component
{
void post_unpack() override

View File

@ -7,4 +7,6 @@ namespace party
using query_callback = std::function<query_callback_func>;
void query_server(const game::netadr_t& host, query_callback callback);
game::netadr_t get_connected_server();
}

View File

@ -0,0 +1,91 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "profile_infos.hpp"
#include "network.hpp"
#include <utils/nt.hpp>
#include <utils/properties.hpp>
#include <utils/concurrency.hpp>
#include "../steam/steam.hpp"
#include <utils/io.hpp>
namespace profile_infos
{
namespace
{
using profile_map = std::unordered_map<uint64_t, profile_info>;
utils::concurrency::container<profile_map> profile_mapping;
std::optional<profile_info> load_profile_info()
{
std::string data{};
if (!utils::io::read_file("players/user/profile_info", &data))
{
return {};
}
profile_info info{};
constexpr auto version_size = sizeof(info.version);
if(data.size() < sizeof(version_size))
{
return {};
}
memcpy(&info.version, data.data(), version_size);
info.ddl.assign(data.begin() + version_size, data.end());
return { std::move(info) };
}
}
std::optional<profile_info> get_profile_info(uint64_t user_id)
{
if (user_id == steam::SteamUser()->GetSteamID().bits)
{
return load_profile_info();
}
return profile_mapping.access<std::optional<profile_info>>([user_id](const profile_map& profiles)
{
std::optional<profile_info> result{};
const auto profile_entry = profiles.find(user_id);
if (profile_entry != profiles.end())
{
result = profile_entry->second;
}
return result;
});
}
void update_profile_info(const profile_info& info)
{
std::string data{};
data.reserve(4 + info.ddl.size());
data.append(reinterpret_cast<const char*>(&info.version), sizeof(info.version));
data.append(info.ddl);
utils::io::write_file("players/user/profile_info", data);
}
struct component final : generic_component
{
void post_load() override
{
}
void post_unpack() override
{
/*network::on("profileInfo", [](const game::netadr_t& server, const network::data_view& data)
{
});*/
}
};
}
REGISTER_COMPONENT(profile_infos::component)

View File

@ -0,0 +1,13 @@
#pragma once
namespace profile_infos
{
struct profile_info
{
int32_t version;
std::string ddl;
};
std::optional<profile_info> get_profile_info(uint64_t user_id);
void update_profile_info(const profile_info& info);
}

View File

@ -1,7 +1,7 @@
#include <std_include.hpp>
#include "../services.hpp"
#include "steam/steam.hpp"
#include <utils/io.hpp>
#include "../../../component/profile_infos.hpp"
namespace demonware
{
@ -19,33 +19,41 @@ namespace demonware
void bdProfiles::getPublicInfos(service_server* server, byte_buffer* buffer) const
{
std::vector<std::pair<uint64_t, profile_infos::profile_info>> profile_infos{};
uint64_t entity_id;
buffer->read_uint64(&entity_id);
auto* result = new bdPublicProfileInfo;
result->m_entityID = entity_id;
result->m_VERSION = 3;
if (utils::io::read_file(std::format("players/user/profileInfo_{}", entity_id), &result->m_ddl))
while (buffer->read_uint64(&entity_id))
{
auto reply = server->create_reply(this->task_id());
auto profile = profile_infos::get_profile_info(entity_id);
if(profile)
{
profile_infos.emplace_back(entity_id, std::move(*profile));
}
}
auto reply = server->create_reply(this->task_id(), profile_infos.empty() ? game::BD_NO_PROFILE_INFO_EXISTS : game::BD_NO_ERROR);
for(auto& info : profile_infos)
{
auto* result = new bdPublicProfileInfo;
result->m_entityID = info.first;
result->m_VERSION = info.second.version;
result->m_ddl = std::move(info.second.ddl);
reply->add(result);
reply->send();
}
else
{
auto reply = server->create_reply(this->task_id(), game::BD_NO_PROFILE_INFO_EXISTS);
reply->send();
}
reply->send();
}
void bdProfiles::setPublicInfo(service_server* server, byte_buffer* buffer) const
{
int32_t version; std::string ddl;
buffer->read_int32(&version);
buffer->read_blob(&ddl);
profile_infos::profile_info info{};
utils::io::write_file(std::format("players/user/profileInfo_{}", steam::SteamUser()->GetSteamID().bits), ddl);
buffer->read_int32(&info.version);
buffer->read_blob(&info.ddl);
profile_infos::update_profile_info(info);
auto reply = server->create_reply(this->task_id());
reply->send();