示例#1
0
        private void HandleLoginPacket(string accountName, byte[] password)
        {
            //TODO: Check IP Ban

            if (string.IsNullOrEmpty(accountName))
            {
                Disconnect("Invalid account name.", Version);
                return;
            }

            byte[] hash           = LoginServer.PasswordHasher.ComputeHash(password);
            string hashedPassword = string.Empty;

            foreach (byte b in hash)
            {
                hashedPassword += b.ToString("x2");
            }

            string       sessionKey;
            AccountModel acc = LoginServerData.RetrieveAccountData(accountName, hashedPassword, out sessionKey);

            if (acc == null)
            {
                Disconnect("Account name or password is not correct.", Version);
                return;
            }

            OutputMessage message = OutputMessagePool.GetOutputMessage(this, false);

            message.AddByte((byte)ServerPacketType.MOTD);
            message.AddString(LoginServer.MOTD);

            message.AddByte((byte)ServerPacketType.SessionKey);
            message.AddString(sessionKey);

            message.AddByte((byte)ServerPacketType.CharacterList);
            message.AddByte((byte)LoginServer.GameWorlds.Count);
            foreach (GameWorldModel world in LoginServer.GameWorlds.Values)
            {
                message.AddByte(world.GameWorldId);
                message.AddString(world.GameWorldName);
                message.AddString(world.GameWorldIP);
                message.AddUInt16(world.GameWorldPort);
                message.AddByte(0);
            }

            message.AddByte((byte)acc.Characters.Count);
            foreach (AccountCharacterModel character in acc.Characters)
            {
                message.AddByte((byte)character.ServerId);
                message.AddString(character.CharacterName);
            }

            if (!acc.PremiumUntil.HasValue)
            {
                message.AddUInt16(0xFFFF);
            }
            else
            {
                TimeSpan premiumLeft = acc.PremiumUntil.Value - DateTime.Now;
                message.AddUInt16((ushort)premiumLeft.TotalDays);
            }

            message.DisconnectAfterMessage = true;
            OutputMessagePool.AddToQueue(message);
        }