refactor: skill and projectile game messages as structs

Converts the skill messages to NetGameMsgs in SkillMessages.{h,cpp}:
AddSkill and RemoveSkill (SendToClient, as before), EchoStartSkill,
EchoSyncSkill and DoClientProjectileImpact, and the received
SelectSkill, StartSkill, SyncSkill and RequestServerProjectileImpact.
The one-off StartSkill, EchoStartSkill, SyncSkill, EchoSyncSkill,
RequestServerProjectileImpact and DoClientProjectileImpact classes are
deleted; SkillComponent, BehaviorContext and InventoryComponent build
the structs, and the dashboard's message decoder reads them.

The received messages are registered in GameMessageHandler's map and
their switch cases are deleted; the handlers call SkillComponent as
before. The echoes still go to every client except the caster, through
the new NetGameMsg::BroadcastExcept. SelectSkill still accepts any
payload, since the old case read nothing. Handler logic is unchanged
(the SyncSkill case's unused hex dump of the payload is dropped).

No wire change. Verified byte for byte against frozen verbatim copies
of the old classes and functions over an input grid (every optional
field set and unset, empty, short and long behavior streams), received
messages compared with the old classes' read sequences and truncated
payloads rejected, the echo's broadcast-except destination compared
with the old send, hand computed golden bytes, round trips, and a
deliberate mutation made the tests fail. Messages that fail to
deserialize are now dropped instead of being handled half read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-26 19:11:26 -05:00
parent 2711c69e3e
commit 27de0cf268
20 changed files with 1385 additions and 801 deletions

View File

@@ -15,6 +15,7 @@
#include "GameMessages.h"
#include "InventoryMessages.h"
#include "Database.h"
#include "SkillMessages.h"
#include "SkillComponent.h"
#include "Character.h"
#include "EntityManager.h"
@@ -1324,14 +1325,25 @@ void InventoryComponent::RemoveItemSkills(const LOT lot) {
// The client stores one acquiredSkillsInfo entry per skillID, tagged with the slotID
// it was originally added with. Always send RemoveSkill to clear that entry, then
// re-add with the surviving slot so the client shows it in the correct place.
GameMessages::SendRemoveSkill(m_Parent, skillId);
GameMessages::RemoveSkill removeSkill;
removeSkill.target = m_Parent->GetObjectID();
removeSkill.skillID = skillId;
removeSkill.SendToClient(m_Parent->GetSystemAddress());
if (surviving != m_Skills.end()) {
GameMessages::SendAddSkill(m_Parent, skillId, surviving->first);
GameMessages::AddSkill addSkill;
addSkill.target = m_Parent->GetObjectID();
addSkill.skillID = skillId;
addSkill.slotID = surviving->first;
addSkill.SendToClient(m_Parent->GetSystemAddress());
}
if (slot == BehaviorSlot::Primary) {
m_Skills.insert_or_assign(BehaviorSlot::Primary, 1);
GameMessages::SendAddSkill(m_Parent, 1, BehaviorSlot::Primary);
GameMessages::AddSkill addSkill;
addSkill.target = m_Parent->GetObjectID();
addSkill.skillID = 1;
addSkill.slotID = BehaviorSlot::Primary;
addSkill.SendToClient(m_Parent->GetSystemAddress());
}
}
@@ -1784,7 +1796,10 @@ bool InventoryComponent::SetSkill(BehaviorSlot slot, uint32_t skillId) {
return pair.first != slot && pair.second == old;
});
if (!usedElsewhere) {
GameMessages::SendRemoveSkill(m_Parent, old);
GameMessages::RemoveSkill removeSkill;
removeSkill.target = m_Parent->GetObjectID();
removeSkill.skillID = old;
removeSkill.SendToClient(m_Parent->GetSystemAddress());
}
}
@@ -1795,7 +1810,11 @@ bool InventoryComponent::SetSkill(BehaviorSlot slot, uint32_t skillId) {
return pair.first != slot && pair.second == skillId;
});
if (!alreadyKnown) {
GameMessages::SendAddSkill(m_Parent, skillId, slot);
GameMessages::AddSkill addSkill;
addSkill.target = m_Parent->GetObjectID();
addSkill.skillID = skillId;
addSkill.slotID = slot;
addSkill.SendToClient(m_Parent->GetSystemAddress());
}
m_Skills.insert_or_assign(slot, skillId);