Пример #1
0
        public static void BBPostMessage(Mobile from, BaseBulletinBoard board, CircularBufferReader reader)
        {
            var thread = World.FindItem(reader.ReadUInt32()) as BulletinMessage;

            if (thread != null && thread.Parent != board)
            {
                thread = null;
            }

            var breakout = 0;

            while (thread?.Thread != null && breakout++ < 10)
            {
                thread = thread.Thread;
            }

            var lastPostTime = DateTime.MinValue;

            if (board.GetLastPostTime(from, thread == null, ref lastPostTime))
            {
                if (thread == null)
                {
                    if (!BulletinBoardSystem.CheckCreateTime(lastPostTime))
                    {
                        from.SendMessage($"You must wait {FormatTS(BulletinBoardSystem.ThreadCreateTime)} before creating a new thread.");
                        return;
                    }
                }
                else if (!BulletinBoardSystem.CheckReplyTime(lastPostTime))
                {
                    from.SendMessage($"You must wait {FormatTS(BulletinBoardSystem.ThreadReplyTime)} before replying to another thread.");
                    return;
                }
            }

            var subject = reader.ReadUTF8Safe(reader.ReadByte());

            if (subject.Length == 0)
            {
                return;
            }

            var lines = new string[reader.ReadByte()];

            if (lines.Length == 0)
            {
                return;
            }

            for (var i = 0; i < lines.Length; ++i)
            {
                lines[i] = reader.ReadUTF8Safe(reader.ReadByte());
            }

            board.PostMessage(from, thread, subject, lines);
        }
Пример #2
0
 public static void SystemInfo(NetState state, CircularBufferReader reader)
 {
     int v1 = reader.ReadByte();
     int v2 = reader.ReadUInt16();
     int v3 = reader.ReadByte();
     var s1 = reader.ReadAscii(32);
     var s2 = reader.ReadAscii(32);
     var s3 = reader.ReadAscii(32);
     var s4 = reader.ReadAscii(32);
     int v4 = reader.ReadUInt16();
     int v5 = reader.ReadUInt16();
     var v6 = reader.ReadInt32();
     var v7 = reader.ReadInt32();
     var v8 = reader.ReadInt32();
 }
Пример #3
0
        public static void BBClientRequest(NetState state, CircularBufferReader reader, int packetLength)
        {
            var from = state.Mobile;

            int packetID = reader.ReadByte();

            if (World.FindItem((Serial)reader.ReadUInt32()) is not BaseBulletinBoard board || !board.CheckRange(from))
            {
                return;
            }

            switch (packetID)
            {
            case 3:
                BBRequestContent(from, board, reader);
                break;

            case 4:
                BBRequestHeader(from, board, reader);
                break;

            case 5:
                BBPostMessage(from, board, reader);
                break;

            case 6:
                BBRemoveMessage(from, board, reader);
                break;
            }
        }
Пример #4
0
        public static void DecodeBundledPacket(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            int packetID = reader.ReadByte();

            PacketHandler ph = GetHandler(packetID);

            if (ph == null)
            {
                return;
            }

            if (ph.Ingame && state.Mobile == null)
            {
                state.WriteConsole("Sent in-game packet (0xBFx{0:X2}) before having been attached to a mobile", packetID);
                state.Disconnect("Sent in-game packet before being attached to a mobile.");
            }
            else if (ph.Ingame && state.Mobile.Deleted)
            {
                state.Disconnect(string.Empty);
            }
            else
            {
                ph.OnReceive(state, reader, ref packetLength);
            }
        }
Пример #5
0
        public static void PollInfo(NetState ns, CircularBufferReader reader, ref int packetLength)
        {
            var version = reader.ReadByte();

            if (_token != null)
            {
                unsafe {
                    byte *tok  = stackalloc byte[_token.Length];
                    var   span = new Span <byte>(tok, _token.Length);
                    reader.Read(span);

                    if (!span.SequenceEqual(_token))
                    {
                        ns.Disconnect("Invalid token sent for ConnectUO");
                        return;
                    }
                }
            }

            ns.WriteConsole($"ConnectUO (v{version}) is requesting stats.");
            if (version > ConnectUOProtocolVersion)
            {
                Utility.PushColor(ConsoleColor.Yellow);
                ns.WriteConsole("Warning! ConnectUO (v{version}) is newer than what is supported.");
                Utility.PopColor();
            }

            ns.SendServerPollInfo();
        }
Пример #6
0
        public static void VendorBuyReply(NetState state, CircularBufferReader reader)
        {
            var vendor = World.FindMobile(reader.ReadUInt32());
            var flag   = reader.ReadByte();

            if (vendor == null)
            {
                return;
            }

            if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10))
            {
                state.Send(new EndVendorBuy(vendor));
                return;
            }

            if (flag == 0x02)
            {
                var msgSize = reader.Remaining;

                if (msgSize / 7 > 100)
                {
                    return;
                }

                var buyList = new List <BuyItemResponse>(msgSize / 7);
                while (msgSize > 0)
                {
                    var    layer  = reader.ReadByte();
                    Serial serial = reader.ReadUInt32();
                    int    amount = reader.ReadInt16();

                    buyList.Add(new BuyItemResponse(serial, amount));
                    msgSize -= 7;
                }

                if (buyList.Count > 0 && vendor is IVendor v && v.OnBuyItems(state.Mobile, buyList))
                {
                    state.Send(new EndVendorBuy(vendor));
                }
            }
            else
            {
                state.Send(new EndVendorBuy(vendor));
            }
        }
Пример #7
0
        public static void CrashReport(NetState state, CircularBufferReader reader)
        {
            var clientMaj = reader.ReadByte();
            var clientMin = reader.ReadByte();
            var clientRev = reader.ReadByte();
            var clientPat = reader.ReadByte();

            var x   = reader.ReadUInt16();
            var y   = reader.ReadUInt16();
            var z   = reader.ReadSByte();
            var map = reader.ReadByte();

            var account   = reader.ReadAscii(32);
            var character = reader.ReadAscii(32);
            var ip        = reader.ReadAscii(15);

            var unk1      = reader.ReadInt32();
            var exception = reader.ReadInt32();

            var process = reader.ReadAscii(100);
            var report  = reader.ReadAscii(100);

            reader.ReadByte(); // 0x00

            var offset = reader.ReadInt32();

            int count = reader.ReadByte();

            for (var i = 0; i < count; i++)
            {
                var address = reader.ReadInt32();
            }
        }
Пример #8
0
        private static void OnMapCommand(NetState state, CircularBufferReader reader, int packetLength)
        {
            var from = state.Mobile;

            if (World.FindItem((Serial)reader.ReadUInt32()) is not MapItem map)
            {
                return;
            }

            int command = reader.ReadByte();
            int number  = reader.ReadByte();

            int x = reader.ReadInt16();
            int y = reader.ReadInt16();

            switch (command)
            {
            case 1:
                map.OnAddPin(from, x, y);
                break;

            case 2:
                map.OnInsertPin(from, number, x, y);
                break;

            case 3:
                map.OnChangePin(from, number, x, y);
                break;

            case 4:
                map.OnRemovePin(from, number);
                break;

            case 5:
                map.OnClearPins(from);
                break;

            case 6:
                map.OnToggleEditable(from);
                break;
            }
        }
Пример #9
0
        public static void VendorBuyReply(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            var vendor = World.FindMobile((Serial)reader.ReadUInt32());

            if (vendor == null)
            {
                return;
            }

            var flag = reader.ReadByte();

            if (!vendor.Deleted && Utility.InRange(vendor.Location, state.Mobile.Location, 10) && flag == 0x02)
            {
                var msgSize = packetLength - 8; // Remaining bytes

                if (msgSize / 7 > 100)
                {
                    return;
                }

                var buyList = new List <BuyItemResponse>(msgSize / 7);
                while (msgSize > 0)
                {
                    var layer  = reader.ReadByte();
                    var serial = (Serial)reader.ReadUInt32();
                    int amount = reader.ReadInt16();

                    buyList.Add(new BuyItemResponse(serial, amount));
                    msgSize -= 7;
                }

                if (buyList.Count <= 0 || (vendor as IVendor)?.OnBuyItems(state.Mobile, buyList) != true)
                {
                    return;
                }
            }

            state.SendEndVendorBuy(vendor.Serial);
        }
Пример #10
0
        public static void DropReq(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            reader.ReadInt32(); // serial, ignored
            int x = reader.ReadInt16();
            int y = reader.ReadInt16();
            int z = reader.ReadSByte();

            if (state.ContainerGridLines)
            {
                reader.ReadByte(); // Grid Location?
            }
            else
            {
                packetLength -= 1;
            }

            Serial dest = (Serial)reader.ReadUInt32();

            var loc = new Point3D(x, y, z);

            var from = state.Mobile;

            if (dest.IsMobile)
            {
                from.Drop(World.FindMobile(dest), loc);
            }
            else if (dest.IsItem)
            {
                var item = World.FindItem(dest);

                if (item is BaseMulti multi && multi.AllowsRelativeDrop)
                {
                    loc.m_X += multi.X;
                    loc.m_Y += multi.Y;
                    from.Drop(loc);
                }
                else
                {
                    from.Drop(item, loc);
                }
            }
Пример #11
0
        public static void ProfileReq(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            int type   = reader.ReadByte();
            var serial = (Serial)reader.ReadUInt32();

            var beholder = state.Mobile;
            var beheld   = World.FindMobile(serial);

            if (beheld == null)
            {
                return;
            }

            switch (type)
            {
            case 0x00:     // display request
            {
                EventSink.InvokeProfileRequest(beholder, beheld);

                break;
            }

            case 0x01:              // edit request
            {
                reader.ReadInt16(); // Skip
                int length = reader.ReadUInt16();

                if (length > 511)
                {
                    return;
                }

                var text = reader.ReadBigUni(length);

                EventSink.InvokeChangeProfileRequest(beholder, beheld, text);

                break;
            }
            }
        }
Пример #12
0
        public static void MobileQuery(NetState state, CircularBufferReader reader)
        {
            var from = state.Mobile;

            if (from == null)
            {
                return;
            }

            reader.ReadInt32(); // 0xEDEDEDED
            int type = reader.ReadByte();
            var m    = World.FindMobile(reader.ReadUInt32());

            if (m == null)
            {
                return;
            }

            switch (type)
            {
            case 0x04:     // Stats
            {
                m.OnStatsQuery(from);
                break;
            }

            case 0x05:
            {
                m.OnSkillsQuery(from);
                break;
            }

            default:
            {
                reader.Trace(state);
                break;
            }
            }
        }
Пример #13
0
 public static void RequestScrollWindow(NetState state, CircularBufferReader reader)
 {
     int lastTip = reader.ReadInt16();
     int type    = reader.ReadByte();
 }
Пример #14
0
 public static void PingReq(NetState state, CircularBufferReader reader)
 {
     state.Send(PingAck.Instantiate(reader.ReadByte()));
 }
Пример #15
0
        public static void ChangeSkillLock(NetState state, CircularBufferReader reader)
        {
            var s = state.Mobile.Skills[reader.ReadInt16()];

            s?.SetLockNoRelay((SkillLock)reader.ReadByte());
        }
Пример #16
0
        public static void TextCommand(NetState state, CircularBufferReader reader)
        {
            var from = state.Mobile;

            if (from == null)
            {
                return;
            }

            int type    = reader.ReadByte();
            var command = reader.ReadAscii();

            switch (type)
            {
            case 0xC7:     // Animate
            {
                EventSink.InvokeAnimateRequest(from, command);

                break;
            }

            case 0x24:     // Use skill
            {
                if (!int.TryParse(command.Split(' ')[0], out var skillIndex))
                {
                    break;
                }

                Skills.UseSkill(from, skillIndex);

                break;
            }

            case 0x43:     // Open spellbook
            {
                if (!int.TryParse(command, out var booktype))
                {
                    booktype = 1;
                }

                EventSink.InvokeOpenSpellbookRequest(from, booktype);

                break;
            }

            case 0x27:     // Cast spell from book
            {
                var split = command.Split(' ');

                if (split.Length > 0)
                {
                    var spellID = Utility.ToInt32(split[0]) - 1;
                    var serial  = split.Length > 1 ? Utility.ToUInt32(split[1]) : (uint)Serial.MinusOne;

                    EventSink.InvokeCastSpellRequest(from, spellID, World.FindItem(serial));
                }

                break;
            }

            case 0x58:     // Open door
            {
                EventSink.InvokeOpenDoorMacroUsed(from);

                break;
            }

            case 0x56:     // Cast spell from macro
            {
                var spellID = Utility.ToInt32(command) - 1;

                EventSink.InvokeCastSpellRequest(from, spellID, null);

                break;
            }

            case 0xF4:     // Invoke virtues from macro
            {
                var virtueID = Utility.ToInt32(command) - 1;

                EventSink.InvokeVirtueMacroRequest(from, virtueID);

                break;
            }

            case 0x2F:     // Old scroll double click
            {
                /*
                 * This command is still sent for items 0xEF3 - 0xEF9
                 *
                 * Command is one of three, depending on the item ID of the scroll:
                 * - [scroll serial]
                 * - [scroll serial] [target serial]
                 * - [scroll serial] [x] [y] [z]
                 */
                break;
            }

            default:
            {
                state.WriteConsole("Unknown text-command type 0x{0:X2}: {1}", state, type, command);
                break;
            }
            }
        }
        public static void TargetResponse(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            int    type     = reader.ReadByte();
            var    targetID = reader.ReadInt32();
            int    flags    = reader.ReadByte();
            Serial serial   = reader.ReadUInt32();
            int    x        = reader.ReadInt16();
            int    y        = reader.ReadInt16();

            reader.ReadByte();
            int z       = reader.ReadSByte();
            int graphic = reader.ReadUInt16();

            if (targetID == unchecked ((int)0xDEADBEEF))
            {
                return;
            }

            var from = state.Mobile;

            var t = from.Target;

            if (t == null)
            {
                return;
            }

            var prof = TargetProfile.Acquire(t.GetType());

            prof?.Start();

            try
            {
                if (x == -1 && y == -1 && !serial.IsValid)
                {
                    // User pressed escape
                    t.Cancel(from, TargetCancelType.Canceled);
                }
                else if (t.TargetID != targetID)
                {
                    // Sanity, prevent fake target
                }
                else
                {
                    object toTarget;

                    if (type == 1)
                    {
                        if (graphic == 0)
                        {
                            toTarget = new LandTarget(new Point3D(x, y, z), from.Map);
                        }
                        else
                        {
                            var map = from.Map;

                            if (map == null || map == Map.Internal)
                            {
                                t.Cancel(from, TargetCancelType.Canceled);
                                return;
                            }
                            else
                            {
                                var tiles = map.Tiles.GetStaticTiles(x, y, !t.DisallowMultis);

                                var valid = false;

                                if (state.HighSeas)
                                {
                                    var id = TileData.ItemTable[graphic & TileData.MaxItemValue];
                                    if (id.Surface)
                                    {
                                        z -= id.Height;
                                    }
                                }

                                for (var i = 0; !valid && i < tiles.Length; ++i)
                                {
                                    if (tiles[i].Z == z && tiles[i].ID == graphic)
                                    {
                                        valid = true;
                                    }
                                }

                                if (!valid)
                                {
                                    t.Cancel(from, TargetCancelType.Canceled);
                                    return;
                                }
                                else
                                {
                                    toTarget = new StaticTarget(new Point3D(x, y, z), graphic);
                                }
                            }
                        }
                    }
                    else if (serial.IsMobile)
                    {
                        toTarget = World.FindMobile(serial);
                    }
                    else if (serial.IsItem)
                    {
                        toTarget = World.FindItem(serial);
                    }
                    else
                    {
                        t.Cancel(from, TargetCancelType.Canceled);
                        return;
                    }

                    t.Invoke(from, toTarget);
                }
            }
            finally
            {
                prof?.Finish();
            }
        }
Пример #18
0
 public static void PingReq(NetState state, CircularBufferReader reader, ref int packetLength)
 {
     state.SendPingAck(reader.ReadByte());
 }
Пример #19
0
        public static void SecureTrade(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            switch (reader.ReadByte())
            {
            case 1:     // Cancel
            {
                var serial = (Serial)reader.ReadUInt32();

                if (World.FindItem(serial) is SecureTradeContainer cont && cont.Trade != null &&
                    (cont.Trade.From.Mobile == state.Mobile || cont.Trade.To.Mobile == state.Mobile))
                {
                    cont.Trade.Cancel();
                }

                break;
            }

            case 2:     // Check
            {
                var serial = (Serial)reader.ReadUInt32();

                if (World.FindItem(serial) is SecureTradeContainer cont)
                {
                    var trade = cont.Trade;

                    var value = reader.ReadInt32() != 0;

                    if (trade != null)
                    {
                        if (trade.From.Mobile == state.Mobile)
                        {
                            trade.From.Accepted = value;
                            trade.Update();
                        }
                        else if (trade.To.Mobile == state.Mobile)
                        {
                            trade.To.Accepted = value;
                            trade.Update();
                        }
                    }
                }

                break;
            }

            case 3:     // Update Gold
            {
                var serial = (Serial)reader.ReadUInt32();

                if (World.FindItem(serial) is SecureTradeContainer cont)
                {
                    var gold = reader.ReadInt32();
                    var plat = reader.ReadInt32();

                    var trade = cont.Trade;

                    if (trade != null)
                    {
                        if (trade.From.Mobile == state.Mobile)
                        {
                            trade.From.Gold = gold;
                            trade.From.Plat = plat;
                            trade.UpdateFromCurrency();
                        }
                        else if (trade.To.Mobile == state.Mobile)
                        {
                            trade.To.Gold = gold;
                            trade.To.Plat = plat;
                            trade.UpdateToCurrency();
                        }
                    }
                }
            }
            break;
            }
        }