2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/HandshakeListener.java
|
|
|
|
+++ b/net/minecraft/server/HandshakeListener.java
|
2015-02-26 23:41:06 +01:00
|
|
|
@@ -1,7 +1,17 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
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
|
|
|
|
2014-11-25 22:32:16 +01: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-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
private final MinecraftServer a;
|
|
|
|
private final NetworkManager b;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2016-05-10 13:47:39 +02:00
|
|
|
@@ -16,6 +26,41 @@
|
2016-02-29 22:32:46 +01:00
|
|
|
this.b.setProtocol(EnumProtocol.LOGIN);
|
2017-05-30 13:25:59 +02:00
|
|
|
ChatMessage chatmessage;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01: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);
|
2017-05-30 13:25:59 +02:00
|
|
|
+ chatmessage = new ChatMessage("Connection throttled! Please wait before reconnecting.");
|
|
|
|
+ this.b.sendPacket(new PacketLoginOutDisconnect(chatmessage));
|
|
|
|
+ this.b.close(chatmessage);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ 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-26 23:41:06 +01:00
|
|
|
+
|
2017-06-08 10:00:00 +02:00
|
|
|
if (packethandshakinginsetprotocol.b() > 335) {
|
|
|
|
chatmessage = new ChatMessage("multiplayer.disconnect.outdated_server", new Object[] { "1.12"});
|
2017-05-30 13:25:59 +02:00
|
|
|
this.b.sendPacket(new PacketLoginOutDisconnect(chatmessage));
|
2016-05-10 13:47:39 +02:00
|
|
|
@@ -26,6 +71,7 @@
|
2017-05-30 13:25:59 +02:00
|
|
|
this.b.close(chatmessage);
|
2014-11-25 22:32:16 +01:00
|
|
|
} else {
|
2016-02-29 22:32:46 +01:00
|
|
|
this.b.setPacketListener(new LoginListener(this.a, this.b));
|
|
|
|
+ ((LoginListener) this.b.i()).hostname = packethandshakinginsetprotocol.hostname + ":" + packethandshakinginsetprotocol.port; // CraftBukkit - set hostname
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|