Beispiel #1
0
        public bool GetBit()
        {
            if (Position == 8)
            {
                Value    = reader.Read <byte>();
                Position = 0;
            }

            int returnValue = Value;

            Value = (byte)(2 * returnValue);
            ++Position;

            return(Convert.ToBoolean(returnValue >> 7));
        }
Beispiel #2
0
        public static void ReadAddonData(byte[] buffer, int size, WorldClass session)
        {
            // Clean possible addon data
            session.Addons.Clear();

            string addonName;
            byte addonEnabled;
            uint addonCRC, UrlStringCRC;

            // Decompress received Addon Data
            PacketReader addonData = new PacketReader(ZLib.ZLibDecompress(buffer, true, size), false);

            // Get Addon number
            int ctr, numAddons = addonData.Read<int>();

            // For each addon, read data from decoded packet and store into session for later use if needed
            for (ctr = 0; ctr < numAddons; ctr++)
            {
                addonName       = addonData.ReadCString();
                addonEnabled    = addonData.Read<byte>();
                addonCRC        = addonData.Read<uint>();
                UrlStringCRC    = addonData.Read<uint>();

                // Get the addon with same properties
                var Addon = AddonMgr.GetAddon(addonName, addonEnabled, addonCRC, UrlStringCRC);

                // Add if found, add default one if not.
                if (Addon != null)
                    session.Addons.Add(Addon);
                else
                    // Note: This can be skipped for those with no addon data.
                    // TODO: Test that!
                    session.Addons.Add(new Framework.ObjectDefines.Addon()
                    {
                        AuthType        = 2,
                        Enabled         = addonEnabled,
                        CRC             = addonCRC,
                        HasPUBData      = 0,
                        PUBData         = null,
                        Version         = 1, // Fixed value
                        HasUrlString    = 0,
                        UrlString       = addonName,
                        UrlStringCRC    = UrlStringCRC
                    });
            }

            int addonEnd = addonData.Read<int>(); // Unknown
        }
        public static void HandleCliSetSpecialization(ref PacketReader packet, ref WorldClass session)
        {
            var pChar = session.Character;

            uint specGroupId = packet.Read<uint>();

            uint specId = SpecializationMgr.GetSpecIdByGroup(pChar, (byte)specGroupId);

            // check if new spec is primary or secondary
            if (pChar.SpecGroupCount == 1 && pChar.PrimarySpec == 0)
            {
                pChar.ActiveSpecGroup = 0;
                pChar.PrimarySpec = (ushort)specId;
            }
            else
            {
                pChar.ActiveSpecGroup = 1;
                pChar.SecondarySpec = (ushort)specId;
                pChar.SpecGroupCount = (byte)(pChar.SpecGroupCount + 1);
            }

            SpecializationMgr.SaveSpecInfo(pChar);

            SendSpecializationSpells(ref session);
            HandleUpdateTalentData(ref session);

            pChar.SetUpdateField<Int32>((int)PlayerFields.CurrentSpecID, (int)pChar.GetActiveSpecId());
            ObjectHandler.HandleUpdateObjectValues(ref session);

            Log.Message(LogType.Debug, "Character (Guid: {0}) choosed specialization {1} for spec group {2}.", pChar.Guid, pChar.GetActiveSpecId(), pChar.ActiveSpecGroup);
        }
        public static void HandleLearnTalents(ref PacketReader packet, ref WorldClass session)
        {
            var pChar = session.Character;
            var talentSpells = new List<uint>();

            BitUnpack BitUnpack = new BitUnpack(packet);

            uint talentCount = BitUnpack.GetBits<uint>(23);

            for (int i = 0; i < talentCount; i++)
            {
                var talentId = packet.Read<ushort>();

                SpecializationMgr.AddTalent(pChar, pChar.ActiveSpecGroup, talentId, true);

                talentSpells.Add(CliDB.Talent.Single(talent => talent.Id == talentId).SpellId);
            }

            HandleUpdateTalentData(ref session);

            pChar.SetUpdateField<Int32>((int)PlayerFields.SpellCritPercentage + 0, SpecializationMgr.GetUnspentTalentRowCount(pChar), 0);
            ObjectHandler.HandleUpdateObjectValues(ref session);

            foreach (var talentSpell in talentSpells)
                SpellHandler.HandleLearnedSpells(ref session, new List<uint>(1) { talentSpell });

            Log.Message(LogType.Debug, "Character (Guid: {0}) learned {1} talents.", pChar.Guid, talentCount);
        }
Beispiel #5
0
        public static void HandleLoadingScreenNotify(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            uint mapId = packet.Read<uint>();
            bool loadingScreenState = BitUnpack.GetBit();

            Log.Message(LogType.Debug, "Loading screen for map '{0}' is {1}.", mapId, loadingScreenState ? "enabled" : "disabled");
        }
Beispiel #6
0
        public static void HandleDisconnectReason(ref PacketReader packet, WorldClass session)
        {
            var pChar = session.Character;
            uint disconnectReason = packet.Read<uint>();

            if (pChar != null)
                WorldMgr.DeleteSession(pChar.Guid);

            DB.Realms.Execute("UPDATE accounts SET online = 0 WHERE id = ?", session.Account.Id);

            Log.Message(LogType.Debug, "Account with Id {0} disconnected. Reason: {1}", session.Account.Id, disconnectReason);
        }
Beispiel #7
0
        public static void HandleChatMessageYell(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            var language = packet.Read<int>();

            var messageLength = packet.ReadByte();
            var message = packet.ReadString(messageLength);

            ChatMessageValues chatMessage = new ChatMessageValues(MessageType.ChatMessageYell, message, true, true);
            chatMessage.Language = (byte)language;

            SendMessage(ref session, chatMessage);
        }
Beispiel #8
0
        public static void HandleChatMessageSay(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            var language = packet.Read<int>();

            var messageLength = BitUnpack.GetBits<byte>(8);
            var message = packet.ReadString(messageLength);

            ChatMessageValues chatMessage = new ChatMessageValues(MessageType.ChatMessageSay, message, true, true);
            chatMessage.Language = (byte)language;

            if (ChatCommandParser.CheckForCommand(message))
                ChatCommandParser.ExecuteChatHandler(message, session);
            else
                SendMessage(ref session, chatMessage);
        }
        public static void HandleCharDelete(ref PacketReader packet, ref WorldClass session)
        {
            bool[] guidMask = new bool[8];
            byte[] guidBytes = new byte[8];

            BitUnpack BitUnpack = new BitUnpack(packet);

            guidMask[2] = BitUnpack.GetBit();
            guidMask[1] = BitUnpack.GetBit();
            guidMask[5] = BitUnpack.GetBit();
            guidMask[7] = BitUnpack.GetBit();
            guidMask[6] = BitUnpack.GetBit();

            var unknown = BitUnpack.GetBit();

            guidMask[3] = BitUnpack.GetBit();
            guidMask[0] = BitUnpack.GetBit();
            guidMask[4] = BitUnpack.GetBit();

            if (guidMask[1]) guidBytes[1] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[3]) guidBytes[3] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[4]) guidBytes[4] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[0]) guidBytes[0] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[7]) guidBytes[7] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[2]) guidBytes[2] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[5]) guidBytes[5] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[6]) guidBytes[6] = (byte)(packet.Read<byte>() ^ 1);

            var guid = BitConverter.ToUInt64(guidBytes, 0);

            PacketWriter deleteChar = new PacketWriter(ServerMessage.DeleteChar);

            deleteChar.WriteUInt8(0x47);

            session.Send(ref deleteChar);

            DB.Characters.Execute("DELETE FROM characters WHERE guid = ?", guid);
            DB.Characters.Execute("DELETE FROM character_spells WHERE guid = ?", guid);
            DB.Characters.Execute("DELETE FROM character_skills WHERE guid = ?", guid);
        }
Beispiel #10
0
        public static void HandleRealmSplit(ref PacketReader packet, ref WorldClass session)
        {
            uint realmSplitState = 0;
            var date = "01/01/01";

            PacketWriter realmSplit = new PacketWriter(ServerMessage.RealmSplit);
            BitPack BitPack = new BitPack(realmSplit);

            BitPack.Write(date.Length, 7);
            realmSplit.WriteString(date);

            realmSplit.WriteUInt32(packet.Read<uint>());
            realmSplit.WriteUInt32(realmSplitState);

            session.Send(ref realmSplit);

            // Crash!!!
            // Wrong data sent...
            // AddonMgr.WriteAddonData(ref session);
        }
Beispiel #11
0
        public static void HandleRealmSplit(ref PacketReader packet, WorldClass session)
        {
            uint realmSplitState = 0;
            var date = "01/01/01";

            PacketWriter realmSplit = new PacketWriter(ServerMessage.RealmSplit);
            BitPack BitPack = new BitPack(realmSplit);

            realmSplit.WriteUInt32(packet.Read<uint>());
            realmSplit.WriteUInt32(realmSplitState);

            BitPack.Write(date.Length, 7);

            BitPack.Flush();

            realmSplit.WriteString(date);

            session.Send(ref realmSplit);

            AddonHandler.WriteAddonData(session);
        }
Beispiel #12
0
        public static void HandleChatMessageWhisper(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            var language = packet.Read<int>();

            var nameLength = BitUnpack.GetBits<byte>(9);
            var messageLength = BitUnpack.GetBits<byte>(8);

            string receiverName = packet.ReadString(nameLength);
            string message = packet.ReadString(messageLength);

            WorldClass rSession = WorldMgr.GetSession(receiverName);

            if (rSession == null)
                return;

            ChatMessageValues chatMessage = new ChatMessageValues(MessageType.ChatMessageWhisperInform, message, false, true);
            SendMessage(ref session, chatMessage, rSession);

            chatMessage = new ChatMessageValues(MessageType.ChatMessageWhisper, message, false, true);
            SendMessage(ref rSession, chatMessage, session);
        }
Beispiel #13
0
        public static void HandleQueryCreature(ref PacketReader packet, ref WorldClass session)
        {
            var hasData = false;
            var id = packet.Read<int>();

            PacketWriter queryCreatureResponse = new PacketWriter(ServerMessage.QueryCreatureResponse);
            BitPack BitPack = new BitPack(queryCreatureResponse);

            queryCreatureResponse.WriteInt32(id);

            Creature creature = DataMgr.FindCreature(id);
            if (hasData = (creature != null))
            {
                CreatureStats stats = creature.Stats;

                BitPack.Write(hasData);
                BitPack.Write(stats.QuestItemId.Count, 22);
                BitPack.Write(0, 11);
                BitPack.Write(stats.RacialLeader);
                BitPack.Write(stats.IconName.Length + 1, 6);

                for (int i = 0; i < 8; i++)
                {
                    if (i == 1)
                        BitPack.Write(stats.Name.Length + 1, 11);
                    else
                        BitPack.Write(0, 11);
                }

                BitPack.Write(stats.SubName.Length != 0 ? stats.SubName.Length + 1 : 0, 11);
                BitPack.Flush();

                queryCreatureResponse.WriteInt32(stats.Rank);
                queryCreatureResponse.WriteInt32(stats.DisplayInfoId[2]);
                queryCreatureResponse.WriteInt32(stats.Type);

                foreach (var v in stats.Flag)
                    queryCreatureResponse.WriteInt32(v);

                queryCreatureResponse.WriteFloat(stats.PowerModifier);
                queryCreatureResponse.WriteInt32(stats.DisplayInfoId[0]);
                queryCreatureResponse.WriteFloat(1);

                queryCreatureResponse.WriteCString(stats.Name);

                if (stats.IconName != "")
                    queryCreatureResponse.WriteCString(stats.IconName);

                queryCreatureResponse.WriteInt32(stats.Family);
                queryCreatureResponse.WriteInt32(stats.QuestKillNpcId[0]);

                if (stats.SubName != "")
                    queryCreatureResponse.WriteCString(stats.SubName);

                queryCreatureResponse.WriteInt32(stats.MovementInfoId);
                queryCreatureResponse.WriteInt32(stats.DisplayInfoId[1]);
                queryCreatureResponse.WriteFloat(1);
                queryCreatureResponse.WriteFloat(stats.HealthModifier);
                queryCreatureResponse.WriteInt32(0);

                foreach (var v in stats.QuestItemId)
                    queryCreatureResponse.WriteInt32(v);

                queryCreatureResponse.WriteInt32(stats.DisplayInfoId[3]);
                queryCreatureResponse.WriteInt32(stats.QuestKillNpcId[1]);
                queryCreatureResponse.WriteInt32(stats.ExpansionRequired);

                session.Send(ref queryCreatureResponse);
            }
            else
            {
                BitPack.Write(hasData);
                Log.Message(LogType.DEBUG, "Creature (Id: {0}) not found.", id);
            }
        }
Beispiel #14
0
        public static void HandleDBQueryBulk(ref PacketReader packet, ref WorldClass session)
        {
            List<int> IdList = new List<int>();
            BitUnpack BitUnpack = new BitUnpack(packet);

            var type = (DBTypes)packet.Read<uint>();

            var count = BitUnpack.GetBits<uint>(21);

            bool[][] Mask = new bool[count][];
            byte[][] Bytes = new byte[count][];

            for (int i = 0; i < count; i++)
            {
                Mask[i] = new bool[8];
                Bytes[i] = new byte[8];
            }

            for (int i = 0; i < count; i++)
            {
                Mask[i][7] = BitUnpack.GetBit();
                Mask[i][2] = BitUnpack.GetBit();
                Mask[i][3] = BitUnpack.GetBit();
                Mask[i][5] = BitUnpack.GetBit();
                Mask[i][4] = BitUnpack.GetBit();
                Mask[i][6] = BitUnpack.GetBit();
                Mask[i][0] = BitUnpack.GetBit();
                Mask[i][1] = BitUnpack.GetBit();
            }

            for (int i = 0; i < count; i++)
            {
                if (Mask[i][5])
                    Bytes[i][5] = (byte)(packet.Read<byte>() ^ 1);

                IdList.Add(packet.Read<int>());

                if (Mask[i][7])
                    Bytes[i][7] = (byte)(packet.ReadByte() ^ 1);

                if (Mask[i][3])
                    Bytes[i][3] = (byte)(packet.ReadByte() ^ 1);

                if (Mask[i][0])
                    Bytes[i][0] = (byte)(packet.ReadByte() ^ 1);

                if (Mask[i][1])
                    Bytes[i][1] = (byte)(packet.ReadByte() ^ 1);

                if (Mask[i][6])
                    Bytes[i][6] = (byte)(packet.ReadByte() ^ 1);

                if (Mask[i][2])
                    Bytes[i][2] = (byte)(packet.ReadByte() ^ 1);

                if (Mask[i][4])
                    Bytes[i][4] = (byte)(packet.ReadByte() ^ 1);
            }

            switch (type)
            {
                case DBTypes.BroadcastText:
                {
                    foreach (var id in IdList)
                        HandleBroadcastText(ref session, id);

                    break;
                }
                default:
                    break;
            }
        }
Beispiel #15
0
        public static void HandleMoveSetFly(ref PacketReader packet, WorldClass session)
        {
            ObjectMovementValues movementValues = new ObjectMovementValues();
            BitUnpack BitUnpack = new BitUnpack(packet);

            var guidMask = new bool[8];
            var guidBytes = new byte[8];

            Vector4 vector = new Vector4()
            {
                Y = packet.Read<float>(),
                X = packet.Read<float>(),
                Z = packet.Read<float>(),
            };

            movementValues.IsFallingOrJumping = BitUnpack.GetBit();

            guidMask[0] = BitUnpack.GetBit();

            movementValues.HasMovementFlags2 = !BitUnpack.GetBit();

            guidMask[6] = BitUnpack.GetBit();

            movementValues.HasMovementFlags = !BitUnpack.GetBit();

            var Unknown = BitUnpack.GetBit();

            guidMask[2] = BitUnpack.GetBit();

            movementValues.HasRotation = !BitUnpack.GetBit();

            var Unknown2 = !BitUnpack.GetBit();

            var HasSplineElevation = !BitUnpack.GetBit();

            movementValues.IsTransport = BitUnpack.GetBit();

            guidMask[1] = BitUnpack.GetBit();

            guidMask[5] = BitUnpack.GetBit();

            var HasPitch = !BitUnpack.GetBit();

            var Unknown4 = BitUnpack.GetBit();

            guidMask[4] = BitUnpack.GetBit();

            var HasTime = !BitUnpack.GetBit();

            var counter = BitUnpack.GetBits<uint>(22);

            var Unknown3 = BitUnpack.GetBit();

            guidMask[7] = BitUnpack.GetBit();

            guidMask[3] = BitUnpack.GetBit();

            if (movementValues.IsFallingOrJumping)
                movementValues.HasJumpData = BitUnpack.GetBit();

            if (movementValues.HasMovementFlags)
                movementValues.MovementFlags = (MovementFlag)BitUnpack.GetBits<uint>(30);

            if (movementValues.HasMovementFlags2)
                movementValues.MovementFlags2 = (MovementFlag2)BitUnpack.GetBits<uint>(13);

            for (int i = 0; i < counter; i++)
                packet.Read<uint>();

            if (guidMask[4])
                guidBytes[4] = (byte)(packet.Read<byte>() ^ 1);

            if (guidMask[2])
                guidBytes[2] = (byte)(packet.Read<byte>() ^ 1);

            if (guidMask[6])
                guidBytes[6] = (byte)(packet.Read<byte>() ^ 1);

            if (guidMask[3])
                guidBytes[3] = (byte)(packet.Read<byte>() ^ 1);

            if (guidMask[0])
                guidBytes[0] = (byte)(packet.Read<byte>() ^ 1);

            if (guidMask[7])
                guidBytes[7] = (byte)(packet.Read<byte>() ^ 1);

            if (guidMask[1])
                guidBytes[1] = (byte)(packet.Read<byte>() ^ 1);

            if (guidMask[5])
                guidBytes[5] = (byte)(packet.Read<byte>() ^ 1);

            if (Unknown2)
                packet.Read<uint>();

            if (movementValues.IsFallingOrJumping)
            {
                if (movementValues.HasJumpData)
                {
                    movementValues.Sin = packet.Read<float>();
                    movementValues.CurrentSpeed = packet.Read<float>();
                    movementValues.Cos = packet.Read<float>();
                }

                movementValues.FallTime = packet.Read<uint>();
                movementValues.JumpVelocity = packet.Read<float>();
            }

            if (HasSplineElevation)
                packet.Read<float>();

            if (movementValues.HasRotation)
                vector.O = packet.Read<float>();

            if (HasTime)
                movementValues.Time = packet.Read<uint>();

            if (HasPitch)
                packet.Read<float>();

            var guid = BitConverter.ToUInt64(guidBytes, 0);
            HandleMoveUpdate(guid, movementValues, vector);
        }
Beispiel #16
0
        public static void HandleQueryPlayerName(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            var guidMask = new bool[8];
            var guidBytes = new byte[8];

            guidMask[1] = BitUnpack.GetBit();
            guidMask[3] = BitUnpack.GetBit();
            guidMask[6] = BitUnpack.GetBit();
            guidMask[7] = BitUnpack.GetBit();
            guidMask[2] = BitUnpack.GetBit();
            guidMask[5] = BitUnpack.GetBit();

            var hasUnknown = BitUnpack.GetBit();

            guidMask[0] = BitUnpack.GetBit();

            var hasUnknown2 = BitUnpack.GetBit();

            guidMask[4] = BitUnpack.GetBit();

            if (guidMask[4]) guidBytes[4] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[6]) guidBytes[6] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[7]) guidBytes[7] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[1]) guidBytes[1] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[2]) guidBytes[2] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[5]) guidBytes[5] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[0]) guidBytes[0] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[3]) guidBytes[3] = (byte)(packet.Read<byte>() ^ 1);

            if (hasUnknown)
                packet.Read<uint>();

            if (hasUnknown2)
                packet.Read<uint>();

            var guid = BitConverter.ToUInt64(guidBytes, 0);

            var pSession = WorldMgr.GetSession(guid);
            if (pSession != null)
            {
                var pChar = pSession.Character;

                if (pChar != null)
                {
                    PacketWriter queryPlayerNameResponse = new PacketWriter(ServerMessage.QueryPlayerNameResponse);
                    BitPack BitPack = new BitPack(queryPlayerNameResponse, guid);

                    BitPack.WriteGuidMask(3, 2, 6, 0, 4, 1, 5, 7);

                    BitPack.Flush();

                    BitPack.WriteGuidBytes(7, 1, 2, 6, 3, 5);

                    queryPlayerNameResponse.WriteUInt8(0);
                    queryPlayerNameResponse.WriteUInt8(pChar.Gender);
                    queryPlayerNameResponse.WriteUInt8(pChar.Class);
                    queryPlayerNameResponse.WriteUInt8(pChar.Level);
                    queryPlayerNameResponse.WriteUInt32(1);
                    queryPlayerNameResponse.WriteUInt8(pChar.Race);
                    queryPlayerNameResponse.WriteUInt32(0);

                    BitPack.WriteGuidBytes(4, 0);

                    BitPack.WriteGuidMask(5);
                    BitPack.Write(0);
                    BitPack.Write(0);
                    BitPack.Write(0);
                    BitPack.WriteGuidMask(3, 7, 0, 6);
                    BitPack.Write(0);
                    BitPack.Write(0);
                    BitPack.WriteGuidMask(1);
                    BitPack.Write(0);

                    for (int i = 0; i < 5; i++)
                        BitPack.Write(0, 7);

                    BitPack.WriteGuidMask(2);
                    BitPack.Write(0);
                    BitPack.WriteGuidMask(4);
                    BitPack.Write(0);
                    BitPack.Write(pChar.Name.Length, 6);
                    BitPack.Write(0);

                    BitPack.Flush();

                    BitPack.WriteGuidBytes(0, 7, 5, 2);

                    queryPlayerNameResponse.WriteString(pChar.Name);

                    BitPack.WriteGuidBytes(4, 1, 3, 6);

                    session.Send(ref queryPlayerNameResponse);
                }
            }
        }
        public static void HandleAuthResponse(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            ushort  skipBytes;
            uint[]  UnknownInt = new uint[5];
            ushort  clientBuild;
            byte[]  authChallenge = new byte[20];
            byte[]  UnknownByte = new byte[2];
            ulong   unknownLong;
            int     addonPackedSize;
            int     addonUnpackedSize;

            skipBytes           = packet.Read<ushort>();

            UnknownInt[4]       = packet.Read<uint>();

            authChallenge[14]   = packet.Read<byte>();
            authChallenge[8]    = packet.Read<byte>();

            UnknownInt[0]       = packet.Read<uint>();

            authChallenge[10]   = packet.Read<byte>();
            authChallenge[19]   = packet.Read<byte>();
            authChallenge[16]   = packet.Read<byte>();
            authChallenge[13]   = packet.Read<byte>();
            authChallenge[4]    = packet.Read<byte>();

            UnknownByte[1]      = packet.Read<byte>();

            authChallenge[9]    = packet.Read<byte>();
            authChallenge[0]    = packet.Read<byte>();

            UnknownInt[2]       = packet.Read<uint>();

            authChallenge[5]    = packet.Read<byte>();
            authChallenge[2]    = packet.Read<byte>();

            clientBuild         = packet.Read<ushort>();

            authChallenge[12]   = packet.Read<byte>();

            UnknownInt[3]       = packet.Read<uint>();

            authChallenge[18]   = packet.Read<byte>();
            authChallenge[17]   = packet.Read<byte>();
            authChallenge[11]   = packet.Read<byte>();

            unknownLong         = packet.Read<ulong>();

            authChallenge[7]    = packet.Read<byte>();
            authChallenge[1]    = packet.Read<byte>();
            authChallenge[3]    = packet.Read<byte>();

            UnknownByte[0]      = packet.Read<byte>();

            authChallenge[6]    = packet.Read<byte>();

            UnknownInt[1]       = packet.Read<uint>();

            authChallenge[15]   = packet.Read<byte>();

            addonPackedSize     = packet.Read<int>();
            addonUnpackedSize   = packet.Read<int>();

            byte[] packedAddon  = packet.ReadBytes(addonPackedSize - 4);
            AddonHandler.ReadAddonData(packedAddon, addonUnpackedSize, session);

            uint nameLength = BitUnpack.GetBits<uint>(11);
            bool aBit = BitUnpack.GetBit();

            // BitUnpack.Flush();

            string accountName = packet.ReadString(nameLength);

            SQLResult result = DB.Realms.Select("SELECT * FROM accounts WHERE name = ?", accountName);
            if (result.Count == 0)
                session.clientSocket.Close();
            else
                session.Account = new Account()
                {
                    Id         = result.Read<int>(0, "id"),
                    Name       = result.Read<string>(0, "name"),
                    Password   = result.Read<string>(0, "password"),
                    SessionKey = result.Read<string>(0, "sessionkey"),
                    Expansion  = result.Read<byte>(0, "expansion"),
                    GMLevel    = result.Read<byte>(0, "gmlevel"),
                    IP         = result.Read<string>(0, "ip"),
                    Language   = result.Read<string>(0, "language")
                };

            string K = session.Account.SessionKey;
            byte[] kBytes = new byte[K.Length / 2];

            for (int i = 0; i < K.Length; i += 2)
                kBytes[i / 2] = Convert.ToByte(K.Substring(i, 2), 16);

            session.Crypt.Initialize(kBytes);

            uint realmId = WorldConfig.RealmId;
            SQLResult realmClassResult = DB.Realms.Select("SELECT class, expansion FROM realm_classes WHERE realmId = ?", realmId);
            SQLResult realmRaceResult = DB.Realms.Select("SELECT race, expansion FROM realm_races WHERE realmId = ?", realmId);

            var HasAccountData = true;
            var IsInQueue = false;

            PacketWriter authResponse = new PacketWriter(ServerMessage.AuthResponse);
            BitPack BitPack = new BitPack(authResponse);

            authResponse.WriteUInt8((byte)AuthCodes.AUTH_OK);

            BitPack.Write(IsInQueue);

            if (IsInQueue)
                BitPack.Write(1);                                  // Unknown

            BitPack.Write(HasAccountData);

            if (HasAccountData)
            {
                BitPack.Write(0);
                BitPack.Write(0, 21);
                BitPack.Write(0, 21);
                BitPack.Write(realmRaceResult.Count, 23);
                BitPack.Write(0);
                BitPack.Write(0);
                BitPack.Write(0);
                BitPack.Write(realmClassResult.Count, 23);
            }

            BitPack.Flush();

            if (HasAccountData)
            {
                authResponse.WriteUInt32(0);
                authResponse.WriteUInt32(0);
                authResponse.WriteUInt8(session.Account.Expansion);

                for (int r = 0; r < realmRaceResult.Count; r++)
                {
                    authResponse.WriteUInt8(realmRaceResult.Read<byte>(r, "expansion"));
                    authResponse.WriteUInt8(realmRaceResult.Read<byte>(r, "race"));

                }

                authResponse.WriteUInt8(session.Account.Expansion);
                authResponse.WriteUInt32(0);

                for (int c = 0; c < realmClassResult.Count; c++)
                {
                    authResponse.WriteUInt8(realmClassResult.Read<byte>(c, "class"));
                    authResponse.WriteUInt8(realmClassResult.Read<byte>(c, "expansion"));
                }

                authResponse.WriteUInt32(0);
                authResponse.WriteUInt32(0);
            }

            if (IsInQueue)
                authResponse.WriteUInt32(0);

            session.Send(ref authResponse);

            MiscHandler.HandleCacheVersion(ref session);
            TutorialHandler.HandleTutorialFlags(ref session);
        }
Beispiel #18
0
        void HandleRealmData(byte[] data)
        {
            using (var reader = new PacketReader(data, false))
            {
                ClientLink cmd = (ClientLink)reader.Read<byte>();

                switch (cmd)
                {
                    case ClientLink.CMD_AUTH_LOGON_CHALLENGE:
                    case ClientLink.CMD_AUTH_RECONNECT_CHALLENGE:
                        HandleAuthLogonChallenge(reader);
                        break;
                    case ClientLink.CMD_AUTH_LOGON_PROOF:
                    case ClientLink.CMD_AUTH_RECONNECT_PROOF:
                        HandleAuthLogonProof(reader);
                        break;
                    case ClientLink.CMD_REALM_LIST:
                        HandleRealmList(reader);
                        break;
                    default:
                        Log.Message(LogType.NORMAL, "Received unknown ClientLink: {0}", cmd);
                        break;
                }
            }
        }
Beispiel #19
0
        public static void HandleQueryRealmName(ref PacketReader packet, ref WorldClass session)
        {
            Character pChar = session.Character;

            uint realmId = packet.Read<uint>();

            SQLResult result = DB.Realms.Select("SELECT name FROM realms WHERE id = ?", WorldConfig.RealmId);
            string realmName = result.Read<string>(0, "Name");

            PacketWriter realmQueryResponse = new PacketWriter(ServerMessage.RealmQueryResponse);
            BitPack BitPack = new BitPack(realmQueryResponse);

            realmQueryResponse.WriteUInt8(0);
            realmQueryResponse.WriteUInt32(realmId);       // <= 0 => End of packet

            BitPack.Write(realmName.Length, 8);
            BitPack.Write(realmName.Length, 8);
            BitPack.Write(1);

            BitPack.Flush();

            realmQueryResponse.WriteString(realmName);
            realmQueryResponse.WriteString(realmName);

            session.Send(ref realmQueryResponse);
        }
Beispiel #20
0
        public static void HandleSetActionButton(ref PacketReader packet, WorldClass session)
        {
            var pChar = session.Character;

            byte[] actionMask = { 5, 0, 3, 1, 4, 7, 6, 2 };
            byte[] actionBytes = { 3, 4, 6, 7, 1, 2, 0, 5 };

            BitUnpack actionUnpacker = new BitUnpack(packet);

            var slotId = packet.Read<byte>();
            var actionId = actionUnpacker.GetPackedValue(actionMask, actionBytes);

            if (actionId == 0)
            {
                var action = pChar.ActionButtons.Where(button => button.SlotId == slotId && button.SpecGroup == pChar.ActiveSpecGroup).Select(button => button).First();

                ActionMgr.RemoveActionButton(pChar, action, true);
                Log.Message(LogType.Debug, "Character (Guid: {0}) removed action button {1} from slot {2}.", pChar.Guid, actionId, slotId);

                return;
            }

            var newAction = new ActionButton
            {
                Action    = actionId,
                SlotId    = slotId,
                SpecGroup = pChar.ActiveSpecGroup
            };

            ActionMgr.AddActionButton(pChar, newAction, true);
            Log.Message(LogType.Debug, "Character (Guid: {0}) added action button {1} to slot {2}.", pChar.Guid, actionId, slotId);
        }
Beispiel #21
0
        public static void HandlePong(ref PacketReader packet, WorldClass session)
        {
            uint latency = packet.Read<uint>();
            uint sequence = packet.Read<uint>();

            PacketWriter pong = new PacketWriter(ServerMessage.Pong);

            pong.WriteUInt32(sequence);

            session.Send(ref pong);
        }
        public static void HandleAuthResponse(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            packet.Skip(54);

            int addonSize = packet.Read<int>();
            packet.Skip(addonSize);

            uint nameLength = BitUnpack.GetBits<uint>(12);
            string accountName = packet.ReadString(nameLength);

            SQLResult result = DB.Realms.Select("SELECT * FROM accounts WHERE name = ?", accountName);
            if (result.Count == 0)
                session.clientSocket.Close();
            else
                session.Account = new Account()
                {
                    Id         = result.Read<int>(0, "id"),
                    Name       = result.Read<String>(0, "name"),
                    Password   = result.Read<String>(0, "password"),
                    SessionKey = result.Read<String>(0, "sessionkey"),
                    Expansion  = result.Read<byte>(0, "expansion"),
                    GMLevel    = result.Read<byte>(0, "gmlevel"),
                    IP         = result.Read<String>(0, "ip"),
                    Language   = result.Read<String>(0, "language")
                };

            string K = session.Account.SessionKey;
            byte[] kBytes = new byte[K.Length / 2];

            for (int i = 0; i < K.Length; i += 2)
                kBytes[i / 2] = Convert.ToByte(K.Substring(i, 2), 16);

            session.Crypt.Initialize(kBytes);

            uint realmId = WorldConfig.RealmId;
            SQLResult realmClassResult = DB.Realms.Select("SELECT class, expansion FROM realm_classes WHERE realmId = ?", realmId);
            SQLResult realmRaceResult = DB.Realms.Select("SELECT race, expansion FROM realm_races WHERE realmId = ?", realmId);

            bool HasAccountData = true;
            bool IsInQueue = false;

            PacketWriter authResponse = new PacketWriter(ServerMessage.AuthResponse);
            BitPack BitPack = new BitPack(authResponse);

            BitPack.Write(IsInQueue);

            if (IsInQueue)
                BitPack.Write(1);                                  // Unknown

            BitPack.Write(HasAccountData);

            if (HasAccountData)
            {
                BitPack.Write(0);                                  // Unknown, 5.0.4
                BitPack.Write(0);                                  // Unknown, 5.3.0
                BitPack.Write(realmRaceResult.Count, 23);          // Activation count for races
                BitPack.Write(0);                                  // Unknown, 5.1.0
                BitPack.Write(0, 21);                              // Activate character template windows/button

                //if (HasCharacterTemplate)
                //Write bits for char templates...

                BitPack.Write(realmClassResult.Count, 23);         // Activation count for classes
                BitPack.Write(0, 22);                              // Unknown, 5.3.0
                BitPack.Write(0);                                  // Unknown2, 5.3.0
            }

            BitPack.Flush();

            if (HasAccountData)
            {
                authResponse.WriteUInt8(0);

                for (int c = 0; c < realmClassResult.Count; c++)
                {
                    authResponse.WriteUInt8(realmClassResult.Read<byte>(c, "expansion"));
                    authResponse.WriteUInt8(realmClassResult.Read<byte>(c, "class"));
                }

                //if (Unknown2)
                //    authResponse.WriteUInt16(0);

                //if (HasCharacterTemplate)
                //Write data for char templates...

                //if (Unknown)
                //    authResponse.WriteUInt16(0);

                for (int r = 0; r < realmRaceResult.Count; r++)
                {
                    authResponse.WriteUInt8(realmRaceResult.Read<byte>(r, "expansion"));
                    authResponse.WriteUInt8(realmRaceResult.Read<byte>(r, "race"));
                }

                authResponse.WriteUInt32(0);
                authResponse.WriteUInt32(0);
                authResponse.WriteUInt32(0);

                authResponse.WriteUInt8(session.Account.Expansion);

                // Unknown Counter
                // Write UInt32...

                authResponse.WriteUInt8(session.Account.Expansion);
            }

            authResponse.WriteUInt8((byte)AuthCodes.AUTH_OK);

            if (IsInQueue)
                authResponse.WriteUInt32(0);

            session.Send(ref authResponse);

            MiscHandler.HandleCacheVersion(ref session);
            TutorialHandler.HandleTutorialFlags(ref session);
        }
Beispiel #23
0
        public static void HandlePlayerLogin(ref PacketReader packet, WorldClass session)
        {
            byte[] guidMask = { 0, 7, 2, 5, 4, 6, 1, 3 };
            byte[] guidBytes = { 7, 1, 5, 0, 3, 6, 2, 4 };

            BitUnpack GuidUnpacker = new BitUnpack(packet);

            var unknown = packet.Read<float>();
            var guid = GuidUnpacker.GetPackedValue(guidMask, guidBytes);

            Log.Message(LogType.Debug, "Character with Guid: {0}, AccountId: {1} tried to enter the world.", guid, session.Account.Id);

            session.Character = new Character(guid);

            if (!WorldMgr.AddSession(guid, ref session))
            {
                Log.Message(LogType.Error, "A Character with Guid: {0} is already logged in", guid);
                return;
            }

            WorldMgr.WriteAccountDataTimes(AccountDataMasks.CharacterCacheMask, ref session);

            MiscHandler.HandleMessageOfTheDay(ref session);
            TimeHandler.HandleLoginSetTimeSpeed(ref session);
            SpecializationHandler.HandleUpdateTalentData(ref session);
            SpellHandler.HandleSendKnownSpells(ref session);
            MiscHandler.HandleUpdateActionButtons(ref session);

            if (session.Character.LoginCinematic)
                CinematicHandler.HandleStartCinematic(ref session);

            ObjectHandler.HandleUpdateObjectCreate(ref session);
        }
Beispiel #24
0
        public static void HandleMove(ref PacketReader packet, ref WorldClass session)
        {
            ObjectMovementValues movementValues = new ObjectMovementValues();
            BitUnpack BitUnpack = new BitUnpack(packet);

            bool[] guidMask = new bool[8];
            byte[] guidBytes = new byte[8];

            Vector4 vector = new Vector4()
            {
                X = packet.Read<float>(),
                Y = packet.Read<float>(),
                Z = packet.Read<float>()
            };

            guidMask[0] = BitUnpack.GetBit();
            guidMask[3] = BitUnpack.GetBit();

            bool HasPitch = !BitUnpack.GetBit();

            guidMask[2] = BitUnpack.GetBit();

            bool HasSplineElevation = !BitUnpack.GetBit();

            bool Unknown = BitUnpack.GetBit();
            bool Unknown2 = BitUnpack.GetBit();

            guidMask[6] = BitUnpack.GetBit();
            guidMask[7] = BitUnpack.GetBit();
            guidMask[5] = BitUnpack.GetBit();

            movementValues.HasMovementFlags = !BitUnpack.GetBit();
            movementValues.HasRotation = !BitUnpack.GetBit();

            bool Unknown3 = BitUnpack.GetBit();

            movementValues.HasMovementFlags2 = !BitUnpack.GetBit();
            movementValues.IsAlive = !BitUnpack.GetBit();

            guidMask[1] = BitUnpack.GetBit();

            movementValues.IsTransport = BitUnpack.GetBit();

            guidMask[4] = BitUnpack.GetBit();

            movementValues.IsInterpolated = BitUnpack.GetBit();
            bool HasTime = !BitUnpack.GetBit();

            uint counter = BitUnpack.GetBits<uint>(22);

            if (movementValues.IsInterpolated)
                movementValues.IsInterpolated2 = BitUnpack.GetBit();

            if (movementValues.HasMovementFlags)
                movementValues.MovementFlags = (MovementFlag)BitUnpack.GetBits<uint>(30);

            if (movementValues.HasMovementFlags2)
                movementValues.MovementFlags2 = (MovementFlag2)BitUnpack.GetBits<uint>(13);

            if (guidMask[0]) guidBytes[0] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[2]) guidBytes[2] = (byte)(packet.Read<byte>() ^ 1);

            for (int i = 0; i < counter; i++)
                packet.Read<uint>();

            if (guidMask[7]) guidBytes[7] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[6]) guidBytes[6] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[1]) guidBytes[1] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[4]) guidBytes[4] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[3]) guidBytes[3] = (byte)(packet.Read<byte>() ^ 1);
            if (guidMask[5]) guidBytes[5] = (byte)(packet.Read<byte>() ^ 1);

            if (HasSplineElevation)
                packet.Read<float>();

            /*if (movementValues.IsTransport)
            {

            }*/

            if (movementValues.IsInterpolated)
            {
                if (movementValues.IsInterpolated2)
                {
                    packet.Read<float>();
                    packet.Read<float>();
                    packet.Read<float>();
                }

                packet.Read<uint>();
                packet.Read<float>();
            }

            if (HasPitch)
                packet.Read<float>();

            if (movementValues.IsAlive)
                movementValues.Time = packet.Read<uint>();

            if (movementValues.HasRotation)
                vector.O = packet.Read<float>();

            if (HasTime)
                movementValues.Time = packet.Read<uint>();

            var guid = BitConverter.ToUInt64(guidBytes, 0);
            HandleMoveUpdate(guid, movementValues, vector);
        }
Beispiel #25
0
        public static void HandleZoneUpdate(ref PacketReader packet, ref WorldClass session)
        {
            var pChar = session.Character;

            uint zone = packet.Read<uint>();

            ObjectMgr.SetZone(ref pChar, zone);
        }
Beispiel #26
0
        public static void HandleQueryGameObject(ref PacketReader packet, ref WorldClass session)
        {
            byte[] guidMask = { 4, 6, 7, 5, 3, 2, 1, 0 };
            byte[] guidBytes = { 0, 2, 3, 5, 6, 1, 4, 7 };

            BitUnpack BitUnpack = new BitUnpack(packet);

            var hasData = false;
            var id = packet.Read<int>();
            var guid = BitUnpack.GetPackedValue(guidMask, guidBytes);

            PacketWriter queryGameObjectResponse = new PacketWriter(ServerMessage.QueryGameObjectResponse);
            BitPack BitPack = new BitPack(queryGameObjectResponse);

            GameObject gObject = DataMgr.FindGameObject(id);
            if (hasData = (gObject != null))
            {
                GameObjectStats stats = gObject.Stats;

                BitPack.Write(hasData);
                BitPack.Flush();

                queryGameObjectResponse.WriteInt32(stats.Id);
                queryGameObjectResponse.WriteInt32(0);
                queryGameObjectResponse.WriteInt32(stats.Type);
                queryGameObjectResponse.WriteInt32(stats.DisplayInfoId);

                queryGameObjectResponse.WriteCString(stats.Name);

                for (int i = 0; i < 3; i++)
                    queryGameObjectResponse.WriteCString("");

                queryGameObjectResponse.WriteCString(stats.IconName);
                queryGameObjectResponse.WriteCString(stats.CastBarCaption);
                queryGameObjectResponse.WriteCString("");

                foreach (var v in stats.Data)
                    queryGameObjectResponse.WriteInt32(v);

                queryGameObjectResponse.WriteFloat(stats.Size);
                queryGameObjectResponse.WriteUInt8((byte)stats.QuestItemId.Count);

                foreach (var v in stats.QuestItemId)
                    queryGameObjectResponse.WriteInt32(v);

                queryGameObjectResponse.WriteInt32(stats.ExpansionRequired);

                var size = (uint)queryGameObjectResponse.BaseStream.Length - 13;
                queryGameObjectResponse.WriteUInt32Pos(size, 9);

                session.Send(ref queryGameObjectResponse);
            }
            else
            {
                BitPack.Write(hasData);
                Log.Message(LogType.DEBUG, "Gameobject (Id: {0}) not found.", id);
            }
        }
Beispiel #27
0
        public static void HandleViolenceLevel(ref PacketReader packet, WorldClass session)
        {
            byte violenceLevel = packet.Read<byte>();

            Log.Message(LogType.Debug, "Violence level from account '{0} (Id: {1})' is {2}.", session.Account.Name, session.Account.Id, (ViolenceLevel)violenceLevel);
        }
Beispiel #28
0
        public static void HandleQueryPlayerName(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            byte[] guidMask = { 2, 1, 5, 7, 4, 3, 6, 0 };
            byte[] guidBytes = { 3, 2, 6, 1, 0, 4, 5, 7 };

            uint realmId = packet.Read<uint>();
            ulong guid = BitUnpack.GetPackedValue(guidMask, guidBytes);

            var pSession = WorldMgr.GetSession(guid);
            if (pSession != null)
            {
                var pChar = pSession.Character;

                if (pChar != null)
                {
                    PacketWriter queryPlayerNameResponse = new PacketWriter(ServerMessage.QueryPlayerNameResponse);
                    BitPack BitPack = new BitPack(queryPlayerNameResponse, guid);

                    BitPack.WriteGuidMask(7, 3, 0, 2, 1, 6);
                    BitPack.Write(pChar.Name.Length, 6);
                    BitPack.WriteGuidMask(4);
                    BitPack.Write(0);
                    BitPack.WriteGuidMask(5);
                    BitPack.Write(0);

                    BitPack.Flush();

                    BitPack.WriteGuidBytes(2, 7);

                    queryPlayerNameResponse.WriteUInt8(0);

                    BitPack.WriteGuidBytes(5, 6, 4, 1);

                    queryPlayerNameResponse.WriteUInt8(pChar.Gender);
                    queryPlayerNameResponse.WriteUInt8(pChar.Race);
                    queryPlayerNameResponse.WriteUInt32(realmId);
                    queryPlayerNameResponse.WriteUInt8(pChar.Class);

                    BitPack.WriteGuidBytes(3, 0);

                    queryPlayerNameResponse.WriteString(pChar.Name);

                    session.Send(ref queryPlayerNameResponse);
                }
            }
        }
Beispiel #29
0
        public static void HandleActivePlayer(ref PacketReader packet, WorldClass session)
        {
            byte active = packet.Read<byte>();    // Always 0

            Log.Message(LogType.Debug, "Player {0} (Guid: {1}) is active.", session.Character.Name, session.Character.Guid);
        }
Beispiel #30
0
        public static void HandleCliQueryNPCText(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            byte[] guidMask = { 4, 7, 3, 6, 0, 1, 5, 2 };
            byte[] guidBytes = { 5, 6, 7, 1, 2, 3, 0, 4 };

            var gossipTextId = packet.Read<int>();
            var guid = BitUnpack.GetPackedValue(guidMask, guidBytes);

            var gossipData = GossipMgr.GetGossip<Creature>(SmartGuid.GetGuid(guid));

            if (gossipData != null)
            {
                PacketWriter queryNPCTextResponse = new PacketWriter(ServerMessage.QueryNPCTextResponse);
                BitPack BitPack = new BitPack(queryNPCTextResponse);

                queryNPCTextResponse.WriteInt32(gossipTextId);
                queryNPCTextResponse.WriteInt32(0);
                queryNPCTextResponse.WriteFloat(1);

                for (int i = 0; i < 7; i++)
                    queryNPCTextResponse.WriteUInt32(0);

                queryNPCTextResponse.WriteInt32(gossipData.BroadCastText.Id);

                for (int i = 0; i < 7; i++)
                    queryNPCTextResponse.WriteUInt32(0);

                BitPack.Write(1);
                BitPack.Flush();

                var size = (uint)queryNPCTextResponse.BaseStream.Length - 13;
                queryNPCTextResponse.WriteUInt32Pos(size, 8);

                session.Send(ref queryNPCTextResponse);
            }
        }
Beispiel #31
0
        public void HandleAuthLogonChallenge(PacketReader data)
        {
            Log.Message(LogType.NORMAL, "AuthLogonChallenge");

            data.Skip(10);
            ushort ClientBuild = data.Read<ushort>();
            data.Skip(8);
            account.Language = data.ReadStringFromBytes(4);
            data.Skip(4);

            account.IP = data.ReadIPAddress();
            account.Name = data.ReadAccountName();

            SQLResult result = DB.Realms.Select("SELECT id, name, password, expansion, gmlevel, securityFlags, online FROM accounts WHERE name = ?", account.Name);

            using (var logonChallenge = new PacketWriter())
            {
                logonChallenge.WriteUInt8((byte)ClientLink.CMD_AUTH_LOGON_CHALLENGE);
                logonChallenge.WriteUInt8(0);

                if (result.Count != 0)
                {
                    if (result.Read<bool>(0, "online"))
                    {
                        logonChallenge.WriteUInt8((byte)AuthResults.WOW_FAIL_ALREADY_ONLINE);
                        Send(logonChallenge);
                        return;
                    }

                    account.Id = result.Read<Int32>(0, "id");
                    account.Expansion = result.Read<Byte>(0, "expansion");
                    account.SecurityFlags = result.Read<Byte>(0, "securityFlags");

                    DB.Realms.Execute("UPDATE accounts SET ip = ?, language = ? WHERE id = ?", account.IP, account.Language, account.Id);

                    var username = result.Read<String>(0, "name").ToUpperInvariant();
                    var password = result.Read<String>(0, "password").ToUpperInvariant();

                    // WoW 5.2.0.16826
                    if (ClientBuild == 16826)
                    {
                        SecureRemotePassword.CalculateX(username, password);

                        var randBytes = new byte[0x10];

                        var random = RNGCryptoServiceProvider.Create();
                        random.GetBytes(randBytes);

                        logonChallenge.WriteUInt8((byte)AuthResults.WOW_SUCCESS);
                        logonChallenge.WriteBytes(SecureRemotePassword.B);
                        logonChallenge.WriteUInt8(1);
                        logonChallenge.WriteUInt8(SecureRemotePassword.g.ToByteArray()[0]);
                        logonChallenge.WriteUInt8(0x20);
                        logonChallenge.WriteBytes(SecureRemotePassword.N);
                        logonChallenge.WriteBytes(SecureRemotePassword.Salt);
                        logonChallenge.WriteBytes(randBytes);

                        // Security flags
                        logonChallenge.WriteUInt8(account.SecurityFlags);

                        // Enable authenticator
                        if ((account.SecurityFlags & 4) != 0)
                            logonChallenge.WriteUInt8(1);
                    }
                }
                else
                    logonChallenge.WriteUInt8((byte)AuthResults.WOW_FAIL_UNKNOWN_ACCOUNT);

                Send(logonChallenge);
            }
        }