From b416dd337f46a20aaf8ff97b22c97fe99e90e4ff Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Tue, 24 Jan 2012 17:38:47 -0500 Subject: [PATCH] Loosen throttle strictness. --- .../minecraft/server/NetworkAcceptThread.java | 46 ++++++++ .../minecraft/server/NetworkListenThread.java | 107 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/main/java/net/minecraft/server/NetworkAcceptThread.java create mode 100644 src/main/java/net/minecraft/server/NetworkListenThread.java diff --git a/src/main/java/net/minecraft/server/NetworkAcceptThread.java b/src/main/java/net/minecraft/server/NetworkAcceptThread.java new file mode 100644 index 0000000000..c702648fc6 --- /dev/null +++ b/src/main/java/net/minecraft/server/NetworkAcceptThread.java @@ -0,0 +1,46 @@ +package net.minecraft.server; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; + +class NetworkAcceptThread extends Thread { + + final MinecraftServer a; + + final NetworkListenThread b; + + NetworkAcceptThread(NetworkListenThread networklistenthread, String s, MinecraftServer minecraftserver) { + super(s); + this.b = networklistenthread; + this.a = minecraftserver; + } + + public void run() { + while (this.b.b) { + try { + Socket socket = NetworkListenThread.a(this.b).accept(); + + if (socket != null) { + synchronized (NetworkListenThread.b(this.b)) { + InetAddress inetaddress = socket.getInetAddress(); + + if (NetworkListenThread.b(this.b).containsKey(inetaddress) && System.currentTimeMillis() - ((Long) NetworkListenThread.b(this.b).get(inetaddress)).longValue() < 6000L) { // CraftBukkit + NetworkListenThread.b(this.b).put(inetaddress, Long.valueOf(System.currentTimeMillis())); + socket.close(); + continue; + } + + NetworkListenThread.b(this.b).put(inetaddress, Long.valueOf(System.currentTimeMillis())); + } + + NetLoginHandler netloginhandler = new NetLoginHandler(this.a, socket, "Connection #" + NetworkListenThread.c(this.b)); + + NetworkListenThread.a(this.b, netloginhandler); + } + } catch (IOException ioexception) { + ioexception.printStackTrace(); + } + } + } +} diff --git a/src/main/java/net/minecraft/server/NetworkListenThread.java b/src/main/java/net/minecraft/server/NetworkListenThread.java new file mode 100644 index 0000000000..0ba014208d --- /dev/null +++ b/src/main/java/net/minecraft/server/NetworkListenThread.java @@ -0,0 +1,107 @@ +package net.minecraft.server; + +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.io.IOException; // CraftBukkit + +public class NetworkListenThread { + + public static Logger a = Logger.getLogger("Minecraft"); + private ServerSocket d; + private Thread e; + public volatile boolean b = false; + private int f = 0; + private ArrayList g = new ArrayList(); + private ArrayList h = new ArrayList(); + public MinecraftServer c; + private HashMap i = new HashMap(); + + public NetworkListenThread(MinecraftServer minecraftserver, InetAddress inetaddress, int i) throws IOException { // CraftBukkit + this.c = minecraftserver; + this.d = new ServerSocket(i, 0, inetaddress); + this.d.setPerformancePreferences(0, 2, 1); + this.b = true; + this.e = new NetworkAcceptThread(this, "Listen thread", minecraftserver); + this.e.start(); + } + + public void a(Socket socket) { + InetAddress inetaddress = socket.getInetAddress(); + HashMap hashmap = this.i; + + synchronized (this.i) { + this.i.remove(inetaddress); + } + } + + public void a(NetServerHandler netserverhandler) { + this.h.add(netserverhandler); + } + + private void a(NetLoginHandler netloginhandler) { + if (netloginhandler == null) { + throw new IllegalArgumentException("Got null pendingconnection!"); + } else { + this.g.add(netloginhandler); + } + } + + public void a() { + int i; + + for (i = 0; i < this.g.size(); ++i) { + NetLoginHandler netloginhandler = (NetLoginHandler) this.g.get(i); + + try { + netloginhandler.a(); + } catch (Exception exception) { + netloginhandler.disconnect("Internal server error"); + a.log(Level.WARNING, "Failed to handle packet: " + exception, exception); + } + + if (netloginhandler.c) { + this.g.remove(i--); + } + + netloginhandler.networkManager.a(); + } + + for (i = 0; i < this.h.size(); ++i) { + NetServerHandler netserverhandler = (NetServerHandler) this.h.get(i); + + try { + netserverhandler.a(); + } catch (Exception exception1) { + a.log(Level.WARNING, "Failed to handle packet: " + exception1, exception1); + netserverhandler.disconnect("Internal server error"); + } + + if (netserverhandler.disconnected) { + this.h.remove(i--); + } + + netserverhandler.networkManager.a(); + } + } + + static ServerSocket a(NetworkListenThread networklistenthread) { + return networklistenthread.d; + } + + static HashMap b(NetworkListenThread networklistenthread) { + return networklistenthread.i; + } + + static int c(NetworkListenThread networklistenthread) { + return networklistenthread.f++; + } + + static void a(NetworkListenThread networklistenthread, NetLoginHandler netloginhandler) { + networklistenthread.a(netloginhandler); + } +}