Skip to content

refactor(netpacket): Simplify raw byte data handling in NetPacket:FillBuffer functions#2310

Open
xezon wants to merge 2 commits intoTheSuperHackers:mainfrom
xezon:xezon/refactor-netpacket-fillbuffer-byte-handling
Open

refactor(netpacket): Simplify raw byte data handling in NetPacket:FillBuffer functions#2310
xezon wants to merge 2 commits intoTheSuperHackers:mainfrom
xezon:xezon/refactor-netpacket-fillbuffer-byte-handling

Conversation

@xezon
Copy link

@xezon xezon commented Feb 15, 2026

This change simplifies raw byte data handling in NetPacket:FillBuffer functions.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing labels Feb 15, 2026
@greptile-apps
Copy link

greptile-apps bot commented Feb 15, 2026

Greptile Summary

Refactored multiple FillBuffer functions to use pointer arithmetic (buffer += sizeof(...)) instead of offset-based indexing (buffer + offset), improving code clarity and reducing opportunities for offset calculation errors.

Key changes:

  • ConstructNetCommandMsgFromRawData: Uses sizeof(variable) instead of hardcoded type sizes for consistency
  • FillBufferWithGameCommand: Replaced offset arithmetic with direct buffer pointer advancement
  • FillBufferWithDisconnectChatCommand: Removed manual offset tracking
  • FillBufferWithChatCommand: Simplified variable data writing with pointer arithmetic
  • FillBufferWithFileMessage: Replaced character-by-character filename copying with single memcpy using getByteCount() + 1
  • FillBufferWithFileAnnounceMessage: Same filename handling improvement

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring systematically replaces offset-based buffer indexing with pointer arithmetic throughout multiple functions. The changes are mechanical and improve code safety by eliminating manual offset tracking. Previous thread comments have been addressed (the commandTypeByte conversion is now correctly implemented). All changes follow the same pattern and are functionally equivalent to the original code.
  • No files require special attention

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameNetwork/NetPacket.cpp Refactored buffer writing to use pointer arithmetic instead of offset calculations, improving code clarity and safety

Flowchart

flowchart TD
    A[Start: FillBuffer function called] --> B[Create packet struct]
    B --> C[Copy fixed packet header to buffer]
    C --> D[Advance buffer pointer: buffer += sizeof]
    D --> E{Variable data to write?}
    E -->|Yes| F[Write data to buffer]
    F --> G[Advance buffer pointer]
    G --> E
    E -->|No| H[End: Buffer filled]
    
    style D fill:#90EE90
    style G fill:#90EE90
    style C fill:#87CEEB
    style F fill:#87CEEB
Loading

Last reviewed commit: 4f21260

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant