Esempio n. 1
0
        public override void RunImpl()
        {
            CipherParameters key = _client.RsaPair._privateKey;
            RSAEngine        rsa = new RSAEngine();

            rsa.init(false, key);

            byte[] decrypt = rsa.processBlock(Raw, 0, 128);

            if (decrypt.Length < 128)
            {
                byte[] temp = new byte[128];
                Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length);
                decrypt = temp;
            }

            string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty);
            string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty);

            AccountModel account = AccountService.GetAccountByLogin(username);

            if (account == null)
            {
                if (Config.Config.Instance.ServerConfig.AutoCreate)
                {
                    account = AccountService.CreateAccount(username, L2Security.HashPassword(password));
                }
                else
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }
            }
            else
            {
                if (!AccountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password)))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }

                if (ServerThreadPool.Instance.LoggedAlready(username.ToLower()))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse));
                    _client.Close();
                    return;
                }
            }

            Random rnd = new Random();

            _client.ActiveAccount = account;
            _client.SetLoginPair(rnd.Next(), rnd.Next());
            _client.SetPlayPair(rnd.Next(), rnd.Next());

            _client.Send(LoginOk.ToPacket(_client));
        }
Esempio n. 2
0
        private byte[] DecryptPacket()
        {
            var key = _client.RsaPair._privateKey;
            var rsa = new RSAEngine();

            rsa.init(false, key);

            var decrypt = rsa.processBlock(Raw, 0, 128);

            if (decrypt.Length < 128)
            {
                var temp = new byte[128];
                Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length);
                return(temp);
            }

            return(decrypt);
        }
Esempio n. 3
0
        public override void run()
        {
            string username, password;

            CipherParameters key = getClient().RsaPair._privateKey;
            RSAEngine        rsa = new RSAEngine();

            rsa.init(false, key);

            byte[] decrypt = rsa.processBlock(_raw, 0, 128);

            if (decrypt.Length < 128)
            {
                byte[] temp = new byte[128];
                Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length);
                decrypt = temp;
            }

            username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", "");
            password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", "");

            AccountModel account = accountService.GetAccountByLogin(username);

            if (account == null)
            {
                if (Cfg.AUTO_ACCOUNTS)
                {
                    account = accountService.CreateAccount(username, L2Security.HashPassword(password));
                }
                else
                {
                    getClient().sendPacket(new LoginFail(getClient(), LoginFail.LoginFailReason.REASON_USER_OR_PASS_WRONG));
                    getClient().close();
                    return;
                }
            }
            else
            {
                if (!accountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password)))
                {
                    getClient().sendPacket(new LoginFail(getClient(), LoginFail.LoginFailReason.REASON_USER_OR_PASS_WRONG));
                    getClient().close();
                    return;
                }

                if (ServerThreadPool.getInstance().LoggedAlready(username.ToLower()))
                {
                    getClient().sendPacket(new LoginFail(getClient(), LoginFail.LoginFailReason.REASON_ACCOUNT_IN_USE));
                    getClient().close();
                    return;
                }
            }

            Random rnd = new Random();

            getClient().activeAccount = account;
            getClient().setLoginPair(rnd.Next(), rnd.Next());
            getClient().setPlayPair(rnd.Next(), rnd.Next());

            getClient().sendPacket(new LoginOk(getClient()));
        }
Esempio n. 4
0
        public override void RunImpl()
        {
            if (_client.State != LoginClientState.AuthedGG)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            var       key = _client.RsaPair._privateKey;
            RSAEngine rsa = new RSAEngine();

            rsa.init(false, key);

            byte[] decrypt = rsa.processBlock(Raw, 0, 128);

            if (decrypt.Length < 128)
            {
                byte[] temp = new byte[128];
                Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length);
                decrypt = temp;
            }

            string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty);
            string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty);

            AccountContract account = _accountService.GetAccountByLogin(username);

            if (account == null)
            {
                if (_config.ServerConfig.AutoCreate)
                {
                    account = _accountService.CreateAccount(username, L2Security.HashPassword(password));
                }
                else
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }
            }
            else
            {
                if (!_accountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password)))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }

                if (LoginServer.ServiceProvider.GetService <ServerThreadPool>().LoggedAlready(username.ToLower()))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse));
                    _client.Close();
                    return;
                }
            }

            _client.ActiveAccount = account;

            _client.State = LoginClientState.AuthedLogin;
            _client.Send(LoginOk.ToPacket(_client));
        }