style: format packetFilter
This commit is contained in:
@@ -5,33 +5,37 @@ import { Transform, TransformCallback } from "stream";
|
||||
* Packet yang terlalu kecil kemungkinan gagal didekripsi oleh Discord
|
||||
*/
|
||||
export class PacketFilter extends Transform {
|
||||
private minPacketSize: number;
|
||||
private filteredCount: number = 0;
|
||||
private totalCount: number = 0;
|
||||
private minPacketSize: number;
|
||||
private filteredCount: number = 0;
|
||||
private totalCount: number = 0;
|
||||
|
||||
constructor(minPacketSize: number = 10) {
|
||||
super();
|
||||
this.minPacketSize = minPacketSize;
|
||||
constructor(minPacketSize: number = 10) {
|
||||
super();
|
||||
this.minPacketSize = minPacketSize;
|
||||
}
|
||||
|
||||
_transform(
|
||||
chunk: Buffer,
|
||||
encoding: string,
|
||||
callback: TransformCallback,
|
||||
): void {
|
||||
this.totalCount++;
|
||||
|
||||
// Filter packet yang terlalu kecil
|
||||
if (chunk.length >= this.minPacketSize) {
|
||||
this.push(chunk);
|
||||
} else {
|
||||
this.filteredCount++;
|
||||
if (this.filteredCount % 10 === 0) {
|
||||
// console.log(`[packet-filter] Filtered ${this.filteredCount} small packets (size < ${this.minPacketSize} bytes)`);
|
||||
}
|
||||
}
|
||||
|
||||
_transform(chunk: Buffer, encoding: string, callback: TransformCallback): void {
|
||||
this.totalCount++;
|
||||
|
||||
// Filter packet yang terlalu kecil
|
||||
if (chunk.length >= this.minPacketSize) {
|
||||
this.push(chunk);
|
||||
} else {
|
||||
this.filteredCount++;
|
||||
if (this.filteredCount % 10 === 0) {
|
||||
// console.log(`[packet-filter] Filtered ${this.filteredCount} small packets (size < ${this.minPacketSize} bytes)`);
|
||||
}
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback: TransformCallback): void {
|
||||
// console.log(`[packet-filter] Total packets: ${this.totalCount}, filtered: ${this.filteredCount}, passed: ${this.totalCount - this.filteredCount}`);
|
||||
callback();
|
||||
}
|
||||
_flush(callback: TransformCallback): void {
|
||||
// console.log(`[packet-filter] Total packets: ${this.totalCount}, filtered: ${this.filteredCount}, passed: ${this.totalCount - this.filteredCount}`);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user