Пример #1
0
        public void Recieve()
        {
            PacketWriter writer = new PacketWriter(Opcodes.SMSG_AUTH_CHALLENGE, false);
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            this.Send(writer);

            while (WorldSession.listenWorldSocket)
            {
                Thread.Sleep(1);
                if (socket.Available > 0)
                {
                    buffer = new byte[socket.Available];
                    socket.Receive(buffer, buffer.Length, SocketFlags.None);

                    OnData();
                }
            }

            socket.Close();
        }
Пример #2
0
        public static void HandlePing(ref PacketReader packet, ref WorldManager manager)
        {
            PacketWriter writer = new PacketWriter(Opcodes.SMSG_PONG);
            writer.WriteUInt32(packet.ReadUInt32());

            manager.Send(writer);
        }
Пример #3
0
        public static void HandleLogoutRequest(ref PacketReader packet, ref WorldManager manager)
        {
            PacketWriter logoutComplete = new PacketWriter(Opcodes.SMSG_LOGOUT_COMPLETE);
            manager.Send(logoutComplete);

            var result = CharacterObject.GetOnlineCharacter(manager.account);
            result.IsOnline = false;
            DB.Characters.Save(result);
        }
Пример #4
0
        public static void HandleMessageChat(ref PacketReader packet, ref WorldManager manager)
        {
            PacketWriter welcomeMessage = new PacketWriter(Opcodes.SMSG_MESSAGECHAT);
            welcomeMessage.WriteUInt8((byte)packet.ReadInt32());     // slashCmd, 9: SystemMessage
            welcomeMessage.WriteUInt32(packet.ReadUInt32());         // Language: General
            welcomeMessage.WriteUInt64(0);                           // Guid: 0 - ToAll???
            welcomeMessage.WriteString(packet.ReadString());
            welcomeMessage.WriteUInt8(0);                            // afkDND, 0: nothing

            manager.Send(welcomeMessage);
        }
Пример #5
0
        public void HandleRealmList(RealmManager Session)
        {
            PacketWriter realmWriter = new PacketWriter();
            realmWriter.WriteUInt8(1);
            realmWriter.WriteBytes(System.Text.Encoding.ASCII.GetBytes("|cFF00FFFF Flame-WoW"));
            realmWriter.WriteUInt8(0);
            realmWriter.WriteBytes(System.Text.Encoding.ASCII.GetBytes("127.0.0.1:9090"));
            realmWriter.WriteUInt8(0);
            realmWriter.WriteUInt32(0);

            Session.Send(realmWriter, realmSocket);
            realmSocket.Close();
        }
Пример #6
0
        public static void HandleNameCache(ref PacketReader packet, ref WorldManager manager)
        {
            UInt64 guid = packet.ReadUInt64();
            Character character = CharacterObject.GetCharacterByGuid(guid);

            PacketWriter nameCache = new PacketWriter(Opcodes.SMSG_NAME_QUERY_RESPONSE);
            nameCache.WriteUInt64(guid);
            nameCache.WriteString(character.Name);
            nameCache.WriteUInt32(character.Race);
            nameCache.WriteUInt32(character.Gender);
            nameCache.WriteUInt32(character.Class);
            nameCache.WriteUInt8(0);
            manager.Send(nameCache);
        }
Пример #7
0
        public void Send(PacketWriter writer, Socket socket)
        {
            byte[] buffer = writer.ReadDataToSend(true);

            try
            {
                socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
            }
            catch (Exception e)
            {
                Log.Message(LogType.Error, "{0}", e.Message);
                Log.Message();
                socket.Close();
            }
        }
Пример #8
0
        public void HandleProxyConnection(RealmManager Session)
        {
            Log.Message();
            Log.Message(LogType.Normal, "Begin redirection to WorldServer.");

            PacketWriter proxyWriter = new PacketWriter();
            proxyWriter.WriteBytes(System.Text.Encoding.ASCII.GetBytes("127.0.0.1:8100"));
            proxyWriter.WriteUInt8(0);

            Session.Send(proxyWriter, proxySocket);
            proxySocket.Close();

            Log.Message(LogType.Normal, "Successfully redirected to WorldServer");
            Log.Message();
        }
Пример #9
0
        public static void HandleCharEnum(ref PacketReader packet, ref WorldManager manager)
        {
            var account = manager.account;
            var result = CharacterObject.GetCharactersByAccount(account);

            PacketWriter writer = new PacketWriter(Opcodes.SMSG_CHAR_ENUM);
            writer.WriteUInt8((byte)result.Length);

            foreach (Character c in result)
            {
                writer.WriteUInt64(c.Guid);
                Console.WriteLine("GUID: {0}", c.Guid);

                writer.WriteString(c.Name);

                writer.WriteUInt8(c.Race);
                writer.WriteUInt8(c.Class);
                writer.WriteUInt8(c.Gender);
                writer.WriteUInt8(c.Skin);
                writer.WriteUInt8(c.Face);
                writer.WriteUInt8(c.HairStyle);
                writer.WriteUInt8(c.HairStyle);
                writer.WriteUInt8(c.FacialHair);
                writer.WriteUInt8(c.Level);

                writer.WriteUInt32(c.Zone);
                writer.WriteUInt32(c.Map);

                writer.WriteFloat(c.X);
                writer.WriteFloat(c.Y);
                writer.WriteFloat(c.Z);

                writer.WriteUInt32(c.GuildGuid);
                writer.WriteUInt32(c.PetDisplayInfo);
                writer.WriteUInt32(c.PetLevel);
                writer.WriteUInt32(c.PetFamily);

                // Not implented
                for (int j = 0; j < 20; j++)
                {
                    writer.WriteUInt32(0);    // DisplayId
                    writer.WriteUInt8(0);     // InventoryType
                }
            }

            manager.Send(writer);
        }
Пример #10
0
        public void Send(PacketWriter packet)
        {
            byte[] buffer = packet.ReadDataToSend();

            try
            {
                socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(FinishSend), socket);

                Log.Message(LogType.Dump, "Send {0}.", packet.Opcode);
                Log.Message();
            }
            catch (Exception ex)
            {
                Log.Message(LogType.Error, "{0}", ex.Message);
                Log.Message();
                socket.Close();
            }
        }
Пример #11
0
        public static void HandleAuthSession(ref PacketReader packet, ref WorldManager manager)
        {
            packet.ReadUInt32();
            packet.ReadUInt32();

            string name = packet.ReadAccountName(); // Error!!! - use UTF-8
            Account account = Account.GetAccountByName(name);

            PacketWriter writer = new PacketWriter(Opcodes.SMSG_AUTH_RESPONSE);

            if (account == null)
                writer.WriteUInt8((byte)AuthCodes.AUTH_UNKNOWN_ACCOUNT);
            else
            {
                manager.account = account;
                writer.WriteUInt8((byte)AuthCodes.AUTH_OK);
            }

            manager.Send(writer);
        }
Пример #12
0
        public static void HandleWorldTeleport(ref PacketReader packet, ref WorldManager manager)
        {
            packet.ReadUInt32();
            byte zone = packet.ReadUInt8();
            float x = packet.ReadFloat();
            float y = packet.ReadFloat();
            float z = packet.ReadFloat();
            float o = packet.ReadFloat();

            PacketWriter movementStatus = new PacketWriter(Opcodes.SMSG_MOVE_WORLDPORT_ACK);
            movementStatus.WriteUInt64(0);
            movementStatus.WriteFloat(0);
            movementStatus.WriteFloat(0);
            movementStatus.WriteFloat(0);
            movementStatus.WriteFloat(0);
            movementStatus.WriteFloat(x);
            movementStatus.WriteFloat(y);
            movementStatus.WriteFloat(z);
            movementStatus.WriteFloat(o);
            movementStatus.WriteFloat(0);
            movementStatus.WriteUInt32(0x08000000);
            manager.Send(movementStatus);
        }
Пример #13
0
        public static void HandleMovementStatus(ref PacketReader packet, ref WorldManager manager)
        {
            Opcodes MoveMessage = packet.Opcode;
            UInt64 TransportGuid = packet.ReadUInt64();
            Single TransportX = packet.ReadFloat();
            Single TransportY = packet.ReadFloat();
            Single TransportZ = packet.ReadFloat();
            Single TransportO = packet.ReadFloat();
            Single X = packet.ReadFloat();
            Single Y = packet.ReadFloat();
            Single Z = packet.ReadFloat();
            Single O = packet.ReadFloat();
            Single Pitch = packet.ReadFloat();
            UInt32 Flags = packet.ReadUInt32();

            PacketWriter movementStatus = new PacketWriter(MoveMessage);
            movementStatus.WriteUInt64(TransportGuid);
            movementStatus.WriteFloat(TransportX);
            movementStatus.WriteFloat(TransportY);
            movementStatus.WriteFloat(TransportZ);
            movementStatus.WriteFloat(TransportO);
            movementStatus.WriteFloat(X);
            movementStatus.WriteFloat(Y);
            movementStatus.WriteFloat(Z);
            movementStatus.WriteFloat(O);
            movementStatus.WriteFloat(Pitch);
            movementStatus.WriteUInt32(Flags);

            manager.Send(movementStatus);

            var result = CharacterObject.GetOnlineCharacter(manager.account);
            result.X = X;
            result.Y = Y;
            result.Z = Z;
            result.O = O;
            DB.Characters.Save(result);
        }
Пример #14
0
        public static void HandleCharCreate(ref PacketReader packet, ref WorldManager manager)
        {
            Character cha = new Character();
            cha.Name = packet.ReadString();
            cha.Race = packet.ReadByte();
            cha.Class = packet.ReadByte();
            cha.Gender = packet.ReadByte();
            cha.Skin = packet.ReadByte();
            cha.Face = packet.ReadByte();
            cha.HairStyle = packet.ReadByte();
            cha.HairColor = packet.ReadByte();
            cha.FacialHair = packet.ReadByte();
            packet.ReadByte();

            var result = DB.Characters.Select<Character>();
            PacketWriter writer = new PacketWriter(Opcodes.SMSG_CHAR_CREATE);

            foreach (Character c in result)
            {
                if (c.Name == cha.Name)
                {
                    // Name already in use
                    writer.WriteUInt8(0x2B);
                    manager.Send(writer);
                    return;
                }
            }

            cha.AccountId = manager.account.Id;
            cha.Guid = (ulong)(DB.Characters.RowCount + 1);
            DB.Characters.Save(cha);

            // Success
            writer.WriteUInt8(0x28);
            manager.Send(writer);
        }
Пример #15
0
        public static void HandleCharDelete(ref PacketReader packet, ref WorldManager manager)
        {
            UInt64 guid = packet.ReadUInt64();
            Character character = CharacterObject.GetCharacterByGuid(guid);

            PacketWriter writer = new PacketWriter(Opcodes.SMSG_CHAR_DELETE);
            writer.WriteUInt8(0x2C);
            manager.Send(writer);

            DB.Characters.Delete(character);
        }
Пример #16
0
 /*
  * Private Functions
  */
 private void AppendPacket(ref BitArray ba, ref Hashtable ht, ref PacketWriter pw, bool create = true)
 {
     for (int i = 0; i < ba.Length; i++) //Iterate each bit array, get hashtable values and append to the packet correctly
     {
         if (ba.Get(i) && ht[i] != null)
         {
             var data = ht[i];
             if (data is byte)
             {
                 pw.WriteUInt8((byte)ht[i]);
             }
             else if (data is sbyte)
             {
                 pw.WriteInt8((sbyte)ht[i]);
             }
             else if (data is UInt16)
             {
                 pw.WriteUInt16((UInt16)ht[i]);
             }
             else if (data is short)
             {
                 pw.WriteInt16((short)ht[i]);
             }
             else if (data is UInt32)
             {
                 pw.WriteUInt32((UInt32)ht[i]);
             }
             else if (data is int)
             {
                 pw.WriteInt32((int)ht[i]);
             }
             else if (data is UInt64)
             {
                 pw.WriteUInt64((UInt64)ht[i]);
             }
             else if (data is Int64)
             {
                 pw.WriteInt64((Int64)ht[i]);
             }
             else if (data is float)
             {
                 pw.WriteFloat((float)ht[i]);
             }
             else if (data is string)
             {
                 pw.WriteString((string)ht[i]);
             }
             else if (data is double)
             {
                 pw.WriteDouble((double)ht[i]);
             }
             else if (data is byte[])
             {
                 foreach (byte b in ((byte[])data)) //Adds a byte array as a list of uint8s
                 {
                     pw.WriteUInt8(b);
                 }
             }
         }
         else if (create)
         {
             pw.WriteUInt32(0);
         }
     }
 }
Пример #17
0
        public static void HandleUpdateObject(ref PacketReader packet, ref WorldManager manager)
        {
            UInt64 guid = packet.ReadUInt64();
            Character character = CharacterObject.GetCharacterByGuid(guid);
            character.IsOnline = true;
            DB.Characters.Save(character);

            PacketWriter welcomeMessage = new PacketWriter(Opcodes.SMSG_MESSAGECHAT);
            welcomeMessage.WriteUInt8(9);     // slashCmd, 9: SystemMessage
            welcomeMessage.WriteUInt32(0);    // Language: General
            welcomeMessage.WriteUInt64(0);    // Guid: 0 - ToAll???
            welcomeMessage.WriteString("Welcome to Flame-WoW Server!");
            welcomeMessage.WriteUInt8(0);     // afkDND, 0: nothing

            manager.Send(welcomeMessage);

            PacketWriter writer = new PacketWriter(Opcodes.SMSG_UPDATE_OBJECT);
            writer.WriteUInt32(1);           // ObjectCount
            writer.WriteUInt8(2);            // UpdateType, UPDATE_FULL/CreateObject) + PartialUpdateFromFullUpdate
            writer.WriteUInt64(guid);        // ObjectGuid
            writer.WriteUInt8(4);            // ObjectType, 4 = Player

            writer.WriteUInt64(0);           // TransportGuid
            writer.WriteFloat(0);            // TransportX
            writer.WriteFloat(0);            // TransportY
            writer.WriteFloat(0);            // TransportZ
            writer.WriteFloat(0);            // TransportW (TransportO)

            writer.WriteFloat(character.X);  // x
            writer.WriteFloat(character.Y);  // y
            writer.WriteFloat(character.Z);  // z
            writer.WriteFloat(character.O);  // w (o)

            writer.WriteFloat(0);            // Pitch

            writer.WriteUInt32(0x08000000);  // MovementFlagMask
            writer.WriteUInt32(0);           // FallTime

            writer.WriteFloat(2.5f);         // WalkSpeed
            writer.WriteFloat(7.0f);         // RunSpeed
            writer.WriteFloat(4.7222f);      // SwimSpeed
            writer.WriteFloat(3.14f);        // TurnSpeed

            writer.WriteUInt32(1);           // Flags, 1 - Player
            writer.WriteUInt32(1);           // AttackCycle
            writer.WriteUInt32(0);           // TimerId
            writer.WriteUInt64(0);           // VictimGuid

            // FillInPartialObjectData
            writer.WriteUInt8(0x14);         // UpdateMaskBlocks, 20

            for (int i = 0; i < 0x14; i++)
                writer.WriteUInt32(0xFFFFFFFF);

            // ObjectFields
            writer.WriteUInt64(guid);
            writer.WriteUInt32(0x19);         // UpdateType, 0x19 - Player (Player + Unit + Object)
            writer.WriteUInt32(0);
            writer.WriteFloat(1);
            writer.WriteUInt32(0);

            // UnitFields
            for (int i = 0; i < 16; i++)
                writer.WriteUInt32(0);

            writer.WriteUInt32(character.Health);
            writer.WriteUInt32(character.Mana);
            writer.WriteUInt32(character.Rage);
            writer.WriteUInt32(character.Focus);
            writer.WriteUInt32(character.Energy);
            // Max values...
            writer.WriteUInt32(character.Health);
            writer.WriteUInt32(character.Mana);
            writer.WriteUInt32(character.Rage);
            writer.WriteUInt32(character.Focus);
            writer.WriteUInt32(character.Energy);
            writer.WriteUInt32(character.Level);
            writer.WriteUInt32(5);
            writer.WriteUInt8(character.Race);
            writer.WriteUInt8(character.Class);
            writer.WriteUInt8(character.Gender);
            writer.WriteUInt8(1);

            writer.WriteUInt32(character.Strength);
            writer.WriteUInt32(character.Agility);
            writer.WriteUInt32(character.Stamina);
            writer.WriteUInt32(character.Intellect);
            writer.WriteUInt32(character.Spirit);
            // BastStats, copy ...
            writer.WriteUInt32(character.Strength);
            writer.WriteUInt32(character.Agility);
            writer.WriteUInt32(character.Stamina);
            writer.WriteUInt32(character.Intellect);
            writer.WriteUInt32(character.Spirit);

            for (int i = 0; i < 10; i++)
                writer.WriteUInt32(0);

            // Money
            writer.WriteUInt32(character.Money);

            for (int i = 0; i < 56; i++)
                writer.WriteUInt32(0);

            for (int i = 0; i < 39; i++)
                writer.WriteUInt32(0);

            // DisplayId
            switch (character.Race)
            {
                case 1:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x31 : 0x32));
                    break;
                case 2:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x33 : 0x34));
                    break;
                case 3:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x35 : 0x36));
                    break;
                case 4:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x37 : 0x38));
                    break;
                case 5:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x39 : 0x40));
                    break;
                case 6:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x3B : 0x3C));
                    break;
                case 7:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x61B : 0x61C));
                    break;
                case 8:
                    writer.WriteUInt32((uint)(character.Gender == 0 ? 0x5C6 : 0x5C7));
                    break;
            }

            for (int i = 0; i < 32; i++)
                writer.WriteUInt32(0);

            // PlayerFields
            for (int i = 0; i < 46; i++)
                writer.WriteUInt32(0);

            for (int i = 0; i < 32; i++)
                writer.WriteUInt32(0);

            for (int i = 0; i < 48; i++)
                writer.WriteUInt32(0);

            for (int i = 0; i < 12; i++)
                writer.WriteUInt32(0);

            writer.WriteUInt32(0);
            writer.WriteUInt32(0);

            writer.WriteUInt32(0);
            writer.WriteUInt32(0);

            writer.WriteUInt32(0);
            writer.WriteUInt32(0);

            // InventarSlots
            writer.WriteUInt32(14);

            writer.WriteUInt32(0);
            writer.WriteUInt32(0);

            // PLAYER_BYTES (Skin, Face, HairStyle, HairColor)
            writer.WriteUInt8(character.Skin);
            writer.WriteUInt8(character.Face);
            writer.WriteUInt8(character.HairStyle);
            writer.WriteUInt8(character.HairColor);

            // XP
            writer.WriteUInt32(0);
            // NextLevel
            writer.WriteUInt32(200);

            // SkillInfo
            for (int i = 0; i < 192; i++)
                writer.WriteUInt32(0);

            // PLAYER_BYTES_2 (FacialHair, Unknown, BankBagSlotCount, RestState)
            writer.WriteUInt8(character.FacialHair);
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            writer.WriteUInt8(1);

            // QuestInfo
            for (int i = 0; i < 96; i++)
                writer.WriteUInt32(0);

            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            // BaseMana
            writer.WriteUInt32(20);
            writer.WriteUInt32(0);

            // Hmm xD?
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            writer.WriteUInt8(0);
            manager.Send(writer);
        }