13
0
geforkt von Mirrors/Paper
Paper/nms-patches/HandshakeListener.patch

70 Zeilen
3.5 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/HandshakeListener.java
+++ b/net/minecraft/server/HandshakeListener.java
2020-06-25 02:00:00 +02:00
@@ -1,7 +1,16 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.net.InetAddress;
+import java.util.HashMap;
+// CraftBukkit end
+
public class HandshakeListener implements PacketHandshakingInListener {
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - add fields
+ private static final HashMap<InetAddress, Long> throttleTracker = new HashMap<InetAddress, Long>();
+ private static int throttleCounter = 0;
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
private static final IChatBaseComponent a = new ChatComponentText("Ignoring status request");
private final MinecraftServer b;
private final NetworkManager c;
@@ -18,6 +27,41 @@
this.c.setProtocol(EnumProtocol.LOGIN);
2019-05-27 22:30:00 +02:00
ChatMessage chatmessage;
2015-02-26 23:41:06 +01:00
2019-05-27 22:30:00 +02:00
+ // CraftBukkit start - Connection throttle
+ try {
+ long currentTime = System.currentTimeMillis();
2020-06-25 02:00:00 +02:00
+ long connectionThrottle = this.b.server.getConnectionThrottle();
+ InetAddress address = ((java.net.InetSocketAddress) this.c.getSocketAddress()).getAddress();
+
2019-05-27 22:30:00 +02:00
+ synchronized (throttleTracker) {
+ if (throttleTracker.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - throttleTracker.get(address) < connectionThrottle) {
+ throttleTracker.put(address, currentTime);
+ chatmessage = new ChatMessage("Connection throttled! Please wait before reconnecting.");
2020-06-25 02:00:00 +02:00
+ this.c.sendPacket(new PacketLoginOutDisconnect(chatmessage));
+ this.c.close(chatmessage);
2019-05-27 22:30:00 +02:00
+ return;
+ }
+
2019-05-27 22:30:00 +02:00
+ throttleTracker.put(address, currentTime);
+ throttleCounter++;
+ if (throttleCounter > 200) {
+ throttleCounter = 0;
+
2019-05-27 22:30:00 +02:00
+ // Cleanup stale entries
+ java.util.Iterator iter = throttleTracker.entrySet().iterator();
+ while (iter.hasNext()) {
+ java.util.Map.Entry<InetAddress, Long> entry = (java.util.Map.Entry) iter.next();
+ if (entry.getValue() > connectionThrottle) {
+ iter.remove();
+ }
+ }
+ }
+ }
2019-05-27 22:30:00 +02:00
+ } catch (Throwable t) {
+ org.apache.logging.log4j.LogManager.getLogger().debug("Failed to check connection throttle", t);
+ }
2019-05-27 22:30:00 +02:00
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2019-12-10 23:00:00 +01:00
if (packethandshakinginsetprotocol.c() > SharedConstants.getGameVersion().getProtocolVersion()) {
chatmessage = new ChatMessage("multiplayer.disconnect.outdated_server", new Object[]{SharedConstants.getGameVersion().getName()});
2020-06-25 02:00:00 +02:00
this.c.sendPacket(new PacketLoginOutDisconnect(chatmessage));
@@ -28,6 +72,7 @@
this.c.close(chatmessage);
2019-05-27 22:30:00 +02:00
} else {
2020-06-25 02:00:00 +02:00
this.c.setPacketListener(new LoginListener(this.b, this.c));
2020-08-11 23:00:00 +02:00
+ ((LoginListener) this.c.j()).hostname = packethandshakinginsetprotocol.hostname + ":" + packethandshakinginsetprotocol.port; // CraftBukkit - set hostname
2019-05-27 22:30:00 +02:00
}
break;
case STATUS: