PageRenderTime 1112ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ONetworkListenThread.java

http://github.com/traitor/Minecraft-Server-Mod
Java | 87 lines | 73 code | 12 blank | 2 comment | 6 complexity | 35eb0f6af85d51b70c8de6d416340f3b MD5 | raw file
  1. import java.io.IOException;
  2. import java.net.InetAddress;
  3. import java.net.ServerSocket;
  4. import java.util.ArrayList;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. import net.minecraft.server.MinecraftServer;
  8. public class ONetworkListenThread {
  9. public static Logger a = Logger.getLogger("Minecraft");
  10. private ServerSocket d;
  11. private Thread e;
  12. public volatile boolean b = false;
  13. private int f = 0;
  14. private ArrayList<ONetLoginHandler> g = new ArrayList<ONetLoginHandler>();
  15. private ArrayList<ONetServerHandler> h = new ArrayList<ONetServerHandler>();
  16. public MinecraftServer c;
  17. // hMod: These static methods are here because dx.java is calling them
  18. // statically... >.>
  19. static ServerSocket a(ONetworkListenThread self) {
  20. return self.d;
  21. }
  22. static int b(ONetworkListenThread self) {
  23. return self.f;
  24. }
  25. static void a(ONetworkListenThread self, ONetLoginHandler newhc) {
  26. ++self.f;
  27. self.a(newhc);
  28. }
  29. public ONetworkListenThread(MinecraftServer paramMinecraftServer, InetAddress paramInetAddress, int paramInt) {
  30. c = paramMinecraftServer;
  31. try {
  32. d = new ServerSocket(paramInt, 0, paramInetAddress);
  33. } catch (IOException ex) {
  34. Logger.getLogger(ONetworkListenThread.class.getName()).log(Level.SEVERE, null, ex);
  35. }
  36. d.setPerformancePreferences(0, 2, 1);
  37. b = true;
  38. e = new ONetworkAcceptThread(this, "Listen thread", paramMinecraftServer);
  39. e.start();
  40. }
  41. public void a(ONetServerHandler paramONetServerHandler) {
  42. h.add(paramONetServerHandler);
  43. }
  44. private void a(ONetLoginHandler paramONetLoginHandler) {
  45. if (paramONetLoginHandler == null)
  46. throw new IllegalArgumentException("Got null pendingconnection!");
  47. g.add(paramONetLoginHandler);
  48. }
  49. public void a() {
  50. ONetLoginHandler loginHandler;
  51. for (int i = 0; i < g.size(); i++) {
  52. loginHandler = g.get(i);
  53. try {
  54. loginHandler.a();
  55. } catch (Exception localException1) {
  56. loginHandler.a("Internal server error");
  57. a.log(Level.WARNING, "Failed to handle packet: " + localException1, localException1);
  58. }
  59. if (loginHandler.c)
  60. g.remove(i--);
  61. }
  62. ONetServerHandler handler;
  63. for (int i = 0; i < h.size(); i++) {
  64. handler = h.get(i);
  65. try {
  66. handler.a();
  67. } catch (Exception localException2) {
  68. a.log(Level.WARNING, "Failed to handle packet: " + localException2, localException2);
  69. handler.a("Internal server error");
  70. }
  71. if (handler.c)
  72. h.remove(i--);
  73. }
  74. }
  75. }