ไวยากรณ์
RakNet.add_receive_hook(callback: (packet: RakNetPacket) -> ()): functionAliases
raknet.add_receive_hookArguments
| ชื่อ | ชนิด | คำอธิบาย |
|---|---|---|
callback | (packet: RakNetPacket) -> () | Function called with each observed incoming RakNetPacket. |
Returns
| ชื่อ | ชนิด | คำอธิบาย |
|---|---|---|
callback | function | The same callback function that was passed in. |
คำอธิบาย
Registers a callback for observed incoming RakNet packets. The callback receives one RakNetPacket while the packet is valid. Registering the same closure again replaces its stored reference. The function returns the callback it was given.
เรียกด้วย parameter 1 ค่า: callback ตาราง arguments อธิบายค่าที่จำเป็นและค่าที่ปรับพฤติกรรม
ส่งคืน callback (function) ใช้ตาราง returns เพื่อแยกค่าที่สำเร็จ ผลลัพธ์ nil และ error ที่จัดการต่อได้
ตัวอย่าง
Observe incoming packets with a callback and remove the same callback later.
if not raknet.is_enabled then
return
end
local function onReceive(packet)
print(packet.ID, packet.Size)
end
raknet.add_receive_hook(onReceive)
task.wait(1)
raknet.remove_receive_hook(onReceive)Types
RakNetPacket
Live packet object passed to RakNet hooks and packet signal callbacks. It is only valid during the callback that receives it.
SetData (data: string | buffer | {number}) -> () Replaces packet bytes and updates the packet id from the first byte, or 0 for empty data.Block () -> () Marks the packet as blocked.Ignore () -> () Alias that resolves to Block.AsString string Packet bytes as a Lua string.AsArray {number} Packet bytes as a 1-based array of numbers.AsBuffer buffer Packet bytes as a buffer.Data buffer Packet bytes as a buffer.ID number Packet id value. PacketId, PacketID, and Id resolve to the same value.Priority number Packet priority value.Reliability number Packet reliability value.OrderingChannel number Packet ordering channel value.SystemIdentifier string Packet system identifier as decimal string.Broadcast boolean Packet broadcast flag.ForceReceiptNumber number Packet receipt number.Size number Number of bytes in the packet data.