Files
DarkflameServer/dGame/dGameMessages/SkillMessages.h
Aaron Kimbrell b2a1e9e0b8 refactor: remaining game messages as structs, switch removed
Every game message still written or read by hand is now a NetGameMsg with
Serialize and Deserialize, in per-domain files:
- MovementMessages: teleport, platforms (resync and its request), orient to
  angle, node rotation lock, gravity scale, jetpack mode, control scheme,
  respawn checkpoint, rails (set/start, ready, cancel, arrived), mount
  inventory ID, dismount complete, possession ack, ghost reference override
  and position, camera cycling (eCameraTargetCyclingMode moves here).
- ZoneMessages: player loaded (the old PLAYER_LOADED case), ready for
  updates, player ready, restore to post load stats, server done loading,
  invalid zone transfer list, zone summary display/dismissed, level
  processing complete, object world state, and the localized announcement
  WorldMigration wrote by hand.
- PlayerMessages: chat mode, GM level, LEGO score, currency, reputation,
  GM invis, pickup currency, zone and player statistics, chat commands, bug
  reports, verify ack.
- ObjectMessages: fire event client/server side, notify client
  (zone) object, notify object, script network vars, failed preconditions,
  terminate interaction, set name, request use, request server object info.
- QuickBuildMessages: notify state, enable, cancel.
- ActivityMessages gains match response/update/request, leaderboard request
  and data, shooting gallery score/rotation/fire, activity state change.
- MissionMessages gains MissionDialogueCancelled (a no-op, as before).
The wire structs left in GameMessages.h move to their domains (tooltip and
emote to Effects, loot and item use to Inventory, model build to Building,
behavior sound to Property, skill sets to Skill) and gain the missing
direction. The dismount logic moves to PossessorComponent::OnDismountComplete.

Every inbound message is registered in the GameMessageHandler map; the
switch is gone, and GameMessages.cpp only holds the GameMsg/NetGameMsg base
code. Call sites build the structs (NotifyClientObject, TerminateInteraction,
Teleport, PlatformResync, FireEventClientSide, NotifyObject and
NotifyClientZoneObject get convenience constructors like PlayFXEffect).
Dead senders are dropped: SendSetShootingGalleryParams (no callers, field
order was a guess), SendTeamPickupItem (the struct already existed),
SendRequestActivitySummaryLeaderboardData (the struct covers it).

Verified with RemainingMessagesTests: every old Send* function is frozen
verbatim in Legacy/RemainingMessagesLegacy.h and compared byte for byte
(same bits, destination and broadcast flag) over grids of inputs; every old
Handle* read sequence is frozen as a Read* oracle and compared with the
struct's Deserialize; round trips, truncation and a golden packet.
PlayerLoaded (0x00dc36f0), SetGMLevel (0x00dd6230), MissionDialogueCancelled
(0x00d9cc10) and LocalizedAnnouncementServerToSingleClient (0x00f23c50)
were checked against the client. Behaviour notes: an inbound message that
fails to deserialize is dropped, so ParseChatMessage over MAX_MESSAGE_LENGTH
is dropped instead of truncated, and PLAYER_LOADED / READY_FOR_UPDATES /
MISSION_DIALOGUE_CANCELLED now read their (unused) client fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:56 -05:00

153 lines
5.8 KiB
C++

#ifndef SKILLMESSAGES_H
#define SKILLMESSAGES_H
#include "GameMessages.h"
#include "NiPoint3.h"
#include "NiQuaternion.h"
#include <string>
enum class BehaviorSlot : int32_t;
// Game messages for skills: casting (StartSkill / SyncSkill and their echoes), projectile impacts and the
// player's skill bar. Field names follow the client (legouniverse.exe 1.10.64); fields are listed in wire order.
// sBitStream is a skill's behavior data (its own bit stream), sent as a u32 byte count and the bytes.
namespace GameMessages {
// Server -> client, to the player only.
struct AddSkill : public NetGameMsg {
AddSkill() : NetGameMsg(MessageType::Game::ADD_SKILL) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
int32_t AICombatWeight{ 0 }; // optional
bool bFromSkillSet{ false };
int32_t castType{ 0 }; // optional
float fTimeSecs{ -1.0f }; // optional
int32_t iTimesCanCast{ -1 }; // optional
TSkillID skillID{};
BehaviorSlot slotID{ static_cast<BehaviorSlot>(-1) }; // optional, BehaviorSlot::Invalid when unset
bool temporary{ true };
};
// Server -> client, to the player only.
struct RemoveSkill : public NetGameMsg {
RemoveSkill() : NetGameMsg(MessageType::Game::REMOVE_SKILL) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
bool bFromSkillSet{ false };
TSkillID skillID{};
};
// Client -> server. The player picked a skill; DLU only uses it to fix invisible items on first load.
struct SelectSkill : public NetGameMsg {
SelectSkill() : NetGameMsg(MessageType::Game::SELECT_SKILL) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
// Not read by DLU: the old handler ignored the payload, so a message without it is still accepted.
bool bFromSkillSet{ false };
int32_t skillID{};
};
// Client -> server. The player cast a skill.
struct StartSkill : public NetGameMsg {
StartSkill() : NetGameMsg(MessageType::Game::START_SKILL) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
bool bUsedMouse{ false };
LWOOBJID consumableItemID{ LWOOBJID_EMPTY }; // optional
float fCasterLatency{ 0.0f }; // optional
int32_t iCastType{ 0 }; // optional
NiPoint3 lastClickedPosit{ NiPoint3Constant::ZERO }; // optional
LWOOBJID optionalOriginatorID{};
LWOOBJID optionalTargetID{ LWOOBJID_EMPTY }; // optional
NiQuaternion originatorRot{ QuatUtils::IDENTITY }; // optional
std::string sBitStream{};
TSkillID skillID{ 0 };
uint32_t uiSkillHandle{ 0 }; // optional
};
// Server -> clients. A skill cast echoed to the other clients so they play it too.
struct EchoStartSkill : public NetGameMsg {
EchoStartSkill() : NetGameMsg(MessageType::Game::ECHO_START_SKILL) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
bool bUsedMouse{ false };
float fCasterLatency{ 0.0f }; // optional
int32_t iCastType{ 0 }; // optional
NiPoint3 lastClickedPosit{ NiPoint3Constant::ZERO }; // optional
LWOOBJID optionalOriginatorID{};
LWOOBJID optionalTargetID{ LWOOBJID_EMPTY }; // optional
NiQuaternion originatorRot{ QuatUtils::IDENTITY }; // optional
std::string sBitStream{};
TSkillID skillID{ 0 };
uint32_t uiSkillHandle{ 0 }; // optional
};
// Client -> server. More behavior data for a skill that is being cast.
struct SyncSkill : public NetGameMsg {
SyncSkill() : NetGameMsg(MessageType::Game::SYNC_SKILL) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
bool bDone{};
std::string sBitStream{};
uint32_t uiBehaviorHandle{};
uint32_t uiSkillHandle{};
};
// Server -> clients.
struct EchoSyncSkill : public NetGameMsg {
EchoSyncSkill() : NetGameMsg(MessageType::Game::ECHO_SYNC_SKILL) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
bool bDone{};
std::string sBitStream{};
uint32_t uiBehaviorHandle{};
uint32_t uiSkillHandle{};
};
// Client -> server. A player's projectile hit something.
struct RequestServerProjectileImpact : public NetGameMsg {
RequestServerProjectileImpact() : NetGameMsg(MessageType::Game::REQUEST_SERVER_PROJECTILE_IMPACT) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
LWOOBJID i64LocalID{ LWOOBJID_EMPTY }; // optional
LWOOBJID i64TargetID{ LWOOBJID_EMPTY }; // optional
std::string sBitStream{};
};
// Server -> clients. A server side projectile hit something.
struct DoClientProjectileImpact : public NetGameMsg {
DoClientProjectileImpact() : NetGameMsg(MessageType::Game::DO_CLIENT_PROJECTILE_IMPACT) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
LWOOBJID i64OrgID{ LWOOBJID_EMPTY }; // optional
LWOOBJID i64OwnerID{ LWOOBJID_EMPTY }; // optional
LWOOBJID i64TargetID{ LWOOBJID_EMPTY }; // optional
std::string sBitStream{};
};
struct UseSkillSet : public NetGameMsg {
UseSkillSet() : NetGameMsg(MessageType::Game::USE_SKILL_SET) {}
void Serialize(RakNet::BitStream& bitStream) const override;
bool Deserialize(RakNet::BitStream& bitStream) override;
bool bRemove{};
LWOOBJID possessedId{ LWOOBJID_EMPTY };
int32_t setId{ -1 };
};
};
#endif // SKILLMESSAGES_H