예제 #1
0
        // TODO: Proper character deletion with all the necessary checks (cash items, guilds, etcetera).
        private void DeleteCharacter(Packet iPacket)
        {
            string pic         = iPacket.ReadString();
            int    characterID = iPacket.ReadInt();

            CharacterDeletionResult result;

            if (SHACryptograph.Encrypt(SHAMode.SHA256, pic) == this.Account.Pic || !WvsLogin.RequestPic)
            {
                //NOTE: As long as foreign keys are set to cascade, all child entries related to this CharacterID will also be deleted.
                Database.Delete("characters", "ID = {0}", characterID);

                result = CharacterDeletionResult.Valid;
            }
            else
            {
                result = CharacterDeletionResult.InvalidPic;
            }

            using (Packet oPacket = new Packet(ServerOperationCode.DeleteCharacterResult))
            {
                oPacket
                .WriteInt(characterID)
                .WriteByte((byte)result);

                this.Send(oPacket);
            }
        }
예제 #2
0
        private void CheckPin(Packet iPacket)
        {
            byte a = iPacket.ReadByte();
            byte b = iPacket.ReadByte();

            PinResult result;

            if (b == 0)
            {
                string pin = iPacket.ReadString();

                if (SHACryptograph.Encrypt(SHAMode.SHA256, pin) != this.Account.Pin)
                {
                    result = PinResult.Invalid;
                }
                else
                {
                    if (a == 1)
                    {
                        result = PinResult.Valid;
                    }
                    else if (a == 2)
                    {
                        result = PinResult.Register;
                    }
                    else
                    {
                        result = PinResult.Error;
                    }
                }
            }
            else if (b == 1)
            {
                if (string.IsNullOrEmpty(this.Account.Pin))
                {
                    result = PinResult.Register;
                }
                else
                {
                    result = PinResult.Request;
                }
            }
            else
            {
                result = PinResult.Error;
            }

            using (Packet oPacket = new Packet(ServerOperationCode.CheckPinCodeResult))
            {
                oPacket.WriteByte((byte)result);

                this.Send(oPacket);
            }
        }
예제 #3
0
        private void UpdatePin(Packet iPacket)
        {
            bool   procceed = iPacket.ReadBool();
            string pin      = iPacket.ReadString();

            if (procceed)
            {
                this.Account.Pin = SHACryptograph.Encrypt(SHAMode.SHA256, pin);

                Datum datum = new Datum("accounts");

                datum["Pin"] = this.Account.Pin;

                datum.Update("ID = {0}", this.Account.ID);

                using (Packet oPacket = new Packet(ServerOperationCode.UpdatePinCodeResult))
                {
                    oPacket.WriteByte(); // NOTE: All the other result types end up in a "trouble logging into the game" message.

                    this.Send(oPacket);
                }
            }
        }
예제 #4
0
        // TODO: Handle different scenarios (ban, quiet ban, etcetera).
        public static void HandleLoginPassword(MapleClient client, InPacket iPacket)
        {
            string username = iPacket.ReadMapleString();
            string password = iPacket.ReadMapleString();

            Account account;

            using (DatabaseQuery query = Database.Query("SELECT * FROM `accounts` WHERE `username` = @username", new MySqlParameter("username", username)))
            {
                if (!query.NextRow())
                {
                    if (MasterServer.Instance.Login.AutoRegister && username == client.LastUsername && password == client.LastPassword)
                    {
                        // TODO: Auto register.
                    }
                    else
                    {
                        LoginHandler.SendLoginResult(client, LoginResult.NotRegistered);
                    }

                    return;
                }

                account = new Account(query);
            }

            if (SHACryptograph.Encrypt(SHAMode.SHA512, password + account.Salt) != account.Password)
            {
                LoginHandler.SendLoginResult(client, LoginResult.IncorrectPassword);
            }
            else
            {
                client.Account = account;

                LoginHandler.SendLoginResult(client, LoginResult.Valid);
            }
        }
예제 #5
0
        private void SelectCharacter(Packet iPacket, bool fromViewAll = false, bool requestPic = false, bool registerPic = false)
        {
            string pic = string.Empty;

            if (requestPic)
            {
                pic = iPacket.ReadString();
            }
            else if (registerPic)
            {
                iPacket.ReadByte();
            }

            int characterID = iPacket.ReadInt();

            //if (this.IsInViewAllChar)
            //{
            //    this.WorldID = (byte)iPacket.ReadInt();
            //    this.ChannelID = 0; // TODO: Least loaded channel.
            //}

            this.MacAddresses = iPacket.ReadString().Split(new char[] { ',', ' ' });

            if (registerPic)
            {
                iPacket.ReadString();
                pic = iPacket.ReadString();

                if (string.IsNullOrEmpty(this.Account.Pic))
                {
                    this.Account.Pic = SHACryptograph.Encrypt(SHAMode.SHA256, pic);

                    Datum datum = new Datum("accounts");

                    datum["Pic"] = this.Account.Pic;

                    datum.Update("ID = {0}", this.Account.ID);
                }
            }

            if (!requestPic || SHACryptograph.Encrypt(SHAMode.SHA256, pic) == this.Account.Pic)
            {
                if (!WvsLogin.CenterConnection.Migrate(this.RemoteEndPoint.Address.ToString(), this.Account.ID, characterID))
                {
                    this.Stop();

                    return;
                }

                using (Packet oPacket = new Packet(ServerOperationCode.SelectCharacterResult))
                {
                    oPacket
                    .WriteByte()
                    .WriteByte()
                    .WriteBytes(127, 0, 0, 1)
                    .WriteUShort(WvsLogin.Worlds[this.World][this.Channel].Port)
                    .WriteInt(characterID)
                    .WriteInt()
                    .WriteByte();

                    this.Send(oPacket);
                }
            }
            else
            {
                using (Packet oPacket = new Packet(ServerOperationCode.CheckSPWResult))
                {
                    oPacket.WriteByte();

                    this.Send(oPacket);
                }
            }
        }
예제 #6
0
        private void Login(Packet iPacket)
        {
            string username = iPacket.ReadString();
            string password = iPacket.ReadString();

            if (!username.IsAlphaNumeric())
            {
                this.SendLoginResult(LoginResult.InvalidUsername);
            }
            else
            {
                this.Account = new Account(this);

                try
                {
                    this.Account.Load(username);

                    if (SHACryptograph.Encrypt(SHAMode.SHA512, password + this.Account.Salt) != this.Account.Password)
                    {
                        this.SendLoginResult(LoginResult.InvalidPassword);
                    }
                    else if (this.Account.IsBanned)
                    {
                        this.SendLoginResult(LoginResult.Banned);
                    }
                    else if (!this.Account.EULA)
                    {
                        this.SendLoginResult(LoginResult.EULA);
                    }
                    else // TODO: Add more scenarios (require master IP, check banned IP, check logged in).
                    {
                        this.SendLoginResult(LoginResult.Valid);
                    }
                }
                catch (NoAccountException)
                {
                    if (WvsLogin.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.EULA          = false;
                        this.Account.Gender        = Gender.Unset;
                        this.Account.Pin           = string.Empty;
                        this.Account.Pic           = string.Empty;
                        this.Account.IsBanned      = false;
                        this.Account.IsMaster      = false;
                        this.Account.Birthday      = DateTime.UtcNow;
                        this.Account.Creation      = DateTime.UtcNow;
                        this.Account.MaxCharacters = WvsLogin.MaxCharacters;

                        this.Account.Save();

                        this.SendLoginResult(LoginResult.Valid);
                    }
                    else
                    {
                        this.SendLoginResult(LoginResult.InvalidUsername);

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