Skip to content

refactor(Packet): Add ServerPacket structure#3361

Open
0blu wants to merge 3 commits intovmangos:developmentfrom
0blu:nice-packets-5-only-some-static
Open

refactor(Packet): Add ServerPacket structure#3361
0blu wants to merge 3 commits intovmangos:developmentfrom
0blu:nice-packets-5-only-some-static

Conversation

@0blu
Copy link
Copy Markdown
Collaborator

@0blu 0blu commented Apr 11, 2026

Converts some of the manually built WorldPacket (which were sent by the server) to nicely structured ServerPackets.

Due to the large amount of changes required this will be split into multiple PRs.

@0blu 0blu force-pushed the nice-packets-5-only-some-static branch from 0e94066 to 896c5b3 Compare April 11, 2026 17:16
// Simplified SMSG_CAST_RESULT for a basic spell failure (status=2) with no extra data.
// For complex failures with additional payload (e.g. cooldown time, required area),
// use the full Spell::SendCastResult() path in Spell.cpp instead.
class CastResultSimpleFailure final : public ServerPacket
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we pass the Spell* to the packet so it can build the whole structure?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear .reload

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not invalidate the pointers. We read the new data into the existing spell entry.
https://github.com/vmangos/core/blob/development/src/game/Spells/SpellMgr.cpp#L3776

// --- Server Packets ---

static constexpr uint8 PARTY_MAX_POSITIVE_AURAS = 32; // MAX_POSITIVE_AURAS
static constexpr uint8 PARTY_MAX_NEGATIVE_AURAS = 16; // MAX_AURAS - MAX_POSITIVE_AURAS
Copy link
Copy Markdown
Contributor

@ratkosrb ratkosrb Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we hardcode this here instead of using the actual defines

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops these changes were not intended for this PR.
I have a larger PR where I cherry picked some changes.

I would need to import SpellAuraDefines.h which then gets indirectly imported in a lot of places.
(because WorldSession.h has all the packet definitions imported)

buffer << charterEntry;
buffer << charterDisplayId;
buffer << charterCost;
buffer << unknown;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tried taking a peak at how this is used to determine it's possible meaning?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be & 1 to show the UI. 🤷
image

@ratkosrb
Copy link
Copy Markdown
Contributor

For cases where the client assigns the same handler to multiple packets, reading the same structure, we should use the same packet class for them as well and just pass opcode in constructor, rather than creating duplicate structures.

@0blu 0blu force-pushed the nice-packets-5-only-some-static branch from 896c5b3 to 5f698c5 Compare April 13, 2026 23:03
@0blu
Copy link
Copy Markdown
Collaborator Author

0blu commented Apr 13, 2026

For cases where the client assigns the same handler to multiple packets, reading the same structure, we should use the same packet class for them as well and just pass opcode in constructor, rather than creating duplicate structures.

I would like to prevent mistakes in the code.
If the developer can freely choose an opcode, the struct might be invalid.

I've used NullClientPacket for empty client packets, which I might want to change too.
Just so every packet is uniquely typed.

@0blu 0blu force-pushed the nice-packets-5-only-some-static branch from 5f698c5 to a1d82da Compare April 13, 2026 23:16
@0blu 0blu force-pushed the nice-packets-5-only-some-static branch from a1d82da to a1385d1 Compare April 13, 2026 23:38
@ratkosrb
Copy link
Copy Markdown
Contributor

If the developer can freely choose an opcode, the struct might be invalid.

That doesn't prevent us from having invalid structs. I don't like this duplication of code. There are a million movement packets with the same structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants