· 7 years ago · Sep 27, 2018, 06:48 PM
1/* */ package net.minecraft.server;
2/* */
3/* */ import java.io.IOException;
4/* */ import java.net.InetAddress;
5/* */ import java.net.Socket;
6/* */ import java.security.KeyPair;
7/* */ import java.security.PrivateKey;
8/* */ import java.security.PublicKey;
9/* */ import java.util.Arrays;
10/* */ import java.util.Random;
11/* */ import java.util.logging.Logger;
12/* */ import javax.crypto.SecretKey;
13/* */ import org.bukkit.craftbukkit.event.CraftEventFactory;
14/* */ import org.bukkit.event.server.ServerListPingEvent;
15/* */
16/* */ public class NetLoginHandler extends NetHandler
17/* */ {
18/* */ private byte[] d;
19/* 15 */ public static Logger logger = Logger.getLogger("Minecraft");
20/* 16 */ private static Random random = new Random();
21/* */ public NetworkManager networkManager;
22/* 18 */ public boolean c = false;
23/* */ private MinecraftServer server;
24/* 20 */ private int g = 0;
25/* 21 */ private String h = null;
26/* 22 */ private volatile boolean i = false;
27/* 23 */ private String loginKey = Long.toString(random.nextLong(), 16);
28/* 24 */ private SecretKey k = null;
29/* 25 */ public String hostname = "";
30/* */
31/* */ public NetLoginHandler(MinecraftServer minecraftserver, Socket socket, String s) throws IOException {
32/* 28 */ this.server = minecraftserver;
33/* 29 */ this.networkManager = new NetworkManager(socket, s, this, minecraftserver.E().getPrivate());
34/* 30 */ this.networkManager.e = 0;
35/* */ }
36/* */
37/* */ public Socket getSocket()
38/* */ {
39/* 35 */ return this.networkManager.getSocket();
40/* */ }
41/* */
42/* */ public void c()
43/* */ {
44/* 40 */ if (this.i) {
45/* 41 */ d();
46/* */ }
47/* */
48/* 44 */ if (this.g++ == 600)
49/* 45 */ disconnect("Took too long to log in");
50/* */ else
51/* 47 */ this.networkManager.b();
52/* */ }
53/* */
54/* */ public void disconnect(String s)
55/* */ {
56/* */ try {
57/* 53 */ logger.info("Disconnecting " + getName() + ": " + s);
58/* 54 */ this.networkManager.queue(new Packet255KickDisconnect(s));
59/* 55 */ this.networkManager.d();
60/* 56 */ this.c = true;
61/* */ } catch (Exception exception) {
62/* 58 */ exception.printStackTrace();
63/* */ }
64/* */ }
65/* */
66/* */ public void a(Packet2Handshake packet2handshake)
67/* */ {
68/* 64 */ this.hostname = (packet2handshake.c + ':' + packet2handshake.d);
69/* */
70/* 66 */ this.h = packet2handshake.f();
71/* 67 */ if (!this.h.equals(StripColor.a(this.h))) {
72/* 68 */ disconnect("Invalid username!");
73/* */ } else {
74/* 70 */ PublicKey publickey = this.server.E().getPublic();
75/* */
76/* 72 */ if (packet2handshake.d() != 39) {
77/* 73 */ if (packet2handshake.d() > 39)
78/* 74 */ disconnect("Outdated server!");
79/* */ else
80/* 76 */ disconnect("Outdated client!");
81/* */ }
82/* */ else {
83/* 79 */ this.loginKey = (this.server.getOnlineMode() ? Long.toString(random.nextLong(), 16) : "-");
84/* 80 */ this.d = new byte[4];
85/* 81 */ random.nextBytes(this.d);
86/* 82 */ this.networkManager.queue(new Packet253KeyRequest(this.loginKey, publickey, this.d));
87/* */ }
88/* */ }
89/* */ }
90/* */
91/* */ public void a(Packet252KeyResponse packet252keyresponse) {
92/* 88 */ PrivateKey privatekey = this.server.E().getPrivate();
93/* */
94/* 90 */ this.k = packet252keyresponse.a(privatekey);
95/* 91 */ if (!Arrays.equals(this.d, packet252keyresponse.b(privatekey))) {
96/* 92 */ disconnect("Invalid client reply");
97/* */ }
98/* */
99/* 95 */ this.networkManager.queue(new Packet252KeyResponse());
100/* */ }
101/* */
102/* */ public void a(Packet205ClientCommand packet205clientcommand) {
103/* 99 */ if (packet205clientcommand.a == 0)
104/* 100 */ if (this.server.getOnlineMode())
105/* 101 */ new ThreadLoginVerifier(this, this.server.server).start();
106/* */ else
107/* 103 */ this.i = true;
108/* */ }
109/* */
110/* */ public void a(Packet1Login packet1login)
111/* */ {
112/* */ }
113/* */
114/* */ public void d()
115/* */ {
116/* 112 */ EntityPlayer s = this.server.getServerConfigurationManager().attemptLogin(this, this.h, this.hostname);
117/* */
118/* 114 */ if (s == null) {
119/* 115 */ return;
120/* */ }
121/* */
122/* 118 */ EntityPlayer entityplayer = this.server.getServerConfigurationManager().processLogin(s);
123/* */
124/* 120 */ if (entityplayer != null) {
125/* 121 */ this.server.getServerConfigurationManager().a(this.networkManager, entityplayer);
126/* */ }
127/* */
128/* 125 */ this.c = true;
129/* */ }
130/* */
131/* */ public void a(String s, Object[] aobject) {
132/* 129 */ logger.info(getName() + " lost connection");
133/* 130 */ this.c = true;
134/* */ }
135/* */
136/* */ public void a(Packet254GetInfo packet254getinfo) {
137/* 134 */ if (this.networkManager.getSocket() == null) return;
138/* */ try
139/* */ {
140/* 137 */ ServerListPingEvent pingEvent = CraftEventFactory.callServerListPingEvent(this.server.server, getSocket().getInetAddress(), this.server.getMotd(), this.server.getServerConfigurationManager().getPlayerCount(), this.server.getServerConfigurationManager().getMaxPlayers());
141/* 138 */ String s = pingEvent.getMotd() + "§" + this.server.getServerConfigurationManager().getPlayerCount() + "§" + pingEvent.getMaxPlayers();
142/* */
143/* 141 */ InetAddress inetaddress = null;
144/* */
145/* 143 */ if (this.networkManager.getSocket() != null) {
146/* 144 */ inetaddress = this.networkManager.getSocket().getInetAddress();
147/* */ }
148/* */
149/* 147 */ this.networkManager.queue(new Packet255KickDisconnect(s));
150/* 148 */ this.networkManager.d();
151/* 149 */ if ((inetaddress != null) && ((this.server.ac() instanceof DedicatedServerConnection))) {
152/* 150 */ ((DedicatedServerConnection)this.server.ac()).a(inetaddress);
153/* */ }
154/* */
155/* 153 */ this.c = true;
156/* */ } catch (Exception exception) {
157/* 155 */ exception.printStackTrace();
158/* */ }
159/* */ }
160/* */
161/* */ public void onUnhandledPacket(Packet packet) {
162/* 160 */ disconnect("Protocol error");
163/* */ }
164/* */
165/* */ public String getName() {
166/* 164 */ return this.h != null ? this.h + " [" + this.networkManager.getSocketAddress().toString() + "]" : this.networkManager.getSocketAddress().toString();
167/* */ }
168/* */
169/* */ public boolean a() {
170/* 168 */ return true;
171/* */ }
172/* */
173/* */ static String a(NetLoginHandler netloginhandler) {
174/* 172 */ return netloginhandler.loginKey;
175/* */ }
176/* */
177/* */ static MinecraftServer b(NetLoginHandler netloginhandler) {
178/* 176 */ return netloginhandler.server;
179/* */ }
180/* */
181/* */ static SecretKey c(NetLoginHandler netloginhandler) {
182/* 180 */ return netloginhandler.k;
183/* */ }
184/* */
185/* */ static String d(NetLoginHandler netloginhandler) {
186/* 184 */ return netloginhandler.h;
187/* */ }
188/* */
189/* */ static boolean a(NetLoginHandler netloginhandler, boolean flag) {
190/* 188 */ return netloginhandler.i = flag;
191/* */ }
192/* */ }
193
194/* Location: D:\Dean\Desktop\craftbukkit-1.3.1-R2.0.jar
195 * Qualified Name: net.minecraft.server.NetLoginHandler
196 * JD-Core Version: 0.6.0
197 */