1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
package net.minecraft.server;
import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
// CraftBukkit start
import java.net.InetAddress;
import java.util.HashMap;
// CraftBukkit end
public class HandshakeListener implements PacketHandshakingInListener {
// CraftBukkit start
private static final HashMap<InetAddress, Long> throttleTracker = new HashMap<InetAddress, Long>();
private static int throttleCounter = 0;
// CraftBukkit end
private final MinecraftServer a;
private final NetworkManager b;
public HandshakeListener(MinecraftServer minecraftserver, NetworkManager networkmanager) {
this.a = minecraftserver;
this.b = networkmanager;
}
public void a(PacketHandshakingInSetProtocol packethandshakinginsetprotocol) {
switch (ProtocolOrdinalWrapper.a[packethandshakinginsetprotocol.c().ordinal()]) {
case 1:
this.b.a(EnumProtocol.LOGIN);
ChatComponentText chatcomponenttext;
// CraftBukkit start
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), new GenericFutureListener[0]);
this.b.a(chatcomponenttext); // Should be close
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().error("Failed to check connection throttle", t);
}
// CraftBukkit end
if (packethandshakinginsetprotocol.d() > 4) {
chatcomponenttext = new ChatComponentText("Outdated server! I\'m still on 1.7.2");
this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
this.b.a((IChatBaseComponent) chatcomponenttext);
} else if (packethandshakinginsetprotocol.d() < 4) {
chatcomponenttext = new ChatComponentText("Outdated client! Please use 1.7.2");
this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
this.b.a((IChatBaseComponent) 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;
case 2:
this.b.a(EnumProtocol.STATUS);
this.b.a((PacketListener) (new PacketStatusListener(this.a, this.b)));
break;
default:
throw new UnsupportedOperationException("Invalid intention " + packethandshakinginsetprotocol.c());
}
}
public void a(IChatBaseComponent ichatbasecomponent) {}
public void a(EnumProtocol enumprotocol, EnumProtocol enumprotocol1) {
if (enumprotocol1 != EnumProtocol.LOGIN && enumprotocol1 != EnumProtocol.STATUS) {
throw new UnsupportedOperationException("Invalid state " + enumprotocol1);
}
}
public void a() {}
}
|