Better Packets Check Settings

This commit is contained in:
LinsaFTW 2022-12-22 00:16:06 -03:00
parent 125b7dffaf
commit 856fc12bd5

View File

@ -1,4 +1,4 @@
From c0f61de5f384a414161976dc5b05be6a1869d090 Mon Sep 17 00:00:00 2001
From d9165053dc58f369fa9920b7112b71fc17912cf9 Mon Sep 17 00:00:00 2001
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
Date: Fri, 4 Mar 2022 13:35:53 -0300
Subject: [PATCH] Antibot System
@ -599,10 +599,10 @@ index 000000000..165963629
+}
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsCheck.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsCheck.java
new file mode 100644
index 000000000..0de670b3f
index 000000000..199da2920
--- /dev/null
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsCheck.java
@@ -0,0 +1,67 @@
@@ -0,0 +1,62 @@
+package dev._2lstudios.flamecord.antibot;
+
+import java.net.SocketAddress;
@ -656,12 +656,7 @@ index 000000000..0de670b3f
+ if (vls >= config.getAntibotPacketsVlsToKick()) {
+ return PacketsCheckResult.KICK;
+ } else if (vls >= config.getAntibotPacketsVlsToCancel()) {
+ if (addressData.isCancelled()) {
+ return PacketsCheckResult.CANCEL;
+ } else {
+ addressData.setCancelled(true);
+ return PacketsCheckResult.FIRST_CANCEL;
+ }
+ return PacketsCheckResult.CANCEL;
+ } else {
+ return PacketsCheckResult.NONE;
+ }
@ -672,10 +667,10 @@ index 000000000..0de670b3f
+}
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsData.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsData.java
new file mode 100644
index 000000000..db1997d63
index 000000000..c4a63e21e
--- /dev/null
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsData.java
@@ -0,0 +1,102 @@
@@ -0,0 +1,113 @@
+package dev._2lstudios.flamecord.antibot;
+
+import java.net.SocketAddress;
@ -699,14 +694,15 @@ index 000000000..db1997d63
+ // The vls of the current address because of rate
+ private double packetsVlsRate = 0;
+
+ // If this was cancelled in the last second
+ private boolean cancelled = false;
+
+ // The last time vls was calculated
+ private long lastVlsCalculated = System.currentTimeMillis();
+
+ // The vls by packet ids
+ private Map<Integer, Double> vlsByPacketId = new HashMap<>();
+
+ // If cancellation was printed
+ private boolean cancelPrinted = false;
+
+ public PacketsData(SocketAddress address) {
+ this.address = address;
+ }
@ -715,16 +711,34 @@ index 000000000..db1997d63
+ return (double) (int) (number * 1000) / 1000;
+ }
+
+ public void printKick() {
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog()) {
+ System.out
+ .println("[FlameCord] [" + address
+ + "] was kicked because of too many packets");
+ }
+ }
+
+ public void printCancel() {
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog() && !cancelPrinted) {
+ System.out
+ .println("[FlameCord] [" + address
+ + "] was cancelled because of too many packets");
+ this.cancelPrinted = true;
+ }
+ }
+
+ public void printPackets() {
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsDebug() && this.packetsVls > 0) {
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsDebug()
+ && simplify(this.packetsVls) > 0) {
+ System.out
+ .println("[FlameCord] [" + address
+ + "] debug is enabled, showing stats (Total: " + simplify(packetsVls) + "vls Size: "
+ + simplify(packetsVlsSize) + "vls Rate: " + simplify(packetsVlsRate) + "vls)");
+ for (Entry<Integer, Double> entry : this.vlsByPacketId.entrySet()) {
+ System.out.print(entry.getKey() + "-" + simplify(entry.getValue()) + "vls, ");
+ }
+ System.out.println("");
+ for (Entry<Integer, Double> entry : this.vlsByPacketId.entrySet()) {
+ System.out.print(entry.getKey() + "-" + simplify(entry.getValue()) + "vls, ");
+ }
+ System.out.println("");
+ }
+ }
+
@ -732,11 +746,11 @@ index 000000000..db1997d63
+ if (System.currentTimeMillis() - lastVlsCalculated >= 1000) {
+ printPackets();
+
+ this.cancelPrinted = false;
+ this.packetsVls = 0;
+ this.packetsVlsSize = 0;
+ this.packetsVlsRate = 0;
+ this.vlsByPacketId.clear();
+ this.cancelled = false;
+ this.lastVlsCalculated = System.currentTimeMillis();
+ }
+
@ -762,14 +776,6 @@ index 000000000..db1997d63
+ }
+ }
+
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ public void setCancelled(boolean cancelled) {
+ this.cancelled = cancelled;
+ }
+
+ public double getPacketsVlsSize() {
+ return packetsVlsSize;
+ }
@ -938,7 +944,7 @@ index 000000000..68cc4c217
+ }
+}
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
index a1d23f74d..367c25d19 100644
index a1d23f74d..d42e3d75f 100644
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
@@ -16,6 +16,160 @@ import net.md_5.bungee.config.Configuration;
@ -1027,9 +1033,9 @@ index a1d23f74d..367c25d19 100644
+ @Getter
+ private boolean antibotPacketsDebug = false;
+ @Getter
+ private double antibotPacketsVlsPerByte = 0.00001;
+ private double antibotPacketsVlsPerByte = 0.0017;
+ @Getter
+ private double antibotPacketsVlsPerPacket = 0.01;
+ private double antibotPacketsVlsPerPacket = 0.1;
+ @Getter
+ private double antibotPacketsVlsToKick = 100;
+ @Getter
@ -1145,14 +1151,14 @@ index 4f306660e..5faab6166 100644
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/enums/PacketsCheckResult.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/enums/PacketsCheckResult.java
new file mode 100644
index 000000000..53f1648ab
index 000000000..285810ea1
--- /dev/null
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/enums/PacketsCheckResult.java
@@ -0,0 +1,5 @@
+package dev._2lstudios.flamecord.enums;
+
+public enum PacketsCheckResult {
+ KICK, FIRST_CANCEL, CANCEL, NONE
+ KICK, CANCEL, NONE
+}
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/enums/PacketsViolationReason.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/enums/PacketsViolationReason.java
new file mode 100644
@ -1200,10 +1206,10 @@ index 000000000..7f26e7a0d
+}
\ No newline at end of file
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
index 6316143f7..209e4f143 100644
index 6316143f7..a1af4e09e 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
@@ -51,12 +51,46 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
@@ -51,12 +51,38 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
throw new FastDecoderException("Error decoding packet with too big capacity: " + capacity);
}
}
@ -1215,21 +1221,13 @@ index 6316143f7..209e4f143 100644
+
+ switch (result) {
+ case KICK:
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog()) {
+ System.out
+ .println("[FlameCord] [" + ctx.channel().remoteAddress()
+ + "] was kicked because of too many packets");
+ }
+ FlameCord.getInstance().getCheckManager().getPacketsCheck().getData(ctx.channel().remoteAddress()).printKick();
+
+ in.skipBytes(in.readableBytes());
+ ctx.close();
+ return;
+ case CANCEL:
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog()) {
+ System.out
+ .println("[FlameCord] [" + ctx.channel().remoteAddress()
+ + "] was cancelled because of too many packets");
+ }
+ FlameCord.getInstance().getCheckManager().getPacketsCheck().getData(ctx.channel().remoteAddress()).printCancel();
+
+ in.skipBytes(in.readableBytes());
+ return;