Registers a passive listener for outgoing packets. The callback receives a packet record and cannot change or stop the packet. Returns an id for disconnect.
RakNet is off by default. The library exists only when the RakNet feature is enabled in the Athena loader, and it is published on getgenv() rather than as a plain global. Guard your code with if getgenv().raknet then ... end, or read raknet.is_enabled.

Parameters

function
required
Called as callback(record) for each outgoing packet.

Returns

number
The listener id, for disconnect.

Behavior

  • Passive only. To rewrite or drop a packet use add_send_hook.
  • Errors are contained. A callback that raises is logged and skipped; it does not break the transport or stop other listeners.
  • Keep it short. This runs on the network path, so heavy work there costs throughput.

Example

Errors