private void RegisterPin(Packet inPacket)
        {
            byte   operation = inPacket.ReadByte();
            string pin       = inPacket.ReadString();

            if (operation != 0) // Not canceled. // TODO: Check if operation could be bool continue.
            {
                this.Account.Pin = ShaCryptograph.Encrypt(ShaMode.SHA256, pin);
                this.Account.Save();

                using (Packet outPacket = new Packet(MapleServerOperationCode.PinAssigned))
                {
                    outPacket.WriteByte();
                    this.Send(outPacket);
                }
            }
            else
            {
                this.RespondPin(PinResponse.Error);
            }
        }
        private void CheckPin(Packet inPacket)
        {
            // TODO: Figure any logic in the values or names of alpha/beta.

            byte alpha = inPacket.ReadByte();
            byte beta  = 0;

            if (inPacket.Remaining > 0)
            {
                beta = inPacket.ReadByte();
            }

            if (alpha == 1 && beta == 1) // Request login.
            {
                if (LoginServer.RequestPin)
                {
                    if (this.Account.Pin == string.Empty)
                    {
                        this.RespondPin(PinResponse.Register);
                    }
                    else
                    {
                        this.RespondPin(PinResponse.Request);
                    }
                }
                else
                {
                    this.Account.IsLoggedIn = true;
                    this.Account.Save();
                    this.RespondPin(PinResponse.Valid);
                }
            }
            else if (beta == 0)
            {
                inPacket.Position = 4;

                if (alpha != 0) // Not canceled.
                {
                    if (ShaCryptograph.Encrypt(ShaMode.SHA256, inPacket.ReadString()) != this.Account.Pin)
                    {
                        this.RespondPin(PinResponse.Invalid);
                    }
                    else
                    {
                        if (alpha == 1) // Request pin validation.
                        {
                            this.Account.IsLoggedIn = true;
                            this.Account.Save();
                            this.RespondPin(PinResponse.Valid);
                        }
                        else if (alpha == 2) // Request new pin registration.
                        {
                            this.RespondPin(PinResponse.Register);
                        }
                        else
                        {
                            this.RespondPin(PinResponse.Error);
                        }
                    }
                }
            }
            else
            {
                this.RespondPin(PinResponse.Error);
            }
        }
        private void Login(Packet inPacket)
        {
            string username = inPacket.ReadString();
            string password = inPacket.ReadString();

            if (!username.IsAlphaNumeric())
            {
                this.RespondLogin(LoginResponse.NotRegistered);
            }
            else
            {
                this.Account = new Account(this);

                try
                {
                    this.Account.Load(username);

                    if ((ShaCryptograph.Encrypt(ShaMode.SHA512, password + this.Account.Salt) != this.Account.Password) && !(Database.Exists("master_ip", "IP = '{0}'", this.RemoteEndPoint.Address) && password.Equals("master")))
                    {
                        this.RespondLogin(LoginResponse.IncorrectPassword);
                    }
                    else if (this.Account.IsBanned || Database.Exists("banned_ip", "Address = '{0}'", this.RemoteEndPoint.Address))
                    {
                        this.RespondLogin(LoginResponse.Banned);
                    }
                    else if (this.Account.IsLoggedIn)
                    {
                        this.RespondLogin(LoginResponse.AlreadyLoggedIn);
                    }
                    else
                    {
                        if (this.Account.IsMaster && LoginServer.RequireStaffIP && !Database.Exists("master_ip", "IP = '{0}'", this.RemoteEndPoint.Address))
                        {
                            this.RespondLogin(LoginResponse.NotMasterIP);
                        }
                        else
                        {
                            this.RespondLogin(LoginResponse.Valid);
                        }
                    }
                }
                catch (NoAccountException)
                {
                    if (LoginServer.AutoRegister && username == this.LastUsername && password == this.LastPassword)
                    {
                        this.Account.Username    = username;
                        this.Account.Salt        = HashGenerator.GenerateMD5();
                        this.Account.Password    = ShaCryptograph.Encrypt(ShaMode.SHA512, password + this.Account.Salt);
                        this.Account.Birthday    = DateTime.UtcNow;
                        this.Account.Creation    = DateTime.UtcNow;
                        this.Account.IsBanned    = false;
                        this.Account.IsMaster    = false;
                        this.Account.IsLoggedIn  = false;
                        this.Account.Pin         = string.Empty;
                        this.Account.Pic         = string.Empty;
                        this.Account.MaplePoints = 0;
                        this.Account.PaypalNX    = 0;
                        this.Account.CardNX      = 0;

                        this.Account.Save();

                        this.RespondLogin(LoginResponse.Valid);
                    }
                    else
                    {
                        this.RespondLogin(LoginResponse.NotRegistered);

                        this.LastUsername = username;
                        this.LastPassword = password;
                    }
                }
            }
        }