2025-03-11 00:23:54 +01:00
|
|
|
package game.network;
|
|
|
|
|
|
|
|
import game.Server;
|
|
|
|
import game.init.Config;
|
|
|
|
import game.packet.HPacketHandshake;
|
|
|
|
import game.packet.RPacketDisconnect;
|
|
|
|
|
2025-03-26 12:22:32 +01:00
|
|
|
public class HandshakeHandlerTCP extends HandshakeHandler
|
2025-03-11 00:23:54 +01:00
|
|
|
{
|
|
|
|
private final Server server;
|
|
|
|
private final NetConnection networkManager;
|
|
|
|
|
2025-03-26 12:22:32 +01:00
|
|
|
public HandshakeHandlerTCP(Server serverIn, NetConnection netManager)
|
2025-03-11 00:23:54 +01:00
|
|
|
{
|
|
|
|
this.server = serverIn;
|
|
|
|
this.networkManager = netManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void processHandshake(HPacketHandshake packetIn)
|
|
|
|
{
|
|
|
|
if(packetIn.getProtocolVersion() == 0) {
|
|
|
|
this.networkManager.closeChannel("Inkompatibel!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.networkManager.setConnectionState(PacketRegistry.LOGIN);
|
|
|
|
if (packetIn.getProtocolVersion() != Config.PROTOCOL)
|
|
|
|
{
|
|
|
|
String comp;
|
|
|
|
if(packetIn.getProtocolVersion() < Config.PROTOCOL)
|
|
|
|
comp = "Der Server nutzt eine neuere Version: " + Config.VERSION;
|
|
|
|
else
|
|
|
|
comp = "Der Server nutzt eine ältere Version: " + Config.VERSION;
|
|
|
|
this.networkManager.sendPacket(new RPacketDisconnect(comp));
|
|
|
|
this.networkManager.closeChannel(comp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-03-26 12:22:32 +01:00
|
|
|
this.networkManager.setNetHandler(new LoginHandler(this.server, this.networkManager));
|
2025-03-11 00:23:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|