Ejemplo n.º 1
0
        public static void HandleChatMessageWhisper(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);
            int language = packet.ReadInt32();

            uint messageLength = BitUnpack.GetBits<uint>(9);
            uint nameLength = BitUnpack.GetNameLength<uint>(9);

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

            WorldClass rSession = WorldMgr.GetSession(receiverName);

            SendMessageByType(ref rSession, MessageType.ChatMessageWhisper, language, chatMessage);
            SendMessageByType(ref session, MessageType.ChatMessageWhisperInform, language, chatMessage);
        }
Ejemplo n.º 2
0
        public static void HandleCreateCharacter(ref PacketReader packet, WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            packet.Skip(1);

            var facialHair = packet.ReadByte();
            var skin = packet.ReadByte();
            var race = packet.ReadByte();
            var hairStyle = packet.ReadByte();
            var pClass = packet.ReadByte();
            var face = packet.ReadByte();
            var gender = packet.ReadByte();
            var hairColor = packet.ReadByte();

            var nameLength  = BitUnpack.GetBits<uint>(6);
            var hasUnknown = BitUnpack.GetBit();
            var name        = Character.NormalizeName(packet.ReadString(nameLength));

            if (hasUnknown)
                packet.ReadUInt32();

            var result      = DB.Characters.Select("SELECT * from characters WHERE name = ?", name);
            var createChar  = new PacketWriter(ServerMessage.CreateChar);

            if (result.Count != 0)
            {
                // Name already in use
                createChar.WriteUInt8(0x32);
                session.Send(ref createChar);
                return;
            }

            result = DB.Characters.Select("SELECT map, zone, posX, posY, posZ, posO FROM character_creation_data WHERE race = ? AND class = ?", race, pClass);
            if (result.Count == 0)
            {
                createChar.WriteUInt8(0x31);
                session.Send(ref createChar);
                return;
            }

            var map  = result.Read<uint>(0, "map");
            var zone = result.Read<uint>(0, "zone");
            var posX = result.Read<float>(0, "posX");
            var posY = result.Read<float>(0, "posY");
            var posZ = result.Read<float>(0, "posZ");
            var posO = result.Read<float>(0, "posO");

            // Allow declined names for now
            var characterFlags = CharacterFlag.Decline;

            DB.Characters.Execute("INSERT INTO characters (name, accountid, realmId, race, class, gender, skin, zone, map, x, y, z, o, face, hairstyle, haircolor, facialhair, characterFlags) VALUES (" +
                                  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                                  name, session.Account.Id, WorldConfig.RealmId, race, pClass, gender, skin, zone, map, posX, posY, posZ, posO, face, hairStyle, hairColor, facialHair, characterFlags);

            // Success
            createChar.WriteUInt8(0x2F);
            session.Send(ref createChar);
        }
Ejemplo n.º 3
0
        public static void HandleChatMessageYell(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);
            int language = packet.ReadInt32();

            uint messageLength = BitUnpack.GetBits<uint>(9);
            string chatMessage = packet.ReadString(messageLength);
            SendMessageByType(ref session, MessageType.ChatMessageYell, language, chatMessage);
        }
Ejemplo n.º 4
0
        public static void HandleChatMessageSay(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);
            int language = packet.ReadInt32();

            uint messageLength = BitUnpack.GetBits<uint>(9);
            string chatMessage = packet.ReadString(messageLength);

            if (ChatCommandParser.CheckForCommand(chatMessage))
                ChatCommandParser.ExecuteChatHandler(chatMessage, ref session);
            else
                SendMessageByType(ref session, MessageType.ChatMessageSay, language, chatMessage);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static void HandleChatMessageYell(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            var language = packet.ReadInt32();

            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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public static void HandleChatMessageSay(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            int language = packet.ReadInt32();

            uint messageLength = BitUnpack.GetBits<uint>(9);
            string chatMessage = packet.ReadString(messageLength);

            PacketWriter messageChat = new PacketWriter(LegacyMessage.MessageChat);

            ulong guid = WorldMgr.Session.Character.Guid;

            messageChat.WriteUInt8(1);
            messageChat.WriteInt32(language);
            messageChat.WriteUInt64(guid);
            messageChat.WriteUInt32(0);
            messageChat.WriteUInt64(guid);
            messageChat.WriteUInt32(messageLength + 1);
            messageChat.WriteCString(chatMessage);
            messageChat.WriteUInt16(0);

            session.Send(messageChat);
        }
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        public static void HandleResponseCharacterCreate(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            byte pClass = packet.ReadByte();
            byte hairStyle = packet.ReadByte();
            byte facialHair = packet.ReadByte();
            byte race = packet.ReadByte();
            byte face = packet.ReadByte();
            byte skin = packet.ReadByte();
            byte gender = packet.ReadByte();
            byte hairColor = packet.ReadByte();
            packet.ReadByte();                      // Always 0

            uint nameLength = BitUnpack.GetNameLength<uint>(7);
            string name = packet.ReadString(nameLength);

            SQLResult result = DB.Characters.Select("SELECT * from characters WHERE name = '{0}'", name);
            PacketWriter writer = new PacketWriter(LegacyMessage.ResponseCharacterCreate);

            if (result.Count != 0)
            {
                // Name already in use
                writer.WriteUInt8(0x32);
                session.Send(writer);
                return;
            }

            result = DB.Characters.Select("SELECT map, zone, posX, posY, posZ, posO FROM character_creation_data WHERE race = {0} AND class = {1}", race, pClass);
            if (result.Count == 0)
            {
                writer.WriteUInt8(0x31);
                session.Send(writer);
                return;
            }

            uint map = result.Read<uint>(0, "map");
            uint zone = result.Read<uint>(0, "zone");
            float posX = result.Read<float>(0, "posX");
            float posY = result.Read<float>(0, "posY");
            float posZ = result.Read<float>(0, "posZ");
            float posO = result.Read<float>(0, "posO");

            DB.Characters.Execute("INSERT INTO characters (name, accountid, race, class, gender, skin, zone, map, x, y, z, o, face, hairstyle, haircolor, facialhair) VALUES (" +
                                  "'{0}', {1}, {2}, {3}, {4}, {5}, {6}, {7}, '{8}', '{9}', '{10}', '{11}', {12}, {13}, {14}, {15})",
                                  name, session.Account.Id, race, pClass, gender, skin, zone, map, posX, posY, posZ, posO, face, hairStyle, hairColor, facialHair);

            // Success
            writer.WriteUInt8(0x2F);
            session.Send(writer);
        }
Ejemplo n.º 12
0
        public static void HandleChangePlayerDNDState(ref PacketReader packet, WorldClass session)
        {
            var pChar           = session.Character;
            string dndText      = "";

            uint stateLength    = packet.Read<byte>();

            if (stateLength > 0)
                dndText = packet.ReadString(stateLength);

            pChar.setDndState(dndText);
        }
Ejemplo n.º 13
0
        public static void HandleChangePlayerAFKState(ref PacketReader packet, WorldClass session)
        {
            var pChar           = session.Character;
            string afkText      = "";

            byte stateLength    = packet.Read<byte>();

            if (stateLength > 0)
                afkText = packet.ReadString(stateLength);

            pChar.setAfkState(afkText);
        }
Ejemplo n.º 14
0
        public static void HandleResponseCharacterCreate(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            byte pClass = packet.ReadByte();
            byte hairStyle = packet.ReadByte();
            byte facialHair = packet.ReadByte();
            byte race = packet.ReadByte();
            byte face = packet.ReadByte();
            byte skin = packet.ReadByte();
            byte gender = packet.ReadByte();
            byte hairColor = packet.ReadByte();
            packet.ReadByte();                      // Always 0

            uint nameLength = BitUnpack.GetNameLength<uint>(7);
            string name = Character.NormalizeName(packet.ReadString(nameLength));

            SQLResult result = DB.Characters.Select("SELECT * from characters WHERE name = ?", name);
            PacketWriter writer = new PacketWriter(LegacyMessage.ResponseCharacterCreate);

            if (result.Count != 0)
            {
                // Name already in use
                writer.WriteUInt8(0x32);
                session.Send(ref writer);
                return;
            }

            result = DB.Characters.Select("SELECT map, zone, posX, posY, posZ, posO FROM character_creation_data WHERE race = ? AND class = ?", race, pClass);
            if (result.Count == 0)
            {
                writer.WriteUInt8(0x31);
                session.Send(ref writer);
                return;
            }

            uint map = result.Read<uint>(0, "map");
            uint zone = result.Read<uint>(0, "zone");
            float posX = result.Read<float>(0, "posX");
            float posY = result.Read<float>(0, "posY");
            float posZ = result.Read<float>(0, "posZ");
            float posO = result.Read<float>(0, "posO");

            // Allow declined names for now
            var characterFlags = CharacterFlag.Decline;

            DB.Characters.Execute("INSERT INTO characters (name, accountid, race, class, gender, skin, zone, map, x, y, z, o, face, hairstyle, haircolor, facialhair, characterFlags) VALUES (" +
                                  "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                                  name, session.Account.Id, race, pClass, gender, skin, zone, map, posX, posY, posZ, posO, face, hairStyle, hairColor, facialHair, characterFlags);

            // Success
            writer.WriteUInt8(0x2F);
            session.Send(ref writer);
        }