In Packet
The in_packet object represents incoming packet data. Provided by the system in packet handler callbacks.
System-Provided Only
Cannot create in_packet objects manually. Only available in on_packet_recv and on_packet_send callbacks.
Methods
packet:get_opcode() -> number
Returns the packet opcode.
lua
function on_packet_recv(packet)
local opcode = packet:get_opcode()
core.log(string.format("Opcode: 0x%04X", opcode))
return true
endpacket:decode_1() -> number
Reads 1 byte (0-255).
packet:decode_2() -> number
Reads 2 bytes (0-65535).
packet:decode_4() -> number
Reads 4 bytes (0-4294967295).
packet:decode_8() -> number
Reads 8 bytes.
packet:decode_string() -> string
Reads a length-prefixed string.
Sequential Reading
Decode methods maintain an internal offset. Each read advances the position. Cannot rewind or re-read data.
Example
lua
function on_packet_recv(packet)
local opcode = packet:get_opcode()
if opcode == 0x1234 then -- Replace with actual opcode
local player_id = packet:decode_4()
local x_pos = packet:decode_2()
local y_pos = packet:decode_2()
core.log(string.format("Player %d at (%d, %d)",
player_id, x_pos, y_pos))
end
return true
end