/moCreatures/server/core/sources/net/minecraft/src/NetworkListenThread.java

https://code.google.com/p/minecraft-smp-mocreatures/ · Java · 116 lines · 96 code · 15 blank · 5 comment · 6 complexity · dfdb6fc1e01b4a8e7aeafce4e111e4c4 MD5 · raw file

  1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.kpdus.com/jad.html
  3. // Decompiler options: packimports(3) braces deadcode
  4. package net.minecraft.src;
  5. import java.io.IOException;
  6. import java.net.InetAddress;
  7. import java.net.ServerSocket;
  8. import java.util.ArrayList;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import net.minecraft.server.MinecraftServer;
  12. // Referenced classes of package net.minecraft.src:
  13. // NetLoginHandler, NetServerHandler, NetworkAcceptThread
  14. public class NetworkListenThread
  15. {
  16. public NetworkListenThread(MinecraftServer minecraftserver, InetAddress inetaddress, int i) throws IOException
  17. {
  18. field_973_b = false;
  19. field_977_f = 0;
  20. pendingConnections = new ArrayList();
  21. playerList = new ArrayList();
  22. mcServer = minecraftserver;
  23. serverSocket = new ServerSocket(i, 0, inetaddress);
  24. serverSocket.setPerformancePreferences(0, 2, 1);
  25. field_973_b = true;
  26. networkAcceptThread = new NetworkAcceptThread(this, "Listen thread", minecraftserver);
  27. networkAcceptThread.start();
  28. }
  29. public void addPlayer(NetServerHandler netserverhandler)
  30. {
  31. playerList.add(netserverhandler);
  32. }
  33. private void addPendingConnection(NetLoginHandler netloginhandler)
  34. {
  35. if(netloginhandler == null)
  36. {
  37. throw new IllegalArgumentException("Got null pendingconnection!");
  38. } else
  39. {
  40. pendingConnections.add(netloginhandler);
  41. return;
  42. }
  43. }
  44. public void handleNetworkListenThread()
  45. {
  46. for(int i = 0; i < pendingConnections.size(); i++)
  47. {
  48. NetLoginHandler netloginhandler = (NetLoginHandler)pendingConnections.get(i);
  49. try
  50. {
  51. netloginhandler.tryLogin();
  52. }
  53. catch(Exception exception)
  54. {
  55. netloginhandler.kickUser("Internal server error");
  56. logger.log(Level.WARNING, (new StringBuilder()).append("Failed to handle packet: ").append(exception).toString(), exception);
  57. }
  58. if(netloginhandler.finishedProcessing)
  59. {
  60. pendingConnections.remove(i--);
  61. }
  62. }
  63. for(int j = 0; j < playerList.size(); j++)
  64. {
  65. NetServerHandler netserverhandler = (NetServerHandler)playerList.get(j);
  66. try
  67. {
  68. netserverhandler.handlePackets();
  69. }
  70. catch(Exception exception1)
  71. {
  72. logger.log(Level.WARNING, (new StringBuilder()).append("Failed to handle packet: ").append(exception1).toString(), exception1);
  73. netserverhandler.kickPlayer("Internal server error");
  74. }
  75. if(netserverhandler.connectionClosed)
  76. {
  77. playerList.remove(j--);
  78. }
  79. }
  80. }
  81. static ServerSocket func_713_a(NetworkListenThread networklistenthread)
  82. {
  83. return networklistenthread.serverSocket;
  84. }
  85. static int func_712_b(NetworkListenThread networklistenthread)
  86. {
  87. return networklistenthread.field_977_f++;
  88. }
  89. static void func_716_a(NetworkListenThread networklistenthread, NetLoginHandler netloginhandler)
  90. {
  91. networklistenthread.addPendingConnection(netloginhandler);
  92. }
  93. public static Logger logger = Logger.getLogger("Minecraft");
  94. private ServerSocket serverSocket;
  95. private Thread networkAcceptThread;
  96. public volatile boolean field_973_b;
  97. private int field_977_f;
  98. private ArrayList pendingConnections;
  99. private ArrayList playerList;
  100. public MinecraftServer mcServer;
  101. }