70 lines
2.6 KiB
Java
Executable file
70 lines
2.6 KiB
Java
Executable file
package client.network;
|
|
|
|
import java.security.PublicKey;
|
|
|
|
import javax.crypto.SecretKey;
|
|
|
|
import client.Client;
|
|
import common.network.IClientLoginHandler;
|
|
import common.network.NetConnection;
|
|
import common.network.NetHandler;
|
|
import common.network.PacketRegistry;
|
|
import common.packet.LPacketPasswordResponse;
|
|
import common.packet.LPacketStartEncrypt;
|
|
import common.packet.RPacketDisconnect;
|
|
import common.packet.RPacketEnableCompression;
|
|
import common.packet.RPacketLoginSuccess;
|
|
import common.packet.RPacketRequestEncrypt;
|
|
import common.util.EncryptUtil;
|
|
import io.netty.util.concurrent.Future;
|
|
import io.netty.util.concurrent.GenericFutureListener;
|
|
|
|
public class ClientLoginHandler extends NetHandler implements IClientLoginHandler {
|
|
private final Client gm;
|
|
private final NetConnection networkManager;
|
|
private final String user;
|
|
private final String access;
|
|
private final String password;
|
|
|
|
public ClientLoginHandler(NetConnection conn, Client gmIn, String userIn, String accessIn, String passwordIn) {
|
|
this.networkManager = conn;
|
|
this.gm = gmIn;
|
|
this.user = userIn;
|
|
this.access = accessIn;
|
|
this.password = passwordIn;
|
|
}
|
|
|
|
public void onDisconnect(String reason)
|
|
{
|
|
this.gm.disconnected(reason);
|
|
}
|
|
|
|
public void handleDisconnect(RPacketDisconnect packetIn)
|
|
{
|
|
this.networkManager.closeChannel(packetIn.getReason());
|
|
}
|
|
|
|
public void handleEncrypt(RPacketRequestEncrypt packet) {
|
|
this.networkManager.setConnectionState(PacketRegistry.LOGIN);
|
|
final SecretKey secret = EncryptUtil.createNewSharedKey();
|
|
PublicKey pubkey = packet.getKey();
|
|
this.networkManager.sendPacket(new LPacketStartEncrypt(secret, pubkey, packet.getToken()), new GenericFutureListener < Future <? super Void >> () {
|
|
public void operationComplete(Future <? super Void > u) throws Exception {
|
|
ClientLoginHandler.this.networkManager.startEncryption(secret);
|
|
ClientLoginHandler.this.networkManager.sendPacket(new LPacketPasswordResponse(ClientLoginHandler.this.user, ClientLoginHandler.this.access, ClientLoginHandler.this.password));
|
|
}
|
|
});
|
|
}
|
|
|
|
public void handleLoginSuccess(RPacketLoginSuccess packetIn)
|
|
{
|
|
this.gm.debugWorld = packetIn.isDebug();
|
|
this.networkManager.setConnectionState(PacketRegistry.PLAY);
|
|
this.networkManager.setNetHandler(new ClientPlayer(this.gm, this.networkManager));
|
|
}
|
|
|
|
public void handleEnableCompression(RPacketEnableCompression packetIn)
|
|
{
|
|
this.networkManager.setCompressionTreshold(packetIn.getValue());
|
|
}
|
|
}
|