codex-5.2: Отладка сети со стороны клиента

This commit is contained in:
2026-01-05 02:25:51 +06:00
parent 6c7a6df8f6
commit 2b2be796e9
33 changed files with 49 additions and 926 deletions

View File

@@ -177,6 +177,9 @@ struct AssetEntry {
*/
class IServerSession {
public:
// Включить логирование входящих сетевых пакетов на клиенте.
bool DebugLogPackets = false;
// Используемые двоичные ресурсы
std::unordered_map<EnumAssets, std::unordered_map<ResourceId, AssetEntry>> Assets;

View File

@@ -38,6 +38,26 @@ const char* assetTypeName(EnumAssets type) {
}
}
const char* toClientPacketName(ToClient type) {
switch(type) {
case ToClient::Init: return "Init";
case ToClient::Disconnect: return "Disconnect";
case ToClient::AssetsBindDK: return "AssetsBindDK";
case ToClient::AssetsBindHH: return "AssetsBindHH";
case ToClient::AssetsInitSend: return "AssetsInitSend";
case ToClient::AssetsNextSend: return "AssetsNextSend";
case ToClient::DefinitionsUpdate: return "DefinitionsUpdate";
case ToClient::ChunkVoxels: return "ChunkVoxels";
case ToClient::ChunkNodes: return "ChunkNodes";
case ToClient::ChunkLightPrism: return "ChunkLightPrism";
case ToClient::RemoveRegion: return "RemoveRegion";
case ToClient::Tick: return "Tick";
case ToClient::TestLinkCameraToEntity: return "TestLinkCameraToEntity";
case ToClient::TestUnlinkCamera: return "TestUnlinkCamera";
default: return "Unknown";
}
}
}
ServerSession::ServerSession(asio::io_context &ioc, std::unique_ptr<Net::AsyncSocket>&& socket)
@@ -875,6 +895,8 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
}
result.Chunks_ChangeOrAdd = std::move(chunks_Changed);
for(auto& [wId, regions] : regions_Lost_Result)
result.Chunks_Lost[wId] = std::vector<Pos::GlobalRegion>(regions.begin(), regions.end());
{
@@ -1233,6 +1255,11 @@ void ServerSession::protocolError() {
coro<> ServerSession::readPacket(Net::AsyncSocket &sock) {
uint8_t first = co_await sock.read<uint8_t>();
if(DebugLogPackets) {
ToClient type = static_cast<ToClient>(first);
LOG.debug() << "Recv packet=" << toClientPacketName(type) << " id=" << int(first);
}
switch((ToClient) first) {
case ToClient::Init:
co_return;

View File

@@ -2291,6 +2291,8 @@ void Vulkan::gui_ConnectedToServer() {
double chunksKb = double(Game.Session->getVisibleCompressedChunksBytes()) / 1024.0;
ImGui::Text("chunks compressed: %.1f KB", chunksKb);
ImGui::Checkbox("Логи сетевых пакетов", &Game.Session->DebugLogPackets);
if(ImGui::Button("Delimeter"))
LOG.debug();

View File

@@ -57,6 +57,10 @@ AssetsPreloader::Out_reloadResources AssetsPreloader::reloadResources(const Asse
try {
ReloadStatus secondStatus;
return _reloadResources(instances, status ? *status : secondStatus);
} catch(const std::exception& exc) {
LOG.error() << exc.what();
assert(!"reloadResources: здесь не должно быть ошибок");
std::unreachable();
} catch(...) {
assert(!"reloadResources: здесь не должно быть ошибок");
std::unreachable();

View File

@@ -44,6 +44,15 @@ namespace js = boost::json;
namespace LV::Server {
template <typename T, size_t N>
bool hasAnyBindings(const std::array<std::vector<T>, N>& data) {
for(const auto& list : data) {
if(!list.empty())
return true;
}
return false;
}
std::string ModInfo::dump() const {
js::object obj;
@@ -1694,7 +1703,7 @@ void GameServer::reloadMods() {
{
AssetsPreloader::Out_bakeId baked = Content.AM.bakeIdTables();
if(!baked.IdToDK.empty()) {
if(hasAnyBindings(baked.IdToDK)) {
packetsToSend.push_back(RemoteClient::makePacket_informateAssets_DK(baked.IdToDK));
}
}
@@ -2487,7 +2496,7 @@ void GameServer::stepSyncContent() {
std::vector<Net::Packet> packetsToAll;
{
AssetsPreloader::Out_bakeId baked = Content.AM.bakeIdTables();
if(!baked.IdToDK.empty()) {
if(hasAnyBindings(baked.IdToDK)) {
packetsToAll.push_back(RemoteClient::makePacket_informateAssets_DK(baked.IdToDK));
}
}

View File

@@ -389,10 +389,8 @@ void RemoteClient::NetworkAndResource_t::prepareWorldRemove(WorldId_t worldId)
void RemoteClient::prepareCameraSetEntity(ServerEntityId_t entityId) {
auto lock = NetworkAndResource.lock();
ClientEntityId_t cId = lock->ReMapEntities.toClient(entityId);
lock->checkPacketBorder(8);
lock->NextPacket << (uint8_t) ToClient::TestLinkCameraToEntity
<< cId;
lock->checkPacketBorder(4);
lock->NextPacket << (uint8_t) ToClient::TestLinkCameraToEntity;
}
ResourceRequest RemoteClient::pushPreparedPackets() {