2012-08-03 07:06:25 +02:00
|
|
|
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 {
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
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;
|
2012-08-03 07:06:25 +02:00
|
|
|
|
2012-08-03 07:46:21 +02:00
|
|
|
long connectionThrottle; // CraftBukkit
|
|
|
|
|
|
|
|
public DedicatedServerConnectionThread(ServerConnection serverconnection, InetAddress inetaddress, int i) throws IOException { // CraftBukkit - added throws
|
2012-08-03 07:06:25 +02:00
|
|
|
super("Listen thread");
|
2013-03-13 23:33:27 +01:00
|
|
|
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);
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a() {
|
2013-03-13 23:33:27 +01:00
|
|
|
List list = this.a;
|
2012-08-03 07:06:25 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
synchronized (this.a) {
|
|
|
|
for (int i = 0; i < this.a.size(); ++i) {
|
|
|
|
PendingConnection pendingconnection = (PendingConnection) this.a.get(i);
|
2012-08-03 07:06:25 +02:00
|
|
|
|
|
|
|
try {
|
2012-12-20 05:03:52 +01:00
|
|
|
pendingconnection.c();
|
2012-08-03 07:06:25 +02:00
|
|
|
} catch (Exception exception) {
|
2012-12-20 05:03:52 +01:00
|
|
|
pendingconnection.disconnect("Internal server error");
|
2013-03-13 23:33:27 +01:00
|
|
|
this.e.d().getLogger().warning("Failed to handle packet for " + pendingconnection.getName() + ": " + exception, (Throwable) exception);
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (pendingconnection.b) {
|
|
|
|
this.a.remove(i--);
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
pendingconnection.networkManager.a();
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
2013-03-13 23:33:27 +01:00
|
|
|
while (this.e.a) {
|
2012-08-03 07:06:25 +02:00
|
|
|
try {
|
2013-03-13 23:33:27 +01:00
|
|
|
Socket socket = this.d.accept();
|
2012-08-03 07:06:25 +02:00
|
|
|
InetAddress inetaddress = socket.getInetAddress();
|
|
|
|
long i = System.currentTimeMillis();
|
2013-03-13 23:33:27 +01:00
|
|
|
HashMap hashmap = this.b;
|
2012-08-03 07:06:25 +02:00
|
|
|
|
2012-08-03 07:46:21 +02:00
|
|
|
// CraftBukkit start
|
2013-03-13 23:33:27 +01:00
|
|
|
if (((MinecraftServer) this.e.d()).server == null) {
|
2012-08-03 07:46:21 +02:00
|
|
|
socket.close();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
connectionThrottle = ((MinecraftServer) this.e.d()).server.getConnectionThrottle();
|
2012-08-03 07:46:21 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
synchronized (this.b) {
|
|
|
|
if (this.b.containsKey(inetaddress) && !b(inetaddress) && i - ((Long) this.b.get(inetaddress)).longValue() < connectionThrottle) {
|
|
|
|
this.b.put(inetaddress, Long.valueOf(i));
|
2012-08-03 07:06:25 +02:00
|
|
|
socket.close();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
this.b.put(inetaddress, Long.valueOf(i));
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
PendingConnection pendingconnection = new PendingConnection(this.e.d(), socket, "Connection #" + this.c++);
|
2012-08-03 07:06:25 +02:00
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
this.a(pendingconnection);
|
2012-08-03 07:06:25 +02:00
|
|
|
} catch (IOException ioexception) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.e.d().getLogger().warning("DSCT: " + ioexception.getMessage()); // CraftBukkit
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
this.e.d().getLogger().info("Closing listening thread");
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
private void a(PendingConnection pendingconnection) {
|
|
|
|
if (pendingconnection == null) {
|
2012-08-03 07:06:25 +02:00
|
|
|
throw new IllegalArgumentException("Got null pendingconnection!");
|
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
List list = this.a;
|
2012-08-03 07:06:25 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
synchronized (this.a) {
|
|
|
|
this.a.add(pendingconnection);
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean b(InetAddress inetaddress) {
|
|
|
|
return "127.0.0.1".equals(inetaddress.getHostAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(InetAddress inetaddress) {
|
|
|
|
if (inetaddress != null) {
|
2013-03-13 23:33:27 +01:00
|
|
|
HashMap hashmap = this.b;
|
2012-08-03 07:06:25 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
synchronized (this.b) {
|
|
|
|
this.b.remove(inetaddress);
|
2012-08-03 07:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b() {
|
|
|
|
try {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.d.close();
|
2012-08-03 07:06:25 +02:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|