Clean up and fix bug in NetworkAcceptThread and NetworkListenThread classes.

Signed-off-by: speakeasy <mekevin1917@gmail.com>
This commit is contained in:
speakeasy
2011-01-11 05:15:25 +08:00
committed by tahg
parent 802a46a709
commit 6a15ae252b
2 changed files with 138 additions and 0 deletions

View File

@@ -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);
}
}