Skip to main content

Packet Interceptor

The PacketInterceptor class is used to intercept packets that are sent and received by the client. It allows users to add callback functions that will be applied to the packets.

Properties

  • clientCallbacks: A map that stores all the callback functions that are registered for client packets. The keys are unique IDs, and the values are the callback functions.
  • serverCallbacks: A map that stores all the callback functions that are registered for server packets. The keys are unique IDs, and the values are the callback functions. Methods
  • addCallback(type: "client" | "server", callback: Function): number: This method is used to add a callback function for a specific type of packet. The type parameter should be either "client" or "server", and the callback parameter should be a function that takes in a single argument (the packet) and returns the modified packet. This method returns a unique ID for the callback function that was added.

When the type is "client", the callback function will be applied BEFORE the packet is sent to the server. This means that for example if you want to modify a chat packet, you can add a new callback and modify the packet.

It works the same for server. The server type is used to modify packets BEFORE the bundle receives them. You can spoof accessories, change the player's coordinates, etc.

  • removeCallback(callbackId: number): This method is used to remove a callback function by its ID. The callbackId parameter should be the ID that was returned when the callback function was added.

Usage

You can add callback functions for client and server packets using the addCallback method:

const clientCallbackId = interceptor.addCallback("client", (packet) => {
// modify the packet here
return packet;
});

const serverCallbackId = interceptor.addCallback("server", (packet) => {
// modify the packet here
return packet;
});

NOTE: The packet in the callback function is not decoded, that means that you will have to use msgpack to decode it, and then RETURN THE ENCODED PACKET.

If you do not return a encoded packet, the packet will fail.

You can remove callbacks by their ID using the removeCallback method

interceptor.removeCallback(clientCallbackId);