chore: foundations for struct based packets and game messages

First step of moving hand written bitstream code to struct based
messages (see docs/PacketArchitecture.md). No wire changes.

- GameMsg is now only a server-internal event (delivered to handlers
  registered with RegisterMsg); NetGameMsg is a wire message with
  Send(sysAddr) (UNASSIGNED broadcasts), SendToClient(sysAddr) (one
  client, never broadcasts), WritePacket, Serialize, Deserialize and
  Handle. Mixing them up is now a compile error. NetGameMsgEvent<T> /
  DeliverLocally carry a wire message to local handlers; loot drops,
  pickup, the object debugger, GM invisibility and model RequestUse
  use them. The GM invisibility message keeps its target, so its bytes
  are unchanged.
- Behaviour change: GameMessageHandler logs and drops messages whose
  Deserialize fails instead of handling them with default fields (the
  4 messages already registered: RequestUse, RequestServerObjectInfo,
  ShootingGalleryFire, PickupItem).
- LUBitStream (kept as on main) gets a virtual destructor (Mail deleted
  derived packets through the base) and WritePacket, also used by
  ChatPackets::SendRoutedMsg with identical bytes.
- BitStreamUtils::WriteOptional/ReadOptional for default-flag fields
  and WriteLengthPrefixed/ReadLengthPrefixed for length prefixed
  strings.
- Every message ID enumerator (MessageType::*, ServiceType, Mail's
  wire enums) is pinned with static_asserts, so renumbering or removing
  one fails to compile.
- Tests: dServerMock copies each sent packet (it kept a pointer to the
  caller's destroyed BitStream); PacketTestUtils.h compares packets bit
  for bit; helper tests use hand computed golden bytes and equality
  with the hand written patterns they replace; compile-time checks
  keep the wire/internal split in place.
- docs/PacketArchitecture.md: survey, target architecture,
  conventions, verification method and migration plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-26 10:25:27 -05:00
parent 6f3a8d502f
commit 5f60900934
27 changed files with 2796 additions and 81 deletions

View File

@@ -783,7 +783,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
lootMsg.spawnPos = m_Parent->GetPosition();
lootMsg.sourceID = source;
lootMsg.item = LOT_NULL;
lootMsg.Send();
GameMessages::DeliverLocally(lootMsg);
character->SetCoins(coinsTotal, eLootSourceType::DELETION);
}
}
@@ -1022,17 +1022,17 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source) {
lootMsg.spawnPos = m_Parent->GetPosition();
lootMsg.sourceID = source;
lootMsg.item = LOT_NULL;
lootMsg.Send();
GameMessages::DeliverLocally(lootMsg);
lootMsg.Send(m_Parent->GetSystemAddress());
while (coinsToDrop > MAX_TO_DROP_PER_GM) {
LOG("Dropping 100,000, %llu left", coinsToDrop);
lootMsg.currency = 100'000;
lootMsg.Send();
GameMessages::DeliverLocally(lootMsg);
lootMsg.Send(m_Parent->GetSystemAddress());
coinsToDrop -= 100'000;
}
lootMsg.currency = coinsToDrop;
lootMsg.Send();
GameMessages::DeliverLocally(lootMsg);
lootMsg.Send(m_Parent->GetSystemAddress());
}
return;

View File

@@ -68,7 +68,9 @@ void GhostComponent::GhostEntity(LWOOBJID id) {
m_ObservedEntities.erase(id);
}
bool GhostComponent::OnToggleGMInvis(GameMessages::ToggleGMInvis& gmInvisMsg) {
bool GhostComponent::OnToggleGMInvis(GameMessages::ToggleGMInvisEvent& event) {
auto& gmInvisMsg = event.msg;
gmInvisMsg.target = event.target; // the wire message goes out with the target the event was delivered to
gmInvisMsg.bStateOut = !m_IsGMInvisible;
m_IsGMInvisible = !m_IsGMInvisible;
LOG_DEBUG("GM Invisibility toggled to: %s", m_IsGMInvisible ? "true" : "false");

View File

@@ -43,7 +43,7 @@ public:
void GhostEntity(const LWOOBJID id);
bool OnToggleGMInvis(GameMessages::ToggleGMInvis& msg);
bool OnToggleGMInvis(GameMessages::ToggleGMInvisEvent& event);
bool OnGetGMInvis(GameMessages::GetGMInvis& msg);

View File

@@ -59,7 +59,8 @@ bool ModelComponent::OnResetModelToDefaults(GameMessages::ResetModelToDefaults&
return true;
}
bool ModelComponent::OnRequestUse(GameMessages::RequestUse& requestUse) {
bool ModelComponent::OnRequestUse(GameMessages::RequestUseEvent& event) {
auto& requestUse = event.msg;
bool toReturn = false;
if (!m_IsPaused) {
for (auto& behavior : m_Behaviors) behavior.HandleMsg(requestUse);

View File

@@ -32,7 +32,7 @@ public:
void LoadBehaviors();
void Update(float deltaTime) override;
bool OnRequestUse(GameMessages::RequestUse& requestUse);
bool OnRequestUse(GameMessages::RequestUseEvent& event);
bool OnResetModelToDefaults(GameMessages::ResetModelToDefaults& resetModelToDefaults);
bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo);