mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
refactor: racing and vehicle game messages as structs
Converts the 12 racing / vehicle / modular assembly messages DLU sends
and the 8 it receives to NetGameMsgs in RacingMessages.{h,cpp}, adds
eRacingClientNotificationType for NotifyRacingClient's event type,
switches the callers (RacingControlComponent, CarBoostBehavior,
PossessorComponent, slash commands), registers the received messages
in GameMessageHandler's map and deletes the old functions. Handlers are
copied verbatim. Also moves the byte-equality test helpers into a
shared GameMessageTestUtils.h.
No wire change. Verified byte for byte against a frozen verbatim copy
of the old functions over an input grid, to one client and broadcast;
received messages compared with the old handlers' read sequences
(including all 16 optional-field combinations of
VehicleNotifyHitImaginationServer) and every truncated payload
rejected; hand computed golden bytes; round trips; a deliberate field
mutation made the tests fail. Layouts confirmed against the 1.10.64
client in Ghidra. Malformed received messages are
dropped (see the foundations commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "ActivityMessages.h"
|
||||
#include "GameDependencies.h"
|
||||
#include "PacketTestUtils.h"
|
||||
#include "GameMessageTestUtils.h"
|
||||
#include "Legacy/ActivityMessagesLegacy.h"
|
||||
|
||||
#include <array>
|
||||
@@ -10,60 +10,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace PacketTestUtils;
|
||||
|
||||
namespace {
|
||||
SystemAddress ClientAddress() {
|
||||
SystemAddress address;
|
||||
address.binaryAddress = 0x0100007f;
|
||||
address.port = 2003;
|
||||
return address;
|
||||
}
|
||||
|
||||
const std::array<LWOOBJID, 3> g_Targets = { LWOOBJID_EMPTY, 0x1000000000000001LL, 0x0102030405060708LL };
|
||||
const std::array<SystemAddress, 2> g_Addresses = { ClientAddress(), UNASSIGNED_SYSTEM_ADDRESS };
|
||||
|
||||
PacketBytes StructPacket(const GameMessages::NetGameMsg& msg) {
|
||||
RakNet::BitStream bitStream;
|
||||
msg.WritePacket(bitStream);
|
||||
return FromBitStream(bitStream);
|
||||
}
|
||||
|
||||
// Sends the same message through the frozen legacy function and through the struct, to one client and as a
|
||||
// broadcast, and requires identical bytes and the same effective destination.
|
||||
void ExpectSameAsLegacy(const std::function<void(const SystemAddress&)>& legacySend, const GameMessages::NetGameMsg& msg) {
|
||||
for (const auto& address : g_Addresses) {
|
||||
SCOPED_TRACE(address == UNASSIGNED_SYSTEM_ADDRESS ? "broadcast" : "single client");
|
||||
const auto legacyPackets = Capture([&] { legacySend(address); });
|
||||
const auto newPackets = Capture([&] { msg.Send(address); });
|
||||
|
||||
ASSERT_FALSE(legacyPackets.empty());
|
||||
ASSERT_EQ(newPackets.size(), 1);
|
||||
// The legacy broadcast path also did a second Send(UNASSIGNED_SYSTEM_ADDRESS, broadcast = false),
|
||||
// which RakPeer::Send rejects without sending anything. Every copy must still match byte for byte.
|
||||
for (const auto& legacyPacket : legacyPackets) {
|
||||
EXPECT_PACKET_EQ(FromCapture(legacyPacket), FromCapture(newPackets[0]));
|
||||
}
|
||||
EXPECT_EQ(legacyPackets[0].broadcast, newPackets[0].broadcast);
|
||||
EXPECT_EQ(legacyPackets[0].sysAddr, newPackets[0].sysAddr);
|
||||
EXPECT_PACKET_EQ(FromCapture(newPackets[0]), StructPacket(msg));
|
||||
}
|
||||
}
|
||||
|
||||
// Serializes msg, reads it back into a fresh T and checks the fresh copy serializes to the same bytes.
|
||||
template<typename T>
|
||||
T RoundTrip(const T& msg) {
|
||||
RakNet::BitStream bitStream;
|
||||
msg.Serialize(bitStream);
|
||||
T copy;
|
||||
EXPECT_TRUE(copy.Deserialize(bitStream));
|
||||
EXPECT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
RakNet::BitStream again;
|
||||
copy.Serialize(again);
|
||||
EXPECT_PACKET_EQ(FromBitStream(bitStream), FromBitStream(again));
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
using namespace GameMessageTestUtils;
|
||||
|
||||
class ActivityMessagesTests : public GameDependenciesTest {
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user