blob: ef7e10d2086c098963b3819ece73e8533c86f199 (
plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package net.minecraft.server;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class DedicatedServerConnectionThread extends Thread {
private final List a = Collections.synchronizedList(new ArrayList());
private final HashMap b = new HashMap();
private int c = 0;
private final ServerSocket d;
private ServerConnection e;
private final InetAddress f;
private final int g;
long connectionThrottle; // CraftBukkit
public DedicatedServerConnectionThread(ServerConnection serverconnection, InetAddress inetaddress, int i) throws IOException { // CraftBukkit - added throws
super("Listen thread");
this.e = serverconnection;
this.g = i;
this.d = new ServerSocket(i, 0, inetaddress);
this.f = inetaddress == null ? this.d.getInetAddress() : inetaddress;
this.d.setPerformancePreferences(0, 2, 1);
}
public void a() {
List list = this.a;
synchronized (this.a) {
for (int i = 0; i < this.a.size(); ++i) {
PendingConnection pendingconnection = (PendingConnection) this.a.get(i);
try {
pendingconnection.c();
} catch (Exception exception) {
pendingconnection.disconnect("Internal server error");
this.e.d().getLogger().warning("Failed to handle packet for " + pendingconnection.getName() + ": " + exception, (Throwable) exception);
}
if (pendingconnection.b) {
this.a.remove(i--);
}
pendingconnection.networkManager.a();
}
}
}
public void run() {
while (this.e.a) {
try {
Socket socket = this.d.accept();
// CraftBukkit start - Connection throttle
InetAddress address = socket.getInetAddress();
long currentTime = System.currentTimeMillis();
if (((MinecraftServer) this.e.d()).server == null) {
socket.close();
continue;
}
connectionThrottle = ((MinecraftServer) this.e.d()).server.getConnectionThrottle();
synchronized (this.b) {
if (this.b.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - ((Long) this.b.get(address)).longValue() < connectionThrottle) {
this.b.put(address, Long.valueOf(currentTime));
socket.close();
continue;
}
this.b.put(address, Long.valueOf(currentTime));
}
// CraftBukkit end
PendingConnection pendingconnection = new PendingConnection(this.e.d(), socket, "Connection #" + this.c++);
this.a(pendingconnection);
} catch (IOException ioexception) {
this.e.d().getLogger().warning("DSCT: " + ioexception.getMessage()); // CraftBukkit
}
}
this.e.d().getLogger().info("Closing listening thread");
}
private void a(PendingConnection pendingconnection) {
if (pendingconnection == null) {
throw new IllegalArgumentException("Got null pendingconnection!");
} else {
List list = this.a;
synchronized (this.a) {
this.a.add(pendingconnection);
}
}
}
public void a(InetAddress inetaddress) {
if (inetaddress != null) {
HashMap hashmap = this.b;
synchronized (this.b) {
this.b.remove(inetaddress);
}
}
}
public void b() {
try {
this.d.close();
} catch (Throwable throwable) {
;
}
}
}
|