summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/minecraft/server/NetworkAcceptThread.java47
-rw-r--r--src/main/java/net/minecraft/server/NetworkListenThread.java91
2 files changed, 138 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..05108d6b
--- /dev/null
+++ b/src/main/java/net/minecraft/server/NetworkAcceptThread.java
@@ -0,0 +1,47 @@
+package net.minecraft.server;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.HashMap;
+
+class NetworkAcceptThread extends Thread {
+
+ final MinecraftServer a; /* synthetic field */
+
+ final NetworkListenThread b; /* synthetic field */
+
+
+ NetworkAcceptThread(NetworkListenThread networklistenthread, String s, MinecraftServer minecraftserver) {
+ b = networklistenthread;
+ a = minecraftserver;
+ // super(s);
+ }
+
+ @Override
+ public void run() {
+ HashMap<InetAddress, Long> clients = new HashMap<InetAddress, Long>();
+ do {
+ if (!b.b) {
+ break;
+ }
+ try {
+ java.net.Socket socket = NetworkListenThread.a(b).accept();
+ if (socket != null) {
+ InetAddress addr = socket.getInetAddress();
+ if (clients.containsKey(addr)) {
+ if (System.currentTimeMillis() - clients.get(addr) < 5000) {
+ clients.put(addr, System.currentTimeMillis());
+ socket.close();
+ continue;
+ }
+ }
+ clients.put(addr, System.currentTimeMillis());
+ NetLoginHandler netloginhandler = new NetLoginHandler(a, socket, (new StringBuilder()).append("Connection #").append(NetworkListenThread.b(b)).toString());
+ NetworkListenThread.a(b, netloginhandler);
+ }
+ } catch (IOException ioexception) {
+ ioexception.printStackTrace();
+ }
+ } while (true);
+ }
+}
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..2a5e0b26
--- /dev/null
+++ b/src/main/java/net/minecraft/server/NetworkListenThread.java
@@ -0,0 +1,91 @@
+package net.minecraft.server;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class NetworkListenThread {
+
+ public static Logger a = Logger.getLogger("Minecraft");
+ private ServerSocket d;
+ private Thread e;
+ public volatile boolean b;
+ private int f;
+ private ArrayList g;
+ private ArrayList h;
+ public MinecraftServer c;
+
+ public NetworkListenThread(MinecraftServer minecraftserver, InetAddress inetaddress, int i) {
+ b = false;
+ f = 0;
+ g = new ArrayList();
+ h = new ArrayList();
+ c = minecraftserver;
+ try {
+ d = new ServerSocket(i, 20, inetaddress);
+ } catch (IOException ioexception) {
+ }
+ d.setPerformancePreferences(0, 2, 1);
+ b = true;
+ e = new NetworkAcceptThread(this, "Listen thread", minecraftserver);
+ e.start();
+ }
+
+ public void a(NetServerHandler netserverhandler) {
+ h.add(netserverhandler);
+ }
+
+ private void a(NetLoginHandler netloginhandler) {
+ if (netloginhandler == null) {
+ throw new IllegalArgumentException("Got null pendingconnection!");
+ } else {
+ g.add(netloginhandler);
+ return;
+ }
+ }
+
+ public void a() {
+ for (int i = 0; i < g.size(); i++) {
+ NetLoginHandler netloginhandler = (NetLoginHandler) g.get(i);
+ try {
+ netloginhandler.a();
+ } catch (Exception exception) {
+ netloginhandler.a("Internal server error");
+ a.log(Level.WARNING, (new StringBuilder()).append("Failed to handle packet: ").append(exception).toString(), exception);
+ }
+ if (netloginhandler.c) {
+ g.remove(i--);
+ }
+ }
+
+ for (int j = 0; j < h.size(); j++) {
+ NetServerHandler netserverhandler = (NetServerHandler) h.get(j);
+
+ try {
+ netserverhandler.a();
+ } catch (Exception exception1) {
+ a.log(Level.WARNING, (new StringBuilder()).append("Failed to handle packet: ").append(exception1).toString(), exception1);
+ netserverhandler.a("Internal server error");
+ }
+ if (netserverhandler.c) {
+ h.remove(j--);
+ }
+ }
+
+ }
+
+ static ServerSocket a(NetworkListenThread networklistenthread) {
+ return networklistenthread.d;
+ }
+
+ static int b(NetworkListenThread networklistenthread) {
+ return networklistenthread.f++;
+ }
+
+ static void a(NetworkListenThread networklistenthread, NetLoginHandler netloginhandler) {
+ networklistenthread.a(netloginhandler);
+ }
+}