Paper/nms-patches/HandshakeListener.patch

71 lines
3.3 KiB
Diff
Raw Normal View History

2015-05-22 21:33:34 +08:00
--- /home/matt/mc-dev-private//net/minecraft/server/HandshakeListener.java 2015-05-22 14:12:44.567222056 +0100
+++ src/main/java/net/minecraft/server/HandshakeListener.java 2015-05-22 14:12:44.567222056 +0100
2015-02-27 06:41:06 +08:00
@@ -1,7 +1,17 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.net.InetAddress;
+import java.util.HashMap;
+// CraftBukkit end
+
public class HandshakeListener implements PacketHandshakingInListener {
2015-02-27 06:41:06 +08:00
+ // CraftBukkit start - add fields
+ private static final HashMap<InetAddress, Long> throttleTracker = new HashMap<InetAddress, Long>();
+ private static int throttleCounter = 0;
+ // CraftBukkit end
2015-02-27 06:41:06 +08:00
+
private final MinecraftServer a;
private final NetworkManager b;
2015-02-27 06:41:06 +08:00
@@ -16,6 +26,41 @@
this.b.a(EnumProtocol.LOGIN);
ChatComponentText chatcomponenttext;
2015-02-27 06:41:06 +08:00
+ // CraftBukkit start - Connection throttle
+ try {
+ long currentTime = System.currentTimeMillis();
+ long connectionThrottle = MinecraftServer.getServer().server.getConnectionThrottle();
+ InetAddress address = ((java.net.InetSocketAddress) this.b.getSocketAddress()).getAddress();
+
+ synchronized (throttleTracker) {
+ if (throttleTracker.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - throttleTracker.get(address) < connectionThrottle) {
+ throttleTracker.put(address, currentTime);
+ chatcomponenttext = new ChatComponentText("Connection throttled! Please wait before reconnecting.");
+ this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext));
+ this.b.close(chatcomponenttext);
+ return;
+ }
+
+ throttleTracker.put(address, currentTime);
+ throttleCounter++;
+ if (throttleCounter > 200) {
+ throttleCounter = 0;
+
+ // 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();
+ }
+ }
+ }
+ }
+ } catch (Throwable t) {
+ org.apache.logging.log4j.LogManager.getLogger().debug("Failed to check connection throttle", t);
+ }
+ // CraftBukkit end
2015-02-27 06:41:06 +08:00
+
if (packethandshakinginsetprotocol.b() > 47) {
2015-05-22 21:33:34 +08:00
chatcomponenttext = new ChatComponentText("Outdated server! I\'m still on 1.8.5");
2015-02-27 06:41:06 +08:00
this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext));
@@ -26,6 +71,7 @@
this.b.close(chatcomponenttext);
} else {
this.b.a((PacketListener) (new LoginListener(this.a, this.b)));
+ ((LoginListener) this.b.getPacketListener()).hostname = packethandshakinginsetprotocol.b + ":" + packethandshakinginsetprotocol.c; // CraftBukkit - set hostname
}
break;