RakNet

RakNet.add_send_hook

Registers a callback for observed outgoing RakNet packets.

문법

RakNet.add_send_hook(callback: (packet: RakNetPacket) -> ()): function
별칭 raknet.add_send_hook

인수

이름타입설명
callback(packet: RakNetPacket) -> ()Function called with each observed outgoing RakNetPacket.

반환값

이름타입설명
callbackfunctionThe same callback function that was passed in.

설명

Registers a callback for observed outgoing 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.

1개 파라미터로 호출합니다: callback. 인수 표는 필수 값과 동작을 조정하는 값을 설명합니다.

callback (function)을 반환합니다. 반환 표를 사용해 성공 값, nil 결과, 복구 가능한 오류를 구분하세요.

예제

Observe outgoing packets with a callback and remove the same callback later.

if not raknet.is_enabled then
    return
end

local function onSend(packet)
    print(packet.ID, packet.Size)
end

raknet.add_send_hook(onSend)
task.wait(1)
raknet.remove_send_hook(onSend)

타입

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.