コード例 #1
0
        public static void EncodedCommand(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            var e        = World.FindEntity(reader.ReadUInt32());
            int packetId = reader.ReadUInt16();

            var ph = IncomingPackets.GetEncodedHandler(packetId);

            if (ph == null)
            {
                reader.Trace(state);
                return;
            }

            if (ph.Ingame && state.Mobile == null)
            {
                state.WriteConsole(
                    "Sent in-game packet (0xD7x{0:X2}) before being attached to a mobile",
                    packetId
                    );
                state.Disconnect($"Sent in-game packet (0xD7x{packetId:X2}) before being attached to a mobile.");
            }
            else if (ph.Ingame && state.Mobile.Deleted)
            {
                state.Disconnect($"Sent in-game packet(0xD7x{packetId:X2}) but mobile is deleted.");
            }
            else
            {
                ph.OnReceive(state, e, new EncodedReader(reader));
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
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();
        }
コード例 #4
0
        public static void DisplayGumpResponse(NetState state, CircularBufferReader reader, ref int packetLength)
        {
            var serial   = reader.ReadUInt32();
            var typeID   = reader.ReadInt32();
            var buttonID = reader.ReadInt32();

            foreach (var gump in state.Gumps)
            {
                if (gump.Serial != serial || gump.TypeID != typeID)
                {
                    continue;
                }

                var buttonExists = buttonID == 0; // 0 is always 'close'

                if (!buttonExists)
                {
                    foreach (var e in gump.Entries)
                    {
                        if (e is GumpButton button && button.ButtonID == buttonID)
                        {
                            buttonExists = true;
                            break;
                        }

                        if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID)
                        {
                            buttonExists = true;
                            break;
                        }
                    }
                }

                if (!buttonExists)
                {
                    state.WriteConsole("Invalid gump response, disconnecting...");
                    state.Disconnect("Invalid gump response.");
                    return;
                }

                var switchCount = reader.ReadInt32();

                if (switchCount < 0 || switchCount > gump.m_Switches)
                {
                    state.WriteConsole("Invalid gump response, disconnecting...");
                    state.Disconnect("Invalid gump response.");
                    return;
                }

                var switches = new int[switchCount];

                for (var j = 0; j < switches.Length; ++j)
                {
                    switches[j] = reader.ReadInt32();
                }

                var textCount = reader.ReadInt32();

                if (textCount < 0 || textCount > gump.m_TextEntries)
                {
                    state.WriteConsole("Invalid gump response, disconnecting...");
                    state.Disconnect("Invalid gump response.");
                    return;
                }

                var textEntries = new TextRelay[textCount];

                for (var j = 0; j < textEntries.Length; ++j)
                {
                    int entryID    = reader.ReadUInt16();
                    int textLength = reader.ReadUInt16();

                    if (textLength > 239)
                    {
                        state.WriteConsole("Invalid gump response, disconnecting...");
                        state.Disconnect("Invalid gump response.");
                        return;
                    }

                    var text = reader.ReadBigUniSafe(textLength);
                    textEntries[j] = new TextRelay(entryID, text);
                }

                state.RemoveGump(gump);

                var prof = GumpProfile.Acquire(gump.GetType());

                prof?.Start();

                gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries));

                prof?.Finish();

                return;
            }

            if (typeID == 461)
            {
                // Virtue gump
                var switchCount = reader.ReadInt32();

                if (buttonID == 1 && switchCount > 0)
                {
                    var beheld = World.FindMobile(reader.ReadUInt32());

                    if (beheld != null)
                    {
                        EventSink.InvokeVirtueGumpRequest(state.Mobile, beheld);
                    }
                }
                else
                {
                    var beheld = World.FindMobile(serial);

                    if (beheld != null)
                    {
                        EventSink.InvokeVirtueItemRequest(state.Mobile, beheld, buttonID);
                    }
                }
            }
        }