network.add_receive_hook
Observes incoming packets.
Syntax
Signature
network.add_receive_hook(Callback: function) -> numberAliases
raknet.add_receive_hookpackets.add_receive_hookRakNet.add_receive_hooknetwork.addreceivehookraknet.addreceivehookpackets.addreceivehookRakNet.addreceivehook
Parameters
| Parameter | Type | Description |
|---|---|---|
Callback | function | Called as Callback(Packet) for each observed incoming packet. |
Returns
| Type | Description |
|---|---|
number | Hook ID accepted by network.remove_receive_hook. |
Notes
The callback receives a readonly packet view. Return values are ignored. This observer cannot change or cancel packets already received. Callback failures are reported by the executor. At most 32 send and receive hooks total can be registered.
Example
Luau
local Hook = network.add_receive_hook(function(Packet)
if Packet.type ~= "Chat" then
return
end
local Fields = Packet.decoded
if Fields then
print(Fields.username, Fields.text)
else
warn(Packet.decodeError)
end
-- Incoming hooks observe packets. They cannot edit or block them.
end)
task.delay(15, function()
network.remove_receive_hook(Hook)
end)