Java 类net.minecraft.network.login.client.CPacketEncryptionResponse 实例源码

项目:Backmemed    文件:NetHandlerLoginClient.java   
public void handleEncryptionRequest(SPacketEncryptionRequest packetIn)
{
    final SecretKey secretkey = CryptManager.createNewSharedKey();
    String s = packetIn.getServerId();
    PublicKey publickey = packetIn.getPublicKey();
    String s1 = (new BigInteger(CryptManager.getServerIdHash(s, publickey, secretkey))).toString(16);

    if (this.mc.getCurrentServerData() != null && this.mc.getCurrentServerData().isOnLAN())
    {
        try
        {
            this.getSessionService().joinServer(this.mc.getSession().getProfile(), this.mc.getSession().getToken(), s1);
        }
        catch (AuthenticationException var10)
        {
            LOGGER.warn("Couldn\'t connect to auth servers but will continue to join LAN");
        }
    }
    else
    {
        try
        {
            this.getSessionService().joinServer(this.mc.getSession().getProfile(), this.mc.getSession().getToken(), s1);
        }
        catch (AuthenticationUnavailableException var7)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {new TextComponentTranslation("disconnect.loginFailedInfo.serversUnavailable", new Object[0])}));
            return;
        }
        catch (InvalidCredentialsException var8)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {new TextComponentTranslation("disconnect.loginFailedInfo.invalidSession", new Object[0])}));
            return;
        }
        catch (AuthenticationException authenticationexception)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {authenticationexception.getMessage()}));
            return;
        }
    }

    this.networkManager.sendPacket(new CPacketEncryptionResponse(secretkey, publickey, packetIn.getVerifyToken()), new GenericFutureListener < Future <? super Void >> ()
    {
        public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
        {
            NetHandlerLoginClient.this.networkManager.enableEncryption(secretkey);
        }
    }, new GenericFutureListener[0]);
}
项目:Backmemed    文件:NetHandlerLoginServer.java   
public void processEncryptionResponse(CPacketEncryptionResponse packetIn)
{
    Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet", new Object[0]);
    PrivateKey privatekey = this.server.getKeyPair().getPrivate();

    if (!Arrays.equals(this.verifyToken, packetIn.getVerifyToken(privatekey)))
    {
        throw new IllegalStateException("Invalid nonce!");
    }
    else
    {
        this.secretKey = packetIn.getSecretKey(privatekey);
        this.currentLoginState = NetHandlerLoginServer.LoginState.AUTHENTICATING;
        this.networkManager.enableEncryption(this.secretKey);
        (new Thread("User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet())
        {
            public void run()
            {
                GameProfile gameprofile = NetHandlerLoginServer.this.loginGameProfile;

                try
                {
                    String s = (new BigInteger(CryptManager.getServerIdHash("", NetHandlerLoginServer.this.server.getKeyPair().getPublic(), NetHandlerLoginServer.this.secretKey))).toString(16);
                    NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.server.getMinecraftSessionService().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s, this.func_191235_a());

                    if (NetHandlerLoginServer.this.loginGameProfile != null)
                    {
                        NetHandlerLoginServer.LOGGER.info("UUID of player {} is {}", new Object[] {NetHandlerLoginServer.this.loginGameProfile.getName(), NetHandlerLoginServer.this.loginGameProfile.getId()});
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Failed to verify username but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Failed to verify username!");
                        NetHandlerLoginServer.LOGGER.error("Username \'{}\' tried to join with an invalid session", new Object[] {gameprofile.getName()});
                    }
                }
                catch (AuthenticationUnavailableException var3)
                {
                    if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Authentication servers are down but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Authentication servers are down. Please try again later, sorry!");
                        NetHandlerLoginServer.LOGGER.error("Couldn\'t verify username because servers are unavailable");
                    }
                }
            }
            @Nullable
            private InetAddress func_191235_a()
            {
                SocketAddress socketaddress = NetHandlerLoginServer.this.networkManager.getRemoteAddress();
                return NetHandlerLoginServer.this.server.func_190518_ac() && socketaddress instanceof InetSocketAddress ? ((InetSocketAddress)socketaddress).getAddress() : null;
            }
        }).start();
    }
}
项目:CustomWorldGen    文件:NetHandlerLoginClient.java   
public void handleEncryptionRequest(SPacketEncryptionRequest packetIn)
{
    final SecretKey secretkey = CryptManager.createNewSharedKey();
    String s = packetIn.getServerId();
    PublicKey publickey = packetIn.getPublicKey();
    String s1 = (new BigInteger(CryptManager.getServerIdHash(s, publickey, secretkey))).toString(16);

    if (this.mc.getCurrentServerData() != null && this.mc.getCurrentServerData().isOnLAN())
    {
        try
        {
            this.getSessionService().joinServer(this.mc.getSession().getProfile(), this.mc.getSession().getToken(), s1);
        }
        catch (AuthenticationException var10)
        {
            LOGGER.warn("Couldn\'t connect to auth servers but will continue to join LAN");
        }
    }
    else
    {
        try
        {
            this.getSessionService().joinServer(this.mc.getSession().getProfile(), this.mc.getSession().getToken(), s1);
        }
        catch (AuthenticationUnavailableException var7)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {new TextComponentTranslation("disconnect.loginFailedInfo.serversUnavailable", new Object[0])}));
            return;
        }
        catch (InvalidCredentialsException var8)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {new TextComponentTranslation("disconnect.loginFailedInfo.invalidSession", new Object[0])}));
            return;
        }
        catch (AuthenticationException authenticationexception)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {authenticationexception.getMessage()}));
            return;
        }
    }

    this.networkManager.sendPacket(new CPacketEncryptionResponse(secretkey, publickey, packetIn.getVerifyToken()), new GenericFutureListener < Future <? super Void >> ()
    {
        public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
        {
            NetHandlerLoginClient.this.networkManager.enableEncryption(secretkey);
        }
    }, new GenericFutureListener[0]);
}
项目:CustomWorldGen    文件:NetHandlerLoginServer.java   
public void processEncryptionResponse(CPacketEncryptionResponse packetIn)
{
    Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet", new Object[0]);
    PrivateKey privatekey = this.server.getKeyPair().getPrivate();

    if (!Arrays.equals(this.verifyToken, packetIn.getVerifyToken(privatekey)))
    {
        throw new IllegalStateException("Invalid nonce!");
    }
    else
    {
        this.secretKey = packetIn.getSecretKey(privatekey);
        this.currentLoginState = NetHandlerLoginServer.LoginState.AUTHENTICATING;
        this.networkManager.enableEncryption(this.secretKey);
        (new Thread("User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet())
        {
            public void run()
            {
                GameProfile gameprofile = NetHandlerLoginServer.this.loginGameProfile;

                try
                {
                    String s = (new BigInteger(CryptManager.getServerIdHash("", NetHandlerLoginServer.this.server.getKeyPair().getPublic(), NetHandlerLoginServer.this.secretKey))).toString(16);
                    NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.server.getMinecraftSessionService().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s);

                    if (NetHandlerLoginServer.this.loginGameProfile != null)
                    {
                        NetHandlerLoginServer.LOGGER.info("UUID of player {} is {}", new Object[] {NetHandlerLoginServer.this.loginGameProfile.getName(), NetHandlerLoginServer.this.loginGameProfile.getId()});
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Failed to verify username but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Failed to verify username!");
                        NetHandlerLoginServer.LOGGER.error("Username \'{}\' tried to join with an invalid session", new Object[] {gameprofile.getName()});
                    }
                }
                catch (AuthenticationUnavailableException var3)
                {
                    if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Authentication servers are down but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Authentication servers are down. Please try again later, sorry!");
                        NetHandlerLoginServer.LOGGER.error("Couldn\'t verify username because servers are unavailable");
                    }
                }
            }
        }).start();
    }
}
项目:ExpandedRailsMod    文件:NetHandlerLoginClient.java   
public void handleEncryptionRequest(SPacketEncryptionRequest packetIn)
{
    final SecretKey secretkey = CryptManager.createNewSharedKey();
    String s = packetIn.getServerId();
    PublicKey publickey = packetIn.getPublicKey();
    String s1 = (new BigInteger(CryptManager.getServerIdHash(s, publickey, secretkey))).toString(16);

    if (this.mc.getCurrentServerData() != null && this.mc.getCurrentServerData().isOnLAN())
    {
        try
        {
            this.getSessionService().joinServer(this.mc.getSession().getProfile(), this.mc.getSession().getToken(), s1);
        }
        catch (AuthenticationException var10)
        {
            LOGGER.warn("Couldn\'t connect to auth servers but will continue to join LAN");
        }
    }
    else
    {
        try
        {
            this.getSessionService().joinServer(this.mc.getSession().getProfile(), this.mc.getSession().getToken(), s1);
        }
        catch (AuthenticationUnavailableException var7)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {new TextComponentTranslation("disconnect.loginFailedInfo.serversUnavailable", new Object[0])}));
            return;
        }
        catch (InvalidCredentialsException var8)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {new TextComponentTranslation("disconnect.loginFailedInfo.invalidSession", new Object[0])}));
            return;
        }
        catch (AuthenticationException authenticationexception)
        {
            this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new Object[] {authenticationexception.getMessage()}));
            return;
        }
    }

    this.networkManager.sendPacket(new CPacketEncryptionResponse(secretkey, publickey, packetIn.getVerifyToken()), new GenericFutureListener < Future <? super Void >> ()
    {
        public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
        {
            NetHandlerLoginClient.this.networkManager.enableEncryption(secretkey);
        }
    }, new GenericFutureListener[0]);
}
项目:Backmemed    文件:INetHandlerLoginServer.java   
void processEncryptionResponse(CPacketEncryptionResponse packetIn);
项目:CustomWorldGen    文件:INetHandlerLoginServer.java   
void processEncryptionResponse(CPacketEncryptionResponse packetIn);