Skip to content

feat(network): packet manager - #448

Merged
Exeloo merged 2 commits into
mainfrom
feat/network/packet-managers
Oct 10, 2026
Merged

Exeloo merged 2 commits into
mainfrom
feat/network/packet-managers

Conversation

@Tchips46

@Tchips46 Tchips46 commented Oct 9, 2026

Copy link
Copy Markdown
Member

Closes #408

Choices

  • Declaration: definePacket<T>(name, { channel?, validate? }), defined in a protocol file shared by client and server. It is exported from @nanoforge-dev/network, so the shared file needs neither /client nor /server.
  • Receiving: two ways, both run in the network __run, before ECS (runAfter: ["ecs"]), so not while paused:
    • packets.on(def, (data, info) => …) listeners, which return an unsubscribe function,
    • packets.read(def), the current tick's packets, for systems.
  • Sending: packets.send / sendToAll / sendToClient. The payload is typed and sent as JSON, on the definition's channel unless overridden.
  • Wire (breaking): every packet starts with [nameLen u8][name]. nameLen = 0 marks a raw sendData packet, still returned by getReceivedPackets().
  • Type id: the name itself, with no registration list. Unknown names get one warning, capped at 100 names.
  • Safety:
    • every listener runs in its own try/catch,
    • a failed validate drops the packet,
    • two definitions with the same name but another channel or validate throw,
    • raw packets left unread for a whole tick are dropped, so typed-only servers can't be flooded.

@Tchips46 Tchips46 self-assigned this Oct 9, 2026
@Tchips46
Tchips46 requested a review from Exeloo as a code owner October 9, 2026 23:40
@github-actions github-actions Bot added documentation Improvements or additions to documentation modules:network Related to Network library labels Oct 9, 2026
@Exeloo
Exeloo merged commit 6444163 into main Oct 10, 2026
3 checks passed
@Exeloo
Exeloo deleted the feat/network/packet-managers branch October 10, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation modules:network Related to Network library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Packet manager included both side

2 participants