Пример #1
0
        public static void SendMultiTargetReq(this NetState ns, MultiTarget t)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x99); // Packet ID
            writer.Write(t.AllowGround);
            writer.Write(t.TargetID);
            writer.Write((byte)t.Flags);
            writer.Clear(11);
            writer.Write((short)t.MultiID);
            writer.Write((short)t.Offset.X);
            writer.Write((short)t.Offset.Y);
            writer.Write((short)t.Offset.Z);
            if (ns.HighSeas)
            {
                writer.Write(0);
            }

            ns.Send(ref buffer, writer.Position);
        }
        public static int SendUnicodeMessage(
            ArraySegment <byte>[] buffer,
            Serial serial, int graphic, MessageType type, int hue, int font, string lang, string name, string text
            )
        {
            name = name?.Trim() ?? "";
            text = text?.Trim() ?? "";
            lang = lang?.Trim() ?? "ENU";

            if (hue == 0)
            {
                hue = 0x3B2;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xAE);
            writer.Write((ushort)(50 + text.Length * 2));
            writer.Write(serial);
            writer.Write((short)graphic);
            writer.Write((byte)type);
            writer.Write((short)hue);
            writer.Write((short)font);
            writer.WriteAscii(lang, 4);
            writer.WriteAscii(name, 30);
            writer.WriteBigUniNull(text);

            return(writer.Position);
        }
Пример #3
0
        public static void SendDamage(this NetState ns, Serial serial, int amount)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            if (ns.DamagePacket)
            {
                writer.Write((byte)0x0B); // Packet ID
                writer.Write(serial);
                writer.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
            }
            else
            {
                writer.Write((byte)0xBF); // Packet ID
                writer.Write((ushort)11); // Length
                writer.Write((ushort)0x22);
                writer.Write((byte)1);
                writer.Write(serial);
                writer.Write((byte)Math.Clamp(amount, 0, 0xFF));
            }

            ns.Send(ref buffer, writer.Position);
        }
        public static void SendSecureTradeEquip(this NetState ns, Item item, Mobile m)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x25); // Packet ID
            writer.Write(item.Serial);
            writer.Write((short)item.ItemID);
            writer.Write((byte)0);
            writer.Write((short)item.Amount);
            writer.Write((short)item.X);
            writer.Write((short)item.Y);
            if (ns.ContainerGridLines)
            {
                writer.Write((byte)0);
            }
            writer.Write(m.Serial);
            writer.Write((short)item.Hue);

            ns.Send(ref buffer, writer.Position);
        }
Пример #5
0
        /// <summary>
        /// Constructs a circular buffer of specified initial size
        /// </summary>
        /// <param name="size">Initial size of buffer</param>
        public CircularBuffer(int size)
        {
            this.internalData = new byte[size + 1];

            this.writer = new CircularBufferWriter(this);
            this.reader = new CircularBufferReader(this);
        }
Пример #6
0
        public static void SendNewSpellbookContent(this NetState ns, Serial book, int graphic, int offset, ulong content)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xBF);  // Packet ID
            writer.Write((ushort)23);  // Length
            writer.Write((short)0x1B); // Subpacket
            writer.Write((short)0x01); // Command

            writer.Write(book);
            writer.Write((short)graphic);
            writer.Write((short)offset);

            for (var i = 0; i < 8; ++i)
            {
                writer.Write((byte)(content >> (i * 8)));
            }

            ns.Send(ref buffer, writer.Position);
        }
Пример #7
0
        public static void SendArrow(this NetState ns, byte command, int x, int y, Serial s)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xBA); // Packet ID
            writer.Write(command);


            if (ns.HighSeas)
            {
                writer.Write((short)x);
                writer.Write((short)y);
                writer.Write(s);
            }
            else if (command == 1)
            {
                writer.Write((short)x);
                writer.Write((short)y);
            }
            else
            {
                writer.Write((short)-1);
                writer.Write((short)-1);
            }

            ns.Send(ref buffer, writer.Position);
        }
Пример #8
0
        public static void SendMapPatches(this NetState ns)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xBF);   // Packet ID
            writer.Write((ushort)41);   // Length
            writer.Write((ushort)0x18); // Subpacket
            writer.Write(4);            // Map count?

            writer.Write(Map.Felucca.Tiles.Patch.StaticBlocks);
            writer.Write(Map.Felucca.Tiles.Patch.LandBlocks);

            writer.Write(Map.Trammel.Tiles.Patch.StaticBlocks);
            writer.Write(Map.Trammel.Tiles.Patch.LandBlocks);

            writer.Write(Map.Ilshenar.Tiles.Patch.StaticBlocks);
            writer.Write(Map.Ilshenar.Tiles.Patch.LandBlocks);

            writer.Write(Map.Malas.Tiles.Patch.StaticBlocks);
            writer.Write(Map.Malas.Tiles.Patch.LandBlocks);

            ns.Send(ref buffer, writer.Position);
        }
        public static void SendVendorBuyList(this NetState ns, Mobile vendor, List <BuyItemState> list)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x74); // Packet ID
            writer.Seek(2, SeekOrigin.Current);
            writer.Write((vendor.FindItemOnLayer(Layer.ShopBuy) as Container)?.Serial ?? Serial.MinusOne);
            writer.Write((byte)list.Count);

            for (var i = 0; i < list.Count; ++i)
            {
                var bis = list[i];

                writer.Write(bis.Price);

                var desc = bis.Description ?? "";

                writer.Write((byte)desc.Length);
                writer.WriteAscii(desc); // Doesn't look like it is used anymore
            }

            writer.WritePacketLength();

            ns.Send(ref buffer, writer.Position);
        }
        public static void SendVendorBuyContent(this NetState ns, List <BuyItemState> list)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x3C); // Packet ID
            writer.Seek(2, SeekOrigin.Current);

            writer.Write((short)list.Count);

            for (var i = list.Count - 1; i >= 0; --i)
            {
                var bis = list[i];

                writer.Write(bis.MySerial);
                writer.Write((ushort)bis.ItemID);
                writer.Write((byte)0);        // itemID offset
                writer.Write((ushort)bis.Amount);
                writer.Write((short)(i + 1)); // x
                writer.Write((short)1);       // y
                if (ns.ContainerGridLines)
                {
                    writer.Write((byte)0); // Grid Location?
                }
                writer.Write(bis.ContainerSerial);
                writer.Write((ushort)bis.Hue);
            }

            writer.WritePacketLength();
            ns.Send(ref buffer, writer.Position);
        }
Пример #11
0
        /**
         * Packet: 0xA8
         * Length: up to 240 bytes
         *
         * Sends login acknowledge with server listing
         */
        public static void SendAccountLoginAck(this NetState ns)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xA8);           // Packet ID
            writer.Seek(2, SeekOrigin.Current); // Length

            writer.Write((byte)0x5D);

            var info = ns.ServerInfo;

            writer.Write((ushort)info.Length);

            for (var i = 0; i < info.Length; ++i)
            {
                var si = info[i];

                writer.Write((ushort)i);
                writer.WriteAscii(si.Name, 32);
                writer.Write((byte)si.FullPercent);
                writer.Write((sbyte)si.TimeZone);
                writer.Write(Utility.GetAddressValue(si.Address.Address));
            }

            writer.WritePacketLength();
            ns.Send(ref buffer, writer.Position);
        }
Пример #12
0
        /**
         * Packet: 0x1B
         * Length: 37 bytes
         *
         * Sends login confirmation
         */
        public static void SendLoginConfirmation(this NetState ns, Mobile m)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x1B); // PacketID
            writer.Write(m.Serial);
            writer.Write(0);
            writer.Write((short)m.Body);
            writer.Write((short)m.X);
            writer.Write((short)m.Y);
            writer.Write((short)m.Z);
            writer.Write((byte)m.Direction);
            writer.Write((byte)0);
            writer.Write(-1);

            writer.Write(0);

            var map = m.Map;

            if (map == null || map == Map.Internal)
            {
                map = m.LogoutMap;
            }

            writer.Write((short)(map?.Width ?? Map.Felucca.Width));
            writer.Write((short)(map?.Height ?? Map.Felucca.Height));
            writer.Clear();

            ns.Send(ref buffer, 37);
        }
Пример #13
0
        public static void WritePacketLength(this CircularBufferWriter writer)
        {
            var length = writer.Position;

            writer.Seek(1, SeekOrigin.Begin);
            writer.Write((ushort)length);
            writer.Seek(length, SeekOrigin.Begin);
        }
Пример #14
0
        public static void SendDisplayItemListMenu(this NetState ns, ItemListMenu menu)
        {
            if (ns == null || menu == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x7C);           // Packet ID
            writer.Seek(2, SeekOrigin.Current); // Length
            writer.Write(menu.Serial);
            writer.Write((ushort)0);

            var question = menu.Question?.Trim();

            if (question == null)
            {
                writer.Write((byte)0);
            }
            else
            {
                var questionLength = question.Length;
                writer.Write((byte)questionLength);
                writer.WriteAscii(question);
            }

            var entries = menu.Entries;

            int entriesLength = (byte)entries.Length;

            writer.Write((byte)entriesLength);

            for (var i = 0; i < entriesLength; ++i)
            {
                var e = entries[i];

                writer.Write((ushort)e.ItemID);
                writer.Write((short)e.Hue);

                var name = e.Name?.Trim();

                if (name == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    var nameLength = name.Length;
                    writer.Write((byte)nameLength);
                    writer.WriteAscii(name);
                }
            }

            writer.WritePacketLength();

            ns.Send(ref buffer, writer.Position);
        }
Пример #15
0
        public static void SendDisplayQuestionMenu(this NetState ns, QuestionMenu menu)
        {
            if (ns == null || menu == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x7C);           // Packet ID
            writer.Seek(2, SeekOrigin.Current); // Length
            writer.Write(menu.Serial);
            writer.Write((ushort)0);

            var question = menu.Question?.Trim();

            if (question == null)
            {
                writer.Write((byte)0);
            }
            else
            {
                var questionLength = question.Length;
                writer.Write((byte)questionLength);
                writer.WriteAscii(question);
            }

            var answers = menu.Answers;

            int answersLength = (byte)answers.Length;

            writer.Write((byte)answersLength);

            for (var i = 0; i < answersLength; ++i)
            {
                writer.Write(0);

                var answer = answers[i]?.Trim();

                if (answer == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    var nameLength = answer.Length;
                    writer.Write((byte)nameLength);
                    writer.WriteAscii(answer);
                }
            }

            writer.WritePacketLength();

            ns.Send(ref buffer, writer.Position);
        }
Пример #16
0
        public static void SendChangeCombatant(this NetState ns, Serial combatant)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xAA); // Packet ID
            writer.Write(combatant);

            ns.Send(ref buffer, writer.Position);
        }
Пример #17
0
        public static void SendContainerContent(this NetState ns, Mobile beholder, Item beheld)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var items = beheld.Items;
            var count = items.Count;

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x3C);           // Packet ID
            writer.Seek(4, SeekOrigin.Current); // Length & writter count

            var written = 0;

            for (var i = 0; i < count; ++i)
            {
                var child = items[i];

                if (!child.Deleted && beholder.CanSee(child))
                {
                    var loc = child.Location;

                    writer.Write(child.Serial);
                    writer.Write((ushort)child.ItemID);
                    writer.Write((byte)0); // signed, itemID offset
                    writer.Write((ushort)Math.Min(child.Amount, ushort.MaxValue));
                    writer.Write((short)loc.X);
                    writer.Write((short)loc.Y);
                    if (ns.ContainerGridLines)
                    {
                        writer.Write((byte)0); // Grid Location?
                    }
                    writer.Write(beheld.Serial);
                    writer.Write((ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));

                    ++written;
                }
            }

            var length = writer.Position;

            writer.Seek(1, SeekOrigin.Begin);
            writer.Write((ushort)length);
            writer.Write((ushort)written);

            ns.Send(ref buffer, length);
        }
Пример #18
0
        public static void SendDisplayEquipmentInfo(
            this NetState ns,
            Serial serial, int number, string crafterName, bool unidentified, List <EquipInfoAttribute> attrs
            )
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            crafterName = crafterName.DefaultIfNullOrEmpty("");

            var length = 17 +
                         (crafterName.Length > 0 ? 6 + crafterName.Length : 0) +
                         (unidentified ? 4 : 0) +
                         attrs.Count * 6;

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xBF);   // Packet ID
            writer.Write((ushort)length);
            writer.Write((ushort)0x10); // Subpacket
            writer.Write(serial);
            writer.Write(number);

            if (crafterName.Length > 0)
            {
                writer.Write(-3); // crafted by

                writer.Write((ushort)crafterName.Length);
                writer.WriteAscii(crafterName);
            }

            if (unidentified)
            {
                writer.Write(-4);
            }

            for (var i = 0; i < attrs.Count; ++i)
            {
                var attr = attrs[i];
                writer.Write(attr.Number);
                writer.Write((short)attr.Charges);
            }

            writer.Write(-1);

            ns.Send(ref buffer, writer.Position);
        }
Пример #19
0
        public static void SendSetWarMode(this NetState ns, bool warmode)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x72); // Packet ID
            // Warmode, 0x00, 0x32, 0x00
            writer.Write(warmode ? 0x01003200 : 0x00003200);

            ns.Send(ref buffer, writer.Position);
        }
Пример #20
0
        public static void SendPersonalLightLevel(this NetState ns, Serial serial, int level)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x4E); // Packet ID
            writer.Write(serial);
            writer.Write((byte)level);

            ns.Send(ref buffer, writer.Position);
        }
Пример #21
0
        public static void SendFastwalkStackKey(this NetState ns, uint key = 0)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xBF);  // Packet ID
            writer.Write((ushort)0x2); // Subpacket
            writer.Write(key);

            ns.Send(ref buffer, writer.Position);
        }
Пример #22
0
        public static void SendFollowMessage(this NetState ns, Serial s1, Serial s2)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x15); // Packet ID
            writer.Write(s1);
            writer.Write(s2);

            ns.Send(ref buffer, 9);
        }
        public static void SendCloseSecureTrade(this NetState ns, Container cont)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x6F); // Packet ID
            writer.Write((ushort)8);  // Length
            writer.Write((byte)TradeFlag.Close);
            writer.Write(cont.Serial);

            ns.Send(ref buffer, writer.Position);
        }
        public static void SendEndVendorBuy(this NetState ns, Serial vendor)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x3B); // Packet ID
            writer.Write((ushort)8);
            writer.Write(vendor);
            writer.Write((byte)0); // Buy count

            ns.Send(ref buffer, writer.Position);
        }
Пример #25
0
        public static void SendSpeedControl(this NetState ns, SpeedControlSetting speedControl)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xBF);   // Packet ID
            writer.Write((ushort)06);
            writer.Write((ushort)0x26); // Subpacket
            writer.Write((byte)speedControl);

            ns.Send(ref buffer, writer.Position);
        }
Пример #26
0
        public static void SendSwing(this NetState ns, Serial attacker, Serial defender)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x2F); // Packet ID
            writer.Write((byte)0);
            writer.Write(attacker);
            writer.Write(defender);

            ns.Send(ref buffer, writer.Position);
        }
Пример #27
0
        public static void SendMapChange(this NetState ns, Map map)
        {
            if (ns == null || map == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xBF);   // Packet ID
            writer.Write((ushort)6);    // Length
            writer.Write((ushort)0x08); // Subpacket
            writer.Write((byte)map.MapID);

            ns.Send(ref buffer, writer.Position);
        }
Пример #28
0
        public static void SendTimeSyncResponse(this NetState ns)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0xF2);     // Packet ID

            writer.Write(Core.TickCount); // ??
            writer.Write(Core.TickCount); // ??
            writer.Write(Core.TickCount); // ??

            ns.Send(ref buffer, writer.Position);
        }
Пример #29
0
        /**
         * Packet: 0x86
         * Length: Up to 424 bytes
         *
         * Sends updated character list
         */
        public static void SendCharacterListUpdate(this NetState ns, IAccount a)
        {
            if (ns == null || a == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x86);           // Packet ID
            writer.Seek(2, SeekOrigin.Current); // Length

            var highSlot = -1;

            for (var i = a.Length - 1; i >= 0; i--)
            {
                if (a[i] != null)
                {
                    highSlot = i;
                    break;
                }
            }

            var count = Math.Max(Math.Max(highSlot + 1, a.Limit), 5);

            writer.Write((byte)count);

            for (int i = 0; i < count; i++)
            {
                var m = a[i];

                if (m == null)
                {
                    writer.Clear(60);
                }
                else
                {
                    var name = (m.RawName?.Trim()).DefaultIfNullOrEmpty("-no name-");
                    writer.WriteAscii(name, 30);
                    writer.Clear(30); // password
                }
            }

            writer.WritePacketLength();
            ns.Send(ref buffer, writer.Position);
        }
Пример #30
0
        /**
         * Packet: 0x8C
         * Length: 11 bytes
         *
         * Sends acknowledge play server
         */
        public static void SendPlayServerAck(this NetState ns, ServerInfo si, int authId)
        {
            if (ns == null || !ns.GetSendBuffer(out var buffer))
            {
                return;
            }

            var writer = new CircularBufferWriter(buffer);

            writer.Write((byte)0x8C); // Packet ID

            writer.WriteLE(si.RawAddress);
            writer.Write((short)si.Address.Port);
            writer.Write(authId);

            ns.Send(ref buffer, writer.Position);
        }
Пример #31
0
		/// <summary>
		/// Constructs a circular buffer of specified initial size
		/// </summary>
		/// <param name="size">Initial size of buffer</param>
		public CircularBuffer(int size)
		{
			this.internalData = new byte[ size+1 ];
			
			this.writer = new CircularBufferWriter(this);
			this.reader = new CircularBufferReader(this);
		}