The event global provides an event system for intercepting and handling packets, connection events, and game events. All packet interception happens in real-time as data flows between the client and server.
event.on("Input", function(ctx) if ctx:has_packet() then local pkt = ctx:get_packet() logger.info("[Chat] {}", pkt.text) -- Block specific messages if pkt.text == "!block" then ctx:cancel() logger.info("Blocked message") end endend)
event.on("server:SendToServer", function(ctx) local pkt = ctx:parse() -- Modify packet fields directly if pkt.net_id then pkt.net_id = 999 end -- Cancel original and send modified version ctx:cancel() send.to_server(pkt)end)
event.on("Input", function(ctx) if ctx:has_packet() then local pkt = ctx:get_packet() if pkt.text == "!hello" then ctx:cancel() local response = LogPacket.new() response.msg = "`2Hello from the proxy!" send.to_client(response) end endend)
event.on("ServerBoundPacket", function(ctx) local pkt = ctx:get_packet() if not pkt then return end -- Handle text packets if pkt.text_parse then local action = pkt.text_parse:get("action") if action ~= "" then logger.info("[Text] Action: {}", action) end end -- Handle game packets if pkt.game_packet then logger.info("[Game] Type: {} NetID: {}", pkt.game_packet.type, pkt.game_packet.net_id ) -- Check for jump flag if pkt.game_packet.flags & packet.PacketFlag.PACKET_FLAG_ON_JUMP ~= 0 then logger.info("[Game] Player jumped!") end end -- Handle variant packets if pkt.variant then logger.info("[Variant] Function: {}", pkt.variant:get(0)) endend)