Skip to main content

Packet Manager

The Packet Manager is a class that is used to count and manage the number of packets. It has a number of read-only properties and methods that can be used to monitor the number of packets sent and determine if the connection is in danger of being disconnected due to sending too many packets.

Properties

  • packetCountPerMinute: number - The number of packets sent per minute.
  • packetCountPerSecond: number - The number of packets sent per second.
  • packetTime: number - The time in seconds until the packet count per minute is reset.
  • packetLimitPerMinute: number - The limit of packets that can be sent per minute.
  • packetLimitPerSecond: number - The limit of packets that can be sent per second.

Methods

addPacket(): number

This method is used to add a packet to the packet count. It should be called every time a packet is sent over the websocket.

getKickPercentagePerMinute(): number

This method returns the percentage of packets that have been sent over the packet limit per minute. A value of 5400 or greater indicates that the connection is in danger of being disconnected.

getKickPercentagePerSecond(): number

This method returns the percentage of packets that have been sent over the packet limit per second. A value of 120 or greater indicates that the connection is in danger of being disconnected.

getPacketCountPerMinute(): number

This method returns the current packet count per minute. 5400 is the maximum safe limit, if its close or above, you should be careful.

getPacketCountPerSecond(): number

This method returns the current packet count per second. 120 is the maximum safe limit, if its close or above, you should be careful.

getPacketTime(): number

This method returns the current packet time.

Example

Here is an example of how to use the Packet Manager:

let packetManager = MooMoo.PacketManager;

for (let i = 0; i < 200; i++) {
MooMoo.sendPacket("pp")
}

console.log(packetManager.getPacketCountPerMinute()); // 200
console.log(packetManager.getPacketCountPerSecond()); // 200
console.log(packetManager.getKickPercentagePerMinute()); // (200/5400)*100 = 3.7%
console.log(packetManager.getKickPercentagePerSecond()); // (200/120)*100 = 166.7%

As you can see, the percentage of packets sent over the limit is very low, so it is safe to send more packets. But the packet count per second is very high, so you are very likely to be kicked.