Example #1
0
        public static void RegisterThrottler(int packetID)
        {
            PacketHandler ph = PacketHandlers.GetHandler(packetID);

            if (ph == null)
            {
                return;
            }

            ph.ThrottleCallback = new ThrottlePacketCallback(Throttle_Callback);
        }
Example #2
0
 public PacketHandler GetHandler(int packetID)
 {
     if (ContainerGridLines)
     {
         return(PacketHandlers.Get6017Handler(packetID));
     }
     else
     {
         return(PacketHandlers.GetHandler(packetID));
     }
 }
Example #3
0
        public static void Initialize()
        {
            m_OldEFHandler = PacketHandlers.GetHandler(0xEF);
            PacketHandlers.Register(0xEF, 21, false, new Server.Network.OnPacketReceive(LoginServerSeed));
            PacketHandlers.Register(Config.EncapsulationHeader, 0, false, new Server.Network.OnPacketReceive(UOExtPacket));

            uint ip = (uint)(BitConverter.ToInt32(IPAddress.Parse(Config.IP).GetAddressBytes(), 0));

            m_UOExtSupport = new UOExtSupport();
            m_UOExtSupport.SetStatic();

            m_handler = UOExt.PacketHandler.Instatinate();

            Console.WriteLine("UOExt: Adapter started.");
        }
Example #4
0
        private static void CMConfig()
        {
            EquipItemRequestParent    = PacketHandlers.GetHandler(0x13);
            DropItemRequestParent     = PacketHandlers.GetHandler(0x08);
            DropItemRequestParent6017 = PacketHandlers.Get6017Handler(0x08);

            EquipItemParent = OutgoingPacketOverrides.GetHandler(0x2E);

            PacketHandlers.Register(0x13, 10, true, EquipItemRequest);
            //PacketHandlers.Register6017(0x13, 10, true, EquipItemRequest6017);
            PacketHandlers.Register(0x08, 14, true, DropItemRequest);
            PacketHandlers.Register6017(0x08, 15, true, DropItemRequest6017);

            OutgoingPacketOverrides.Register(0x2E, true, EquipItem);
        }
        public static void Configure()
        {
            EventSink.QuestGumpRequest += XmlQuest.QuestButton;

            ContentChangeParent = PacketHandlers.GetHandler(0x66);
            UseReqParent        = PacketHandlers.GetHandler(0x06);
            LookReqParent       = PacketHandlers.GetHandler(0x09);

            PacketHandlers.Register(0x66, 0, true, BaseEntryBook.ContentChange);
            PacketHandlers.Register(0x06, 5, true, XmlAttach.UseReq);
            PacketHandlers.Register(0x09, 5, true, XmlAttach.LookReq);

                        #if CLIENT6017
            PacketHandlers.Register6017(0x66, 0, true, BaseEntryBook.ContentChange);
            PacketHandlers.Register6017(0x06, 5, true, XmlAttach.UseReq);
            PacketHandlers.Register6017(0x09, 5, true, XmlAttach.LookReq);
                        #endif
        }
Example #6
0
        public static void Initialize()
        {
            m_Target     = PacketHandlers.GetHandler(0x6C);
            m_Target6017 = PacketHandlers.Get6017Handler(0x6C);

            m_Equip     = PacketHandlers.GetHandler(0x13);
            m_Equip6017 = PacketHandlers.Get6017Handler(0x13);

            if (m_Target6017 == null)
            {
                m_Target6017 = m_Target;
            }

            if (m_Equip6017 == null)
            {
                m_Equip6017 = m_Equip;
            }

            PacketHandlers.Register(0x6C, 19, true, new OnPacketReceive(TargetResponse));
            PacketHandlers.Register6017(0x6C, 19, true, new OnPacketReceive(TargetResponse6017));
            PacketHandlers.Register(0x13, 10, true, new OnPacketReceive(EquipReq));
            PacketHandlers.Register6017(0x13, 10, true, new OnPacketReceive(EquipReq6017));
        }
Example #7
0
        public static void Init()
        {
            if (Initialized)
            {
                return;
            }

            ReqOplParent = PacketHandlers.GetExtendedHandler(0x10);
            PacketHandlers.RegisterExtended(ReqOplParent.PacketID, ReqOplParent.Ingame, OnQueryProperties);

            ReqBatchOplParent = PacketHandlers.GetHandler(0xD6);

            var is6017 = (PacketHandlers.Get6017Handler(0xD6) != null);

            PacketHandlers.Register(
                ReqBatchOplParent.PacketID,
                ReqBatchOplParent.Length,
                ReqBatchOplParent.Ingame,
                OnBatchQueryProperties);

            if (is6017)
            {
                PacketHandlers.Register6017(
                    ReqBatchOplParent.PacketID,
                    ReqBatchOplParent.Length,
                    ReqBatchOplParent.Ingame,
                    OnBatchQueryProperties);
            }

            OutParent0xD6 = OutgoingPacketOverrides.GetHandler(0xD6);
            OutgoingPacketOverrides.Register(0xD6, OnEncode0xD6);

            Initialized = true;

            PollTimer.FromSeconds(10.0, FreeCache);
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="netState"></param>
        internal static void MessagePump_ProcessReceive(object sender, NetStateEventArgs eventArgs)
        {
            LOGs.WriteLine(LogMessageType.MSG_HACK, "ProcessNet.MessagePump_ProcessReceive(...){0}", Thread.CurrentThread.Name);

            if (eventArgs.NetState == null)
            {
                Debug.WriteLine("ProcessNet.EventDelegateProcessReceive(...) - netState == null error!");
                return;
            }

            ReceiveQueue l_ReceiveQueueBuffer = eventArgs.NetState.ReceiveBuffer;

            if (l_ReceiveQueueBuffer == null)
            {
                Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - byteQueueBuffer == null error!");
                return;
            }

            LOGs.WriteLine(LogMessageType.MSG_HACK, "ProcessNet.MessagePump_ProcessReceive(...)-Length={0},{1}", l_ReceiveQueueBuffer.Length, Thread.CurrentThread.Name);

            if (l_ReceiveQueueBuffer.Length < PACKAGE_HEAD)
            {
                                                              // 等待数据包的完整
                return;
            }

            long l_iReceiveBufferLength = l_ReceiveQueueBuffer.Length; // 隔段时间就会有数据过来,所以可以不用锁定的,锁定了也没用,很难保证多线程中处理了所有的数据

            while (l_iReceiveBufferLength >= PACKAGE_HEAD)
            {
                // ReceiveQueue内部已经有锁定
                long l_iPacketSize = l_ReceiveQueueBuffer.GetPacketLength();
                if (l_iPacketSize < PACKAGE_HEAD)
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - iPacketSize <= 0 error!");

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                if (l_iReceiveBufferLength < l_iPacketSize)
                {
                                                              // 等待数据包的完整
                    break;
                }

                if (l_iPacketSize > BUFFER_SIZE)   // 数据包过大
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - iPacketSize > BUFFER_SIZE error!");

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                // 获取空数据
                byte[] l_PacketBuffer = m_ProcessorBuffers.AcquireBuffer();

                // ReceiveQueue内部已经有锁定
                long l_iReturnPacketSize = l_ReceiveQueueBuffer.Dequeue(ref l_PacketBuffer, 0, l_iPacketSize);

                // 获取的数据不相同
                if (l_iReturnPacketSize != l_iPacketSize)
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - iReturnPacketSize != iPacketSize error!");

                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                //////////////////////////////////////////////////////////////////////////
                using (StreamWriter streamWriter = new StreamWriter("PreIn_Packets.log", true))
                {
                    byte[] byteBuffer = l_PacketBuffer;

                    if (byteBuffer.Length > 0)
                    {
                        streamWriter.WriteLine("客户端:  {0}  未经解密过的信息包 长度 = 0x{1:X4} ID = Unknown", eventArgs.NetState, l_iPacketSize);
                        streamWriter.WriteLine("--------------------------------------------------------------------------");
                    }

                    using (MemoryStream memoryStream = new MemoryStream(byteBuffer))
                        Utility.FormatBuffer(streamWriter, memoryStream, l_iPacketSize);

                    streamWriter.WriteLine();
                    streamWriter.WriteLine();
                }
                //////////////////////////////////////////////////////////////////////////

                try
                {
                    // 解密数据包
                    ROSECrypt.CryptPacket(ref l_PacketBuffer, eventArgs.NetState.EncoderSeed);
                }
                catch
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - ROSECrypt.CryptPacket(...) Exception error!");

                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                // 读取的数据包
                PacketReader l_PacketReader = new PacketReader(l_PacketBuffer, l_iPacketSize, PACKAGE_HEAD /*包的长度大小-2个字节、ID大小-2个字节、未用数据大小-2个字节, 6个字节跳过*/);

                //////////////////////////////////////////////////////////////////////////
                using (StreamWriter streamWriter = new StreamWriter("In_Packets.log", true))
                {
                    byte[] byteBuffer = l_PacketBuffer;

                    if (byteBuffer.Length > 0)
                    {
                        streamWriter.WriteLine("客户端:  {0}  经解密过的信息包 长度 = 0x{1:X4} ID = 0x{2:X4}", eventArgs.NetState, l_iPacketSize, l_PacketReader.GetPacketID());
                        streamWriter.WriteLine("--------------------------------------------------------------------------");
                    }

                    using (MemoryStream memoryStream = new MemoryStream(byteBuffer))
                        Utility.FormatBuffer(streamWriter, memoryStream, l_iPacketSize);

                    streamWriter.WriteLine();
                    streamWriter.WriteLine();
                }
                //////////////////////////////////////////////////////////////////////////

                // 获取数据包命令的ID
                long l_iPacketID = l_PacketReader.GetPacketID();

                LOGs.WriteLine(LogMessageType.MSG_HACK, "ProcessNet.MessagePump_ProcessReceive(...)-Packet ID = 0x{0:X4}", l_iPacketID);

                // 获取处理数据包的实例
                PacketHandler l_PacketHandler = PacketHandlers.GetHandler(l_iPacketID);
                if (l_PacketHandler == null)   // 说明还没有解开当前的数据包内容
                {
                    l_PacketReader.Trace(eventArgs.NetState);

                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    // 获取剩下的数据长度
                    l_iReceiveBufferLength = l_ReceiveQueueBuffer.Length;

                    continue;
                }

                // 当前需处理的数据包的大小
                long l_iPacketHandlerLength = l_PacketHandler.Length;
                if (l_iPacketHandlerLength > l_iReturnPacketSize)   // 包需求的数据大小大于得到的数据大小
                {
                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                PacketProfile l_PacketProfile = PacketProfile.GetIncomingProfile(l_iPacketID);
                DateTime      dateTimeStart   = (l_PacketProfile == null ? DateTime.MinValue : DateTime.Now);
                {
                    l_PacketHandler.OnReceive(eventArgs.NetState, l_PacketReader);
                }
                if (l_PacketProfile != null)
                {
                    l_PacketProfile.Record(l_iPacketHandlerLength, DateTime.Now - dateTimeStart);
                }

                // 返回内存池
                m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                // 获取剩下的数据长度
                l_iReceiveBufferLength = l_ReceiveQueueBuffer.Length;
            }
        }
        public static void OpCode(Decode state, Client ed)
        {
            try
            {
                LogConsole.Show(LogType.DEBUG, "OpCode()");
                Systems sys = (Systems)state.Packet;
                sys.PacketInformation = state;

                ByteQueue queue = ed.queue;

                int length = queue.Length;
                LogConsole.Show(LogType.DEBUG, "OpCode() {0}", length);
                while ((length > 0))
                {
                    byte[] buffer;
                    int    packetID          = queue.GetPacketID();
                    int    packetLength      = queue.GetPacketLength();
                    int    packetControlCode = queue.GetPacketControlCode();

                    LogConsole.Show(LogType.DEBUG, "PacketControl: {0} PacketID: 0x{1:X2} Length: {2}", packetControlCode, packetID, packetLength);
                    LogConsole.HexDump(state.buffer, "", 16);

                    PacketHandler handler = PacketHandlers.GetHandler(packetID);
                    if (handler == null)
                    {
                        byte[] buffer2 = new byte[length];
                        length = queue.Dequeue(buffer2, 0, length);
                        LogConsole.Show(LogType.DEBUG, "Client: {0}: Unhandled packet 0x{1:X2}", new object[] { state, packetID });
                        break;
                    }

                    int size = handler.Length;
                    if (length >= 4)
                    {
                        size = packetLength;
                        if (packetLength >= 4)
                        {
                            if (length < size)
                            {
                                break;
                            }

                            if (0x400 >= size)
                            {
                                buffer = m_Buffers.AquireBuffer();
                            }
                            else
                            {
                                buffer = new byte[size];
                            }

                            size = queue.Dequeue(buffer, 0, size);

                            ushort packetid = ByteQueue.GetPacketID(buffer);

                            bool flag = IsCrypted(packetid);
                            if (flag)
                            {
                                LogConsole.Show(LogType.DEBUG, "Crypted Packet 0x{0:X4}", new object[] { packetid });
                            }

                            try
                            {
                                PacketReader2 pr = new PacketReader2(buffer, size);
                                handler.OnReceive(ed, pr);
                            }
                            catch { break; }

                            length = queue.Length;
                            if ((0x400 >= size) && !flag)
                            {
                                m_Buffers.ReleaseBuffer(buffer);
                                break;
                            }
                        }
                    }

                    length = 0;
                }
            }
            catch (Exception)
            {
            }
        }