mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-05 18:21:27 +01:00
Better Packets Check Settings
This commit is contained in:
parent
125b7dffaf
commit
856fc12bd5
@ -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>
|
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
|
||||||
Date: Fri, 4 Mar 2022 13:35:53 -0300
|
Date: Fri, 4 Mar 2022 13:35:53 -0300
|
||||||
Subject: [PATCH] Antibot System
|
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
|
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
|
new file mode 100644
|
||||||
index 000000000..0de670b3f
|
index 000000000..199da2920
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsCheck.java
|
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsCheck.java
|
||||||
@@ -0,0 +1,67 @@
|
@@ -0,0 +1,62 @@
|
||||||
+package dev._2lstudios.flamecord.antibot;
|
+package dev._2lstudios.flamecord.antibot;
|
||||||
+
|
+
|
||||||
+import java.net.SocketAddress;
|
+import java.net.SocketAddress;
|
||||||
@ -656,13 +656,8 @@ index 000000000..0de670b3f
|
|||||||
+ if (vls >= config.getAntibotPacketsVlsToKick()) {
|
+ if (vls >= config.getAntibotPacketsVlsToKick()) {
|
||||||
+ return PacketsCheckResult.KICK;
|
+ return PacketsCheckResult.KICK;
|
||||||
+ } else if (vls >= config.getAntibotPacketsVlsToCancel()) {
|
+ } else if (vls >= config.getAntibotPacketsVlsToCancel()) {
|
||||||
+ if (addressData.isCancelled()) {
|
|
||||||
+ return PacketsCheckResult.CANCEL;
|
+ return PacketsCheckResult.CANCEL;
|
||||||
+ } else {
|
+ } else {
|
||||||
+ addressData.setCancelled(true);
|
|
||||||
+ return PacketsCheckResult.FIRST_CANCEL;
|
|
||||||
+ }
|
|
||||||
+ } else {
|
|
||||||
+ return PacketsCheckResult.NONE;
|
+ 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
|
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
|
new file mode 100644
|
||||||
index 000000000..db1997d63
|
index 000000000..c4a63e21e
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsData.java
|
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/PacketsData.java
|
||||||
@@ -0,0 +1,102 @@
|
@@ -0,0 +1,113 @@
|
||||||
+package dev._2lstudios.flamecord.antibot;
|
+package dev._2lstudios.flamecord.antibot;
|
||||||
+
|
+
|
||||||
+import java.net.SocketAddress;
|
+import java.net.SocketAddress;
|
||||||
@ -699,14 +694,15 @@ index 000000000..db1997d63
|
|||||||
+ // The vls of the current address because of rate
|
+ // The vls of the current address because of rate
|
||||||
+ private double packetsVlsRate = 0;
|
+ private double packetsVlsRate = 0;
|
||||||
+
|
+
|
||||||
+ // If this was cancelled in the last second
|
|
||||||
+ private boolean cancelled = false;
|
|
||||||
+
|
|
||||||
+ // The last time vls was calculated
|
+ // The last time vls was calculated
|
||||||
+ private long lastVlsCalculated = System.currentTimeMillis();
|
+ private long lastVlsCalculated = System.currentTimeMillis();
|
||||||
+
|
+
|
||||||
|
+ // The vls by packet ids
|
||||||
+ private Map<Integer, Double> vlsByPacketId = new HashMap<>();
|
+ private Map<Integer, Double> vlsByPacketId = new HashMap<>();
|
||||||
+
|
+
|
||||||
|
+ // If cancellation was printed
|
||||||
|
+ private boolean cancelPrinted = false;
|
||||||
|
+
|
||||||
+ public PacketsData(SocketAddress address) {
|
+ public PacketsData(SocketAddress address) {
|
||||||
+ this.address = address;
|
+ this.address = address;
|
||||||
+ }
|
+ }
|
||||||
@ -715,8 +711,26 @@ index 000000000..db1997d63
|
|||||||
+ return (double) (int) (number * 1000) / 1000;
|
+ 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() {
|
+ public void printPackets() {
|
||||||
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsDebug() && this.packetsVls > 0) {
|
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsDebug()
|
||||||
|
+ && simplify(this.packetsVls) > 0) {
|
||||||
+ System.out
|
+ System.out
|
||||||
+ .println("[FlameCord] [" + address
|
+ .println("[FlameCord] [" + address
|
||||||
+ + "] debug is enabled, showing stats (Total: " + simplify(packetsVls) + "vls Size: "
|
+ + "] debug is enabled, showing stats (Total: " + simplify(packetsVls) + "vls Size: "
|
||||||
@ -732,11 +746,11 @@ index 000000000..db1997d63
|
|||||||
+ if (System.currentTimeMillis() - lastVlsCalculated >= 1000) {
|
+ if (System.currentTimeMillis() - lastVlsCalculated >= 1000) {
|
||||||
+ printPackets();
|
+ printPackets();
|
||||||
+
|
+
|
||||||
|
+ this.cancelPrinted = false;
|
||||||
+ this.packetsVls = 0;
|
+ this.packetsVls = 0;
|
||||||
+ this.packetsVlsSize = 0;
|
+ this.packetsVlsSize = 0;
|
||||||
+ this.packetsVlsRate = 0;
|
+ this.packetsVlsRate = 0;
|
||||||
+ this.vlsByPacketId.clear();
|
+ this.vlsByPacketId.clear();
|
||||||
+ this.cancelled = false;
|
|
||||||
+ this.lastVlsCalculated = System.currentTimeMillis();
|
+ 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() {
|
+ public double getPacketsVlsSize() {
|
||||||
+ return packetsVlsSize;
|
+ 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
|
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
|
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
|
||||||
+++ b/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;
|
@@ -16,6 +16,160 @@ import net.md_5.bungee.config.Configuration;
|
||||||
@ -1027,9 +1033,9 @@ index a1d23f74d..367c25d19 100644
|
|||||||
+ @Getter
|
+ @Getter
|
||||||
+ private boolean antibotPacketsDebug = false;
|
+ private boolean antibotPacketsDebug = false;
|
||||||
+ @Getter
|
+ @Getter
|
||||||
+ private double antibotPacketsVlsPerByte = 0.00001;
|
+ private double antibotPacketsVlsPerByte = 0.0017;
|
||||||
+ @Getter
|
+ @Getter
|
||||||
+ private double antibotPacketsVlsPerPacket = 0.01;
|
+ private double antibotPacketsVlsPerPacket = 0.1;
|
||||||
+ @Getter
|
+ @Getter
|
||||||
+ private double antibotPacketsVlsToKick = 100;
|
+ private double antibotPacketsVlsToKick = 100;
|
||||||
+ @Getter
|
+ @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
|
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
|
new file mode 100644
|
||||||
index 000000000..53f1648ab
|
index 000000000..285810ea1
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/enums/PacketsCheckResult.java
|
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/enums/PacketsCheckResult.java
|
||||||
@@ -0,0 +1,5 @@
|
@@ -0,0 +1,5 @@
|
||||||
+package dev._2lstudios.flamecord.enums;
|
+package dev._2lstudios.flamecord.enums;
|
||||||
+
|
+
|
||||||
+public enum PacketsCheckResult {
|
+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
|
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
|
new file mode 100644
|
||||||
@ -1200,10 +1206,10 @@ index 000000000..7f26e7a0d
|
|||||||
+}
|
+}
|
||||||
\ No newline at end of file
|
\ 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
|
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
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
|
||||||
+++ b/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);
|
throw new FastDecoderException("Error decoding packet with too big capacity: " + capacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1215,21 +1221,13 @@ index 6316143f7..209e4f143 100644
|
|||||||
+
|
+
|
||||||
+ switch (result) {
|
+ switch (result) {
|
||||||
+ case KICK:
|
+ case KICK:
|
||||||
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog()) {
|
+ FlameCord.getInstance().getCheckManager().getPacketsCheck().getData(ctx.channel().remoteAddress()).printKick();
|
||||||
+ System.out
|
|
||||||
+ .println("[FlameCord] [" + ctx.channel().remoteAddress()
|
|
||||||
+ + "] was kicked because of too many packets");
|
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
+ in.skipBytes(in.readableBytes());
|
+ in.skipBytes(in.readableBytes());
|
||||||
+ ctx.close();
|
+ ctx.close();
|
||||||
+ return;
|
+ return;
|
||||||
+ case CANCEL:
|
+ case CANCEL:
|
||||||
+ if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog()) {
|
+ FlameCord.getInstance().getCheckManager().getPacketsCheck().getData(ctx.channel().remoteAddress()).printCancel();
|
||||||
+ System.out
|
|
||||||
+ .println("[FlameCord] [" + ctx.channel().remoteAddress()
|
|
||||||
+ + "] was cancelled because of too many packets");
|
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
+ in.skipBytes(in.readableBytes());
|
+ in.skipBytes(in.readableBytes());
|
||||||
+ return;
|
+ return;
|
||||||
|
Loading…
Reference in New Issue
Block a user