| 1 | package net.minecraft.server.network;
|
| 2 |
|
| 3 | import net.minecraft.network.EnumConnectionState;
|
| 4 | import net.minecraft.network.NetworkManager;
|
| 5 | import net.minecraft.network.handshake.INetHandlerHandshakeServer;
|
| 6 | import net.minecraft.network.handshake.client.C00Handshake;
|
| 7 | import net.minecraft.network.login.server.S00PacketDisconnect;
|
| 8 | import net.minecraft.server.MinecraftServer;
|
| 9 | import net.minecraft.util.ChatComponentText;
|
| 10 | import net.minecraft.util.IChatComponent;
|
| 11 |
|
| 12 | public class NetHandlerHandshakeTCP implements INetHandlerHandshakeServer
|
| 13 | {
|
| 14 | private final MinecraftServer server;
|
| 15 | private final NetworkManager networkManager;
|
| 16 |
|
| 17 | public NetHandlerHandshakeTCP(MinecraftServer serverIn, NetworkManager netManager)
|
| 18 | {
|
| 19 | this.server = serverIn;
|
| 20 | this.networkManager = netManager;
|
| 21 | }
|
| 22 |
|
| 23 | /**
|
| 24 | * There are two recognized intentions for initiating a handshake: logging in and acquiring server status. The
|
| 25 | * NetworkManager's protocol will be reconfigured according to the specified intention, although a login-intention
|
| 26 | * must pass a versioncheck or receive a disconnect otherwise
|
| 27 | */
|
| 28 | public void processHandshake(C00Handshake packetIn)
|
| 29 | {
|
| 30 | switch (packetIn.getRequestedState())
|
| 31 | {
|
| 32 | case LOGIN:
|
| 33 | this.networkManager.setConnectionState(EnumConnectionState.LOGIN);
|
| 34 |
|
| 35 | if (packetIn.getProtocolVersion() > 47)
|
| 36 | {
|
| 37 | ChatComponentText chatcomponenttext = new ChatComponentText("Outdated server! I\'m still on 1.8.9");
|
| 38 | this.networkManager.sendPacket(new S00PacketDisconnect(chatcomponenttext));
|
| 39 | this.networkManager.closeChannel(chatcomponenttext);
|
| 40 | }
|
| 41 | else if (packetIn.getProtocolVersion() < 47)
|
| 42 | {
|
| 43 | ChatComponentText chatcomponenttext1 = new ChatComponentText("Outdated client! Please use 1.8.9");
|
| 44 | this.networkManager.sendPacket(new S00PacketDisconnect(chatcomponenttext1));
|
| 45 | this.networkManager.closeChannel(chatcomponenttext1);
|
| 46 | }
|
| 47 | else
|
| 48 | {
|
| 49 | this.networkManager.setNetHandler(new NetHandlerLoginServer(this.server, this.networkManager));
|
| 50 | }
|
| 51 |
|
| 52 | break;
|
| 53 |
|
| 54 | case STATUS:
|
| 55 | this.networkManager.setConnectionState(EnumConnectionState.STATUS);
|
| 56 | this.networkManager.setNetHandler(new NetHandlerStatusServer(this.server, this.networkManager));
|
| 57 | break;
|
| 58 |
|
| 59 | default:
|
| 60 | throw new UnsupportedOperationException("Invalid intention " + packetIn.getRequestedState());
|
| 61 | }
|
| 62 | }
|
| 63 |
|
| 64 | /**
|
| 65 | * Invoked when disconnecting, the parameter is a ChatComponent describing the reason for termination
|
| 66 | */
|
| 67 | public void onDisconnect(IChatComponent reason)
|
| 68 | {
|
| 69 | }
|
| 70 | }
|
| 71 |
|