RakNet
Packet callbacks, transport state and RakNet message operations.
raknet and RakNet refer to the same library. The application's network setting must be enabled. enabled reports this state; callback registration/removal is otherwise a no-op, while manual send/receive raises Network disabled. Native observation is queued to the Lua scheduler, not executed inline on a network thread. Use the canonical underscore names below. The current registration helper does not install the attempted addsendhook/addreceivehook/removesendhook/removereceivehook/removeallsendhooks/removeallreceivehooks shorthand aliases as table members.
Observers
raknet.add_send_hook
raknet.add_send_hook(callback: (RakNetMessage) -> ()): function?Registers an outgoing observer, returning the supplied callback. Registering the same function in the same VM twice does not duplicate it. Returns no value while disabled.
Also available as RakNet.add_send_hook.
raknet.add_receive_hook
raknet.add_receive_hook(callback: (RakNetMessage) -> ()): function?Registers an incoming observer with the same identity and return rules as add_send_hook.
Also available as RakNet.add_receive_hook.
raknet.remove_send_hook
raknet.remove_send_hook(callback: function): ()Removes that outgoing observer in the current VM. When the final outgoing observer is removed, outgoing persistent rules are cleared.
Also available as RakNet.remove_send_hook.
raknet.remove_receive_hook
raknet.remove_receive_hook(callback: function): ()Removes that incoming observer in the current VM. Removing the final incoming observer clears incoming persistent rules.
Also available as RakNet.remove_receive_hook.
raknet.remove_all_send_hooks
raknet.remove_all_send_hooks(): ()Removes all outgoing observers belonging to the current VM, even while disabled. Persistent outgoing rules are cleared once no observers remain.
Also available as RakNet.remove_all_send_hooks.
raknet.remove_all_receive_hooks
raknet.remove_all_receive_hooks(): ()Removes all incoming observers belonging to the current VM, even while disabled. Persistent incoming rules are cleared once no observers remain.
Also available as RakNet.remove_all_receive_hooks.
raknet.enabled
raknet.enabled(): booleanReturns the current application network-feature setting. This function does not enable or disable it.
Also available as RakNet.enabled.
Manual packets
Packet data may be a binary string, buffer or dense byte array. It must contain 1–1,048,576 bytes; array entries must be finite integers in 0–255. Successful calls queue a copy and return no values. Actual transport dispatch occurs later on an available matching native connection. Invalid arguments, unavailable connections, a disabled feature, memory allocation failure or full dispatch queue raise an error.
raknet.send
raknet.send(data: string | buffer | {number}, options: PacketSendOptions?): ()Queues an outgoing packet. Also accepts positional arguments: raknet.send(data, priority?, reliability?, orderingChannel?, transport?, transportChannel?). Options use the case-sensitive field names below; backend values are case-insensitive.
Also available as RakNet.send.
raknet.receive
raknet.receive(data: string | buffer | {number}, options: {Transport: string?}?): ()Queues a packet for the incoming dispatch path. Also accepts raknet.receive(data, transport?). A TransportChannel is not accepted for incoming dispatch; Priority, Reliability and OrderingChannel fields are not read from incoming options.
Also available as RakNet.receive.
RakNetMessage
Observer callbacks receive a table snapshot. Its byte fields do not share writable storage with the native packet. Block and SetData are only valid during the callback; using them later raises Callback finished. Observer errors are swallowed by the dispatcher. Callbacks must finish without yielding.
RakNetMessage:Block
message:Block(): ()Records a persistent block rule for this original PacketId and direction. Observation is deferred: this changes future matching packets, not the already-observed packet. Rule lifetime ends when cleared by observer removal/reset.
RakNetMessage:SetData
message:SetData(data: string | buffer | {number}): ()Records replacement bytes for a persistent rule matching the original PacketId and direction. The displayed AsBuffer/AsString/AsArray fields remain the earlier snapshot. This method's table reader converts entries to byte values; unlike manual send/receive, it does not perform the strict packet-array validation.
Rules are keyed by direction and first packet byte, not by a unique packet instance. Up to 2,048 observations are queued per direction and up to 256 per direction are processed in a scheduler tick, so this API is a bounded observation stream.
Written for Lynx 0.0.0
Something unclear? Tell us on Discord