PageRenderTime 656ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://code.google.com/p/minecraft-smp-mocreatures/
Java | 172 lines | 145 code | 18 blank | 9 comment | 14 complexity | 04839186f2b8de44221729abcdcbb769 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.Socket;
  7. import java.util.Random;
  8. import java.util.logging.Logger;
  9. import net.minecraft.server.MinecraftServer;
  10. // Referenced classes of package net.minecraft.src:
  11. // NetHandler, ChunkCoordinates, Packet70Bed, NetworkListenThread,
  12. // ThreadLoginVerifier, EntityPlayerMP, WorldServer, Packet4UpdateTime,
  13. // ServerConfigurationManager, NetServerHandler, Packet2Handshake, Packet1Login,
  14. // Packet3Chat, NetworkManager, Packet6SpawnPosition, WorldProvider,
  15. // Packet255KickDisconnect, Packet
  16. public class NetLoginHandler extends NetHandler
  17. {
  18. public NetLoginHandler(MinecraftServer minecraftserver, Socket socket, String s) throws IOException
  19. {
  20. finishedProcessing = false;
  21. loginTimer = 0;
  22. username = null;
  23. packet1login = null;
  24. serverId = "";
  25. mcServer = minecraftserver;
  26. netManager = new NetworkManager(socket, s, this);
  27. netManager.chunkDataSendCounter = 0;
  28. }
  29. public void tryLogin()
  30. {
  31. if(packet1login != null)
  32. {
  33. doLogin(packet1login);
  34. packet1login = null;
  35. }
  36. if(loginTimer++ == 600)
  37. {
  38. kickUser("Took too long to log in");
  39. } else
  40. {
  41. netManager.processReadPackets();
  42. }
  43. }
  44. public void kickUser(String s)
  45. {
  46. try
  47. {
  48. logger.info((new StringBuilder()).append("Disconnecting ").append(getUserAndIPString()).append(": ").append(s).toString());
  49. netManager.addToSendQueue(new Packet255KickDisconnect(s));
  50. netManager.serverShutdown();
  51. finishedProcessing = true;
  52. }
  53. catch(Exception exception)
  54. {
  55. exception.printStackTrace();
  56. }
  57. }
  58. public void handleHandshake(Packet2Handshake packet2handshake)
  59. {
  60. if(mcServer.onlineMode)
  61. {
  62. serverId = Long.toHexString(rand.nextLong());
  63. netManager.addToSendQueue(new Packet2Handshake(serverId));
  64. } else
  65. {
  66. netManager.addToSendQueue(new Packet2Handshake("-"));
  67. }
  68. }
  69. public void handleLogin(Packet1Login packet1login)
  70. {
  71. username = packet1login.username;
  72. if(packet1login.protocolVersion != 11)
  73. {
  74. if(packet1login.protocolVersion > 11)
  75. {
  76. kickUser("Outdated server!");
  77. } else
  78. {
  79. kickUser("Outdated client!");
  80. }
  81. return;
  82. }
  83. if(!mcServer.onlineMode)
  84. {
  85. doLogin(packet1login);
  86. } else
  87. {
  88. (new ThreadLoginVerifier(this, packet1login)).start();
  89. }
  90. }
  91. public void doLogin(Packet1Login packet1login)
  92. {
  93. EntityPlayerMP entityplayermp = mcServer.configManager.login(this, packet1login.username);
  94. if(entityplayermp != null)
  95. {
  96. logger.info((new StringBuilder()).append(getUserAndIPString()).append(" logged in with entity id ").append(entityplayermp.entityId).append(" at (").append(entityplayermp.posX).append(", ").append(entityplayermp.posY).append(", ").append(entityplayermp.posZ).append(")").toString());
  97. ChunkCoordinates chunkcoordinates = mcServer.worldMngr.getSpawnPoint();
  98. NetServerHandler netserverhandler = new NetServerHandler(mcServer, netManager, entityplayermp);
  99. netserverhandler.sendPacket(new Packet1Login("", entityplayermp.entityId, mcServer.worldMngr.getRandomSeed(), (byte)mcServer.worldMngr.worldProvider.worldType));
  100. netserverhandler.sendPacket(new Packet6SpawnPosition(chunkcoordinates.posX, chunkcoordinates.posY, chunkcoordinates.posZ));
  101. if(mcServer.worldMngr.func_27068_v())
  102. {
  103. netserverhandler.sendPacket(new Packet70Bed(1));
  104. }
  105. mcServer.configManager.sendPacketToAllPlayers(new Packet3Chat((new StringBuilder()).append("\247e").append(entityplayermp.username).append(" joined the game.").toString()));
  106. mcServer.configManager.playerLoggedIn(entityplayermp);
  107. netserverhandler.teleportTo(entityplayermp.posX, entityplayermp.posY, entityplayermp.posZ, entityplayermp.rotationYaw, entityplayermp.rotationPitch);
  108. mcServer.networkServer.addPlayer(netserverhandler);
  109. netserverhandler.sendPacket(new Packet4UpdateTime(mcServer.worldMngr.getWorldTime()));
  110. entityplayermp.func_20057_k();
  111. }
  112. finishedProcessing = true;
  113. }
  114. public void handleErrorMessage(String s, Object aobj[])
  115. {
  116. logger.info((new StringBuilder()).append(getUserAndIPString()).append(" lost connection").toString());
  117. finishedProcessing = true;
  118. }
  119. public void registerPacket(Packet packet)
  120. {
  121. kickUser("Protocol error");
  122. }
  123. public String getUserAndIPString()
  124. {
  125. if(username != null)
  126. {
  127. return (new StringBuilder()).append(username).append(" [").append(netManager.getRemoteAddress().toString()).append("]").toString();
  128. } else
  129. {
  130. return netManager.getRemoteAddress().toString();
  131. }
  132. }
  133. public boolean isServerHandler()
  134. {
  135. return true;
  136. }
  137. static String getServerId(NetLoginHandler netloginhandler)
  138. {
  139. return netloginhandler.serverId;
  140. }
  141. static Packet1Login setLoginPacket(NetLoginHandler netloginhandler, Packet1Login packet1login)
  142. {
  143. return netloginhandler.packet1login = packet1login;
  144. }
  145. public static Logger logger = Logger.getLogger("Minecraft");
  146. private static Random rand = new Random();
  147. public NetworkManager netManager;
  148. public boolean finishedProcessing;
  149. private MinecraftServer mcServer;
  150. private int loginTimer;
  151. private String username;
  152. private Packet1Login packet1login;
  153. private String serverId;
  154. }