summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvilSeph <evilseph@gmail.com>2012-01-24 17:38:47 -0500
committerEvilSeph <evilseph@gmail.com>2012-01-24 18:45:30 -0500
commitb416dd337f46a20aaf8ff97b22c97fe99e90e4ff (patch)
treecb30593dce80f662f0d1393c66fbfea32e39d3d2
parent39935eb3f28f0d7c8ac1ddccff7897fcfb988194 (diff)
downloadcraftbukkit-b416dd337f46a20aaf8ff97b22c97fe99e90e4ff.tar
craftbukkit-b416dd337f46a20aaf8ff97b22c97fe99e90e4ff.tar.gz
craftbukkit-b416dd337f46a20aaf8ff97b22c97fe99e90e4ff.tar.lz
craftbukkit-b416dd337f46a20aaf8ff97b22c97fe99e90e4ff.tar.xz
craftbukkit-b416dd337f46a20aaf8ff97b22c97fe99e90e4ff.zip
Loosen throttle strictness.
-rw-r--r--src/main/java/net/minecraft/server/NetworkAcceptThread.java46
-rw-r--r--src/main/java/net/minecraft/server/NetworkListenThread.java107
2 files changed, 153 insertions, 0 deletions
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 00000000..c702648f
--- /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 00000000..0ba01420
--- /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);
+ }
+}