mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-10 14:53:43 +00:00
refactor: remove the packet macros, WriteHeader and PacketUtils
Nothing in the server writes or reads a packet by hand any more, so the helpers for doing so go: - CBITSTREAM, CMSGHEADER, CINSTREAM, CINSTREAM_SKIP_HEADER, SEND_PACKET, SEND_PACKET_BROADCAST and HEADER_SIZE leave dCommonVars.h; - the free BitStreamUtils::WriteHeader (LUBitStream::WriteHeader writes the same bytes) and the unused PacketUtils::SavePacket are deleted. The last raw reads are replaced: WorldServer builds its input stream directly, the master packet logs read the header with LUBitStream::ReadHeader instead of peeking at packet->data[1] and [3], and MessageInspector reads a sent game message's header with the new NetGameMsg::ReadPacketHeader (the counterpart of WritePacket) instead of memcmp/memcpy. packet->data[0] is still compared with RakNet's own connection IDs. The frozen oracles keep using the macros verbatim through the test-only tests/dGameTests/LegacyPacketMacros.h; the HeaderSkip tests, which only tested CINSTREAM_SKIP_HEADER, are removed. docs/PacketArchitecture.md: "where we are" now describes the final state and what still touches raw bytes (RakNet IDs, replica headers, behavior bit streams), and a new section collects the known wire discrepancies found during the conversion, with client addresses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "Entity.h"
|
||||
#include "Game.h"
|
||||
#include "GameMessageDecoder.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Logger.h"
|
||||
#include "master/MessageCapture.h"
|
||||
#include "MessageType/Client.h"
|
||||
@@ -140,21 +141,15 @@ namespace {
|
||||
|
||||
// Packets the server sends: only game messages are kept
|
||||
void OnSend(const RakNet::BitStream& bitStream, const SystemAddress& sysAddr, bool broadcast) {
|
||||
static const auto header = [] {
|
||||
RakNet::BitStream expected;
|
||||
BitStreamUtils::WriteHeader(expected, ServiceType::CLIENT, MessageType::Client::GAME_MSG);
|
||||
return std::string(reinterpret_cast<const char*>(expected.GetData()), expected.GetNumberOfBytesUsed());
|
||||
}();
|
||||
const auto totalBits = bitStream.GetNumberOfBitsUsed();
|
||||
if (totalBits < GAME_MESSAGE_HEADER_BYTES * 8) return;
|
||||
const auto* data = bitStream.GetData();
|
||||
if (std::memcmp(data, header.data(), header.size()) != 0) return;
|
||||
|
||||
auto* data = bitStream.GetData();
|
||||
RakNet::BitStream stream(data, bitStream.GetNumberOfBytesUsed(), false);
|
||||
LWOOBJID objectId{};
|
||||
uint16_t messageId{};
|
||||
std::memcpy(&objectId, data + 8, sizeof(objectId));
|
||||
std::memcpy(&messageId, data + 8 + sizeof(objectId), sizeof(messageId));
|
||||
Record(eMessageDirection::TO_CLIENT, sysAddr, broadcast, objectId, messageId, data + GAME_MESSAGE_HEADER_BYTES,
|
||||
MessageType::Game messageId{};
|
||||
if (!GameMessages::NetGameMsg::ReadPacketHeader(stream, objectId, messageId)) return;
|
||||
|
||||
Record(eMessageDirection::TO_CLIENT, sysAddr, broadcast, objectId, static_cast<uint16_t>(messageId), data + GAME_MESSAGE_HEADER_BYTES,
|
||||
static_cast<uint32_t>(totalBits - GAME_MESSAGE_HEADER_BYTES * 8));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user