Exemplo n.º 1
0
        internal static void WriteLoginRequest(IPacketWriter Writer, string username, string password)
        {
            if (username.Contains('\t') || password.Contains('\t'))
                throw new ArgumentException("Username or password contains invalid character");

            string textdata = string.Format("{0}\t{1}", username, password);
            byte[] data = Encoding.ASCII.GetBytes(textdata);

            using (var buffer = new FeenPacketBuffer(PacketID.LoginRequest, data))
            {
                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemplo n.º 2
0
        internal static void WriteAudioData(IPacketWriter Writer, Guid userID, Audio.Codecs.CodecID Codec, byte[] AudioData, int AudioDataLen)
        {
            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.Audio);
                buffer.WriteLength(AudioDataLen + (userID == Guid.Empty ? 1 : 17) + 1);
                if (userID == Guid.Empty)
                    buffer.Write(false);
                else
                {
                    buffer.Write(true);
                    buffer.Write(userID.ToByteArray());
                }
                buffer.Write(Codec);
                buffer.Write(AudioData, AudioDataLen);

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemplo n.º 3
0
        internal static void WriteChat(IPacketWriter Writer, IUser user, string text)
        {
            byte[] dataText = Encoding.ASCII.GetBytes(text);

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                byte[] dataUser = UserData(user);
                var len = dataUser.Length + dataText.Length;

                buffer.Write(PacketID.Chat);

                buffer.WriteLength(len);

                buffer.Write(dataUser);

                buffer.Write(dataText);

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemplo n.º 4
0
        public void Write(IPacketWriter writer)
        {
            writer.WriteVarInt(Position.X);
            writer.WriteVarInt(Position.Z);

            const int last18Bits         = 0b0000_0000_0000_0011_1111_1111_1111_1111;
            int       skylightZeroMask   = CalculateZeroMask(Chunk.Skylight.Span, Chunk) & last18Bits;
            int       blocklightZeroMask = CalculateZeroMask(Chunk.Blocklight.Span, Chunk) & last18Bits;

            // note, we always send all light values. In theory, it is allowed to only update specific sections using this mask
            // meaning the zero mask is not necessarily the inverse of the main mask
            var skylightWriteMask = ~skylightZeroMask & last18Bits;

            writer.WriteVarInt(skylightWriteMask);
            var blocklightWriteMask = ~blocklightZeroMask & last18Bits;

            writer.WriteVarInt(blocklightWriteMask);

            writer.WriteVarInt(skylightZeroMask);
            writer.WriteVarInt(blocklightZeroMask);

            WriteSections(Chunk.Skylight.Span, skylightWriteMask, writer);
            WriteSections(Chunk.Blocklight.Span, blocklightWriteMask, writer);
        }
Exemplo n.º 5
0
 public static Task <Packet> GetDrillResultAsync(this IPacketWriter writer)
 {
     return(writer.SendCommandAsync("62007", "3", "101"));
 }
 public PacketClientNotificationHandler(IFeenPhonePacketNetState state)
 {
     this.State = state;
     this.Writer = state.Writer;
 }
Exemplo n.º 7
0
 public override void WriteData(IPacketWriter writer)
 {
     writer.WriteString(Text);
 }
Exemplo n.º 8
0
 public void WriteLoginStream(IPacketWriter writer)
 {
     Debug.LogWarning("TODO investigate loginstream for shiftableAppearance");
 }
Exemplo n.º 9
0
 /// <summary>
 /// Hạ cấp hàng loạt.
 /// </summary>
 /// <param name="equipmentId">ID của trang bị.</param>
 public static async Task <Packet> DegradeEquipmentAllAsync(this IPacketWriter writer, int equipmentId)
 {
     return(await writer.SendCommandAsync(39402, equipmentId.ToString()));
 }
Exemplo n.º 10
0
 internal static void WritePingReq(IPacketWriter Writer)
 {
     var timestamp = (int)Timekeeper.Elapsed.TotalMilliseconds;
     using (var buffer = new FeenPacketBuffer(PacketID.PingReq, new byte[] { (byte)(timestamp >> 8), (byte)(timestamp) }))
     {
         if (Writer != null)
             Writer.Write(buffer);
     }
 }
Exemplo n.º 11
0
 public static async Task <Packet> RefreshCollectAsync(this IPacketWriter writer)
 {
     return(await writer.SendCommandAsync("30100"));
 }
Exemplo n.º 12
0
 internal static void WriteUserLogout(IPacketWriter Writer, IUser user)
 {
     using (var buffer = new FeenPacketBuffer(PacketID.UserLogout, UserData(user)))
     {
         if (Writer != null)
             Writer.Write(buffer);
     }
 }
Exemplo n.º 13
0
        internal static void WriteUserList(IPacketWriter Writer, IEnumerable<IUser> users)
        {
            if (users.Count() > byte.MaxValue)
                throw new ArgumentException("Too many users, max is " + byte.MaxValue);

            List<byte[]> usersDatas = new List<byte[]>();

            foreach (var user in users)
                usersDatas.Add(UserData(user));

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.UserList);
                buffer.WriteLength(usersDatas.Sum(m => m.Length) + 1);
                buffer.Write((byte)usersDatas.Count());
                buffer.Write(usersDatas.SelectMany(m => m).ToArray());

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemplo n.º 14
0
 internal static void WritePingResp(IPacketWriter Writer, ushort timestamp)
 {
     using (var buffer = new FeenPacketBuffer(PacketID.PingResp, new byte[] { (byte)(timestamp >> 8), (byte)(timestamp) }))
     {
         if (Writer != null)
             Writer.Write(buffer);
     }
 }
Exemplo n.º 15
0
 public static Task <Packet> DrillAsync(this IPacketWriter writer)
 {
     return(writer.SendCommandAsync("62006", "3", "101", "0", "0"));
 }
Exemplo n.º 16
0
        public static void WriteCharacterData(this IPacketWriter p, Character c, CharacterDataFlags flags = CharacterDataFlags.All)
        {
            p.WriteLong((long)flags);
            p.WriteByte(0);
            p.WriteByte(0);

            if (flags.HasFlag(CharacterDataFlags.Character))
            {
                p.WriteCharacterStats(c);

                p.WriteByte(250); // nFriendMax
                p.WriteBool(false);
            }

            if (flags.HasFlag(CharacterDataFlags.Money)) p.WriteInt(c.Money);

            if (flags.HasFlag(CharacterDataFlags.InventorySize))
            {
                if (flags.HasFlag(CharacterDataFlags.ItemSlotEquip))
                    p.WriteByte((byte)c.Inventories[ItemInventoryType.Equip].SlotMax);
                if (flags.HasFlag(CharacterDataFlags.ItemSlotConsume))
                    p.WriteByte((byte)c.Inventories[ItemInventoryType.Consume].SlotMax);
                if (flags.HasFlag(CharacterDataFlags.ItemSlotInstall))
                    p.WriteByte((byte)c.Inventories[ItemInventoryType.Install].SlotMax);
                if (flags.HasFlag(CharacterDataFlags.ItemSlotEtc))
                    p.WriteByte((byte)c.Inventories[ItemInventoryType.Etc].SlotMax);
                if (flags.HasFlag(CharacterDataFlags.ItemSlotCash))
                    p.WriteByte((byte)c.Inventories[ItemInventoryType.Cash].SlotMax);
            }

            if (flags.HasFlag(CharacterDataFlags.AdminShopCount))
            {
                p.WriteInt(0);
                p.WriteInt(0);
            }

            if (flags.HasFlag(CharacterDataFlags.ItemSlotEquip))
            {
                var inventory = c.Inventories[ItemInventoryType.Equip].Items;
                var equip = inventory.Where(kv => kv.Key >= 0);
                var equipped = inventory.Where(kv => kv.Key >= -100 && kv.Key < 0);
                var equipped2 = inventory.Where(kv => kv.Key >= -1000 && kv.Key < -100);
                var dragonEquipped = inventory.Where(kv => kv.Key >= -1100 && kv.Key < -1000);
                var mechanicEquipped = inventory.Where(kv => kv.Key >= -1200 && kv.Key < -1100);

                new List<IEnumerable<KeyValuePair<short, AbstractItemSlot>>>
                    {
                        equipped, equipped2, equip, dragonEquipped, mechanicEquipped
                    }
                    .ForEach(e =>
                    {
                        e.ForEach(kv =>
                        {
                            p.WriteShort((short)(Math.Abs(kv.Key) % 100));
                            p.WriteItemData(kv.Value);
                        });
                        p.WriteShort(0);
                    });
            }

            new List<(CharacterDataFlags, ItemInventoryType)>
                {
                    (CharacterDataFlags.ItemSlotConsume, ItemInventoryType.Consume),
                    (CharacterDataFlags.ItemSlotInstall, ItemInventoryType.Install),
                    (CharacterDataFlags.ItemSlotEtc, ItemInventoryType.Etc),
                    (CharacterDataFlags.ItemSlotCash, ItemInventoryType.Cash)
                }
                .Where(t => flags.HasFlag(t.Item1))
                .ForEach(t =>
                {
                    var inventory = c.Inventories[t.Item2].Items;

                    inventory.ForEach(kv =>
                    {
                        p.WriteByte((byte)kv.Key);
                        p.WriteItemData(kv.Value);
                    });
                    p.WriteByte(0);
                });

            if (flags.HasFlag(CharacterDataFlags.SkillRecord))
            {
                p.WriteShort((short)c.SkillRecord.Count);

                c.SkillRecord.ForEach(kv =>
                {
                    p.WriteInt(kv.Key);
                    p.WriteInt(kv.Value.Level);
                    p.WriteDateTime(kv.Value.DateExpire ?? GameConstants.Permanent);

                    if (GameConstants.IsSkillNeedMasterLevel(kv.Key))
                        p.WriteInt(kv.Value.MasterLevel ?? 0);
                });
            }

            if (flags.HasFlag(CharacterDataFlags.SkillCooltime))
            {
                p.WriteShort(0);
            }

            if (flags.HasFlag(CharacterDataFlags.QuestRecord))
            {
                p.WriteShort(0);
            }

            if (flags.HasFlag(CharacterDataFlags.QuestComplete))
            {
                p.WriteShort(0);
            }

            if (flags.HasFlag(CharacterDataFlags.MinigameRecord))
            {
                p.WriteShort(0);
            }

            if (flags.HasFlag(CharacterDataFlags.CoupleRecord))
            {
                p.WriteShort(0); // Couple
                p.WriteShort(0); // Friend
                p.WriteShort(0); // Marriage
            }

            if (flags.HasFlag(CharacterDataFlags.MapTransfer))
            {
                for (var i = 0; i < 5; i++) p.WriteInt(0);
                for (var i = 0; i < 10; i++) p.WriteInt(0);
            }

            if (flags.HasFlag(CharacterDataFlags.NewYearCard))
            {
                p.WriteShort(0);
            }

            if (flags.HasFlag(CharacterDataFlags.QuestRecordEx))
            {
                p.WriteShort(0);
            }

            if (flags.HasFlag(CharacterDataFlags.WildHunterInfo))
            {
                if (c.Job / 100 == 33)
                {
                    p.WriteByte(0);
                    for (var i = 0; i < 5; i++) p.WriteInt(0);
                }
            }

            if (flags.HasFlag(CharacterDataFlags.QuestCompleteOld))
            {
                p.WriteShort(0);
            }

            if (flags.HasFlag(CharacterDataFlags.VisitorLog))
            {
                p.WriteShort(0);
            }
        }
Exemplo n.º 17
0
        internal static void WriteLoginStatus(IPacketWriter Writer, bool isLoggedIn, string message = null)
        {
            byte[] dataText = message == null || message.Length == 0 ? null : Encoding.ASCII.GetBytes(message);
            int dataTextLen = dataText == null ? 0 : dataText.Length;

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.LoginStatus);
                buffer.WriteLength(3 + dataTextLen);
                buffer.Write(isLoggedIn);
                buffer.Write((ushort)FeenPhone.Accounting.AccountHandler.Instance.Version);

                if (dataText != null)
                    buffer.Write(dataText);

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Collect.
 /// </summary>
 public static async Task <Packet> Collect(this IPacketWriter writer, int value)
 {
     return(await writer.SendCommandAsync("30401", value + ""));
 }
Exemplo n.º 19
0
 public abstract void WriteAddStream(IPacketWriter writer);
Exemplo n.º 20
0
 /// <summary>
 /// Hạ cấp trang bị (ma lực không ảnh hưởng).
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="equipmentId">ID của trang bị.</param>
 public static async Task <Packet> DegradeEquipmentAsync(this IPacketWriter writer, int equipmentId)
 {
     return(await writer.DegradeEquipmentAsync(equipmentId, 0));
 }
Exemplo n.º 21
0
 public void WriteToPacket(IPacketWriter writer)
 {
     writer.WriteByte((byte)_history.Count);
     _history.ForEach(o => writer.Write(o));
 }
Exemplo n.º 22
0
 public virtual void WriteAddStream(IPacketWriter writer)
 {
     throw new NotImplementedException(); //only playerAppearance should implement this
 }
Exemplo n.º 23
0
 protected override void WriteData(IPacketWriter writer)
 {
     writer.WriteBool(_stat);
 }
Exemplo n.º 24
0
 public void WriteAddStream(IPacketWriter writer)
 {
     writer.WriteInt32(mShiftedNPCTypeID);
 }
Exemplo n.º 25
0
 public static async Task <Packet> SetDefaultFormationAsync(this IPacketWriter writer, int formationId)
 {
     return(await writer.SendCommandAsync("42104", formationId.ToString()));
 }
Exemplo n.º 26
0
 public static async Task <Packet> SendCommandAsync(this IPacketWriter writer, string commandId, params string[] parameters)
 {
     return(await writer.SendCommandAsync(Int32.Parse(commandId), parameters));
 }
Exemplo n.º 27
0
 public static async Task <Packet> RemoveAllHeroesFromFormationAsync(this IPacketWriter writer, int formationId)
 {
     return(await writer.SendCommandAsync("42107", formationId.ToString()));
 }
Exemplo n.º 28
0
 public void Send(IPacketWriter packet)
 {
     Socket.SendData(packet, packet.Name);
 }
Exemplo n.º 29
0
 public void WriteLoginStream(IPacketWriter writer)
 {
     writer.WriteInt32(GetRelevanceID());
     writer.WriteFloat(Time.realtimeSinceStartup);
     writer.WriteByte((byte)mNetState);
 }
Exemplo n.º 30
0
 public static Task <Packet> RefreshOutsideAsync(this IPacketWriter writer, long playerId)
 {
     return(writer.SendCommandAsync("62002", playerId.ToString()));
 }
Exemplo n.º 31
0
 public override void WriteAddStream(IPacketWriter writer)
 {
     writer.WriteInt32(GetRelevanceID());
     writer.WriteInt32(((Rotator)transform.rotation).Yaw);
 }
Exemplo n.º 32
0
 public override void WriteAddStream(IPacketWriter writer)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 33
0
 public abstract void Encode(IPacketWriter packetWriter);
Exemplo n.º 34
0
 public void SetPacketWriter(IPacketWriter writer)
 {
     packetWriter = writer;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Giữ cải tiến.
 /// </summary>
 /// <param name="heroId">ID của tướng</param>
 public static async Task <Packet> KeepStatsAsync(this IPacketWriter writer, int heroId)
 {
     return(await writer.SendCommandAsync(41303, heroId.ToString(), "0"));
 }
Exemplo n.º 36
0
 /// <summary>
 /// Chuyen bang chu.
 /// </summary>
 ///
 public static async Task <Packet> Swap(this IPacketWriter writer, long slot1Id)
 {
     return(await writer.SendCommandAsync("32108", slot1Id + ""));
 }
Exemplo n.º 37
0
 /// <summary>
 /// Cải tiến.
 /// </summary>
 /// <param name="heroId">ID của tướng.</param>
 public static async Task <Packet> ImproveHeroAsync(this IPacketWriter writer, int heroId)
 {
     return(await writer.SendCommandAsync(41301, heroId.ToString(), "0"));
 }
Exemplo n.º 38
0
 /// <summary>
 /// Tìm bang chu.
 /// </summary>
 public static async Task <Packet> RefreshLegionAsync(this IPacketWriter writer)
 {
     return(await writer.SendCommandAsync("32101", "0", "12", " "));
 }
Exemplo n.º 39
0
 /// <summary>
 /// Hạ cấp trang bị.
 /// </summary>
 /// <param name="equipmentId">ID của trang bị.</param>
 /// <param name="magic">Ma lực hiện tại</param>
 public static async Task <Packet> DegradeEquipmentAsync(this IPacketWriter writer, int equipmentId, int magic)
 {
     return(await writer.SendCommandAsync(39103, equipmentId.ToString(), "0", magic.ToString()));
 }