Skip to content

Conversation

@bobtista
Copy link

@bobtista bobtista commented Oct 7, 2025

Created NetPacketStructs.h with packed struct definitions for network packets
Refactored 27 getPackedByteCount() functions to use packed structs: 22 use pure sizeof(struct) calls, 5 use sizeof(struct) as a base for additional calculations.

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

I cannot compile this branch. There are 700 linker errors.

@Mauller
Copy link

Mauller commented Oct 7, 2025

You can still do this for the messages that are variable in length, just make the fixed portion of the message a struct.
Then you just calculate the message size based on the size of the fixed portion and the variable data appended to it.

@bobtista bobtista force-pushed the bobtista/packedstructpackets branch 2 times, most recently from dbb01a8 to 9d9e804 Compare October 8, 2025 17:25
@bobtista bobtista force-pushed the bobtista/packedstructpackets branch from 9d9e804 to db5c043 Compare October 8, 2025 22:08

++msglen; // the NetPacketFieldTypes::Data
msglen += sizeof(UnsignedByte); // string msglength
UnsignedByte textmsglen = cmdMsg->getText().getLength();
Copy link

Choose a reason for hiding this comment

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

Side note: This truncates 4 bytes to 1 byte 👀

@xezon xezon added Major Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Refactor Edits the code with insignificant behavior changes, is never user facing labels Oct 13, 2025
@bobtista bobtista force-pushed the bobtista/packedstructpackets branch from 34ab595 to ba6335d Compare October 13, 2025 19:27
@bobtista bobtista force-pushed the bobtista/packedstructpackets branch 2 times, most recently from 960e7a4 to ad27a6c Compare October 14, 2025 03:29
@bobtista bobtista force-pushed the bobtista/packedstructpackets branch from 586fafb to 07b592f Compare October 17, 2025 16:58
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

This looks very promising.

// Frame Info Command Packet
////////////////////////////////////////////////////////////////////////////////

struct NetPacketFrameCommand {
Copy link

Choose a reason for hiding this comment

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

Would it perhaps make sense to put these packed structs into the non packed message classes?

Such as:

class NetGameCommandMsg : public NetCommandMsg
{
...
public:
#pragma pack(push, 1)
  struct Packed
  {
    ...
  };
#pragma pack(pop)
...
};

This way they would sit together and would perhaps be easier to maintain? Not sure.

Copy link
Author

Choose a reason for hiding this comment

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

Yes we could do that, we'd get to use return sizeof(Packed) instead of return sizeof(NetPacketGameCommand), and we could remove some imports, and it keeps the related code together visually. On the other hand, the packed structs are really about network serialization, not about the message logic. Are there places where we only want to import one vs both? Any file that includes NetCommandMsg.h would now also pull in all the packed struct definitions. Whatever you think is best

Copy link

Choose a reason for hiding this comment

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

Maybe move in later changes when more refactor work is done and we have a clearer picture. Right now seems to be ok.

Copy link
Author

Choose a reason for hiding this comment

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

You mean later in another PR or now in this one?

Copy link

Choose a reason for hiding this comment

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

In a future Pull.

@bobtista
Copy link
Author

@xezon any changes you want still?

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Did you push all changes? (Some Review Comments were closed without response or action)

@bobtista
Copy link
Author

Did you push all changes? (Some Review Comments were closed without response or action)

I just pushed the latest. I tried to only resolve comments if I addressed them in a commit.

@xezon
Copy link

xezon commented Oct 21, 2025

For example you marked resolved the virtual function comment without action. Or the obsolete CppMacros.h comment without action. So I wonder what was the resolution for it.

Edit: I see the edits now. Strangely GitHub did not show the changes before. I will look over tomorrow.

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

I think it is good. Needs replication in Generals.

@xezon xezon added the Approved Pull Request was approved label Oct 22, 2025
@bobtista
Copy link
Author

I think it is good. Needs replication in Generals.

I just pushed the replication commit. Note, I just copied NetCommandMsg and NetPacket.cpp and corrected comments that mentioned Zero Hour.

@xezon
Copy link

xezon commented Oct 22, 2025

Copying files from ZH to Generals is risky, unless they are identical. Better use script to replicate:

Batch:

FOR /F "delims=" %%b IN ('git merge-base --fork-point main') DO git diff %%b > changes.patch
git apply -p2 --directory=Generals --reject --whitespace=fix changes.patch
del changes.patch

@bobtista
Copy link
Author

Copying files from ZH to Generals is risky, unless they are identical. Better use script to replicate:

Batch:

FOR /F "delims=" %%b IN ('git merge-base --fork-point main') DO git diff %%b > changes.patch
git apply -p2 --directory=Generals --reject --whitespace=fix changes.patch
del changes.patch

Ah ok. 118 rejected hunks. I'll try going through them like it's a merge conflict.

…mand pattern

Reorganize getPackedByteCount() functions to their respective class sections for better code organization
…classes

- Add NetLoadCompleteCommandMsg and NetTimeOutGameStartCommandMsg classes
- Update ConnectionManager.cpp to use specific classes instead of base NetCommandMsg
- Remove special case handling from NetPacket.cpp since all types now have classes
- Eliminate the switch statement entirely - now just calls virtual function
nit: Clean up tabs from empty lines

nit: clean up import

nit: add comments, split line for readability

nit: clean up comments
refactor(network): move NetPacketStructs to Core
…nd isRoomForTimeOutGameStartMessage size calculations
…teMessage and isRoomForTimeOutGameStartMessage
@bobtista bobtista force-pushed the bobtista/packedstructpackets branch from b52ea4a to 275e85e Compare December 21, 2025 18:55
@bobtista
Copy link
Author

What is the current state of this change?

I tested all but the following:
WrapperCommand
PacketRouterAckCommand
PacketRouterQueryCommand

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Sizes of PacketRouterAckCommand, PacketRouterQueryCommand are correct.

inline UnsignedInt getPlayerID() const { return m_playerID; }
inline UnsignedShort getID() const { return m_id; }
inline void setNetCommandType(NetCommandType type) { m_commandType = type; }
inline NetCommandType getNetCommandType() { return m_commandType; }
Copy link

Choose a reason for hiding this comment

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

Remove inline again

@xezon xezon removed the Approved Pull Request was approved label Dec 22, 2025
@xezon xezon dismissed their stale review December 22, 2025 22:00

Still needs a bit of work

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

Labels

Major Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants