当前位置: 首页>>代码示例>>C#>>正文


C# PacketReader.Trace方法代码示例

本文整理汇总了C#中System.IO.PacketReader.Trace方法的典型用法代码示例。如果您正苦于以下问题:C# PacketReader.Trace方法的具体用法?C# PacketReader.Trace怎么用?C# PacketReader.Trace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.PacketReader的用法示例。


在下文中一共展示了PacketReader.Trace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MessagePump_ProcessReceive


//.........这里部分代码省略.........
                    Debug.WriteLine( "ProcessNet.MessagePump_ProcessReceive(...) - ROSECrypt.CryptPacket(...) Exception error!" );

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

                    eventArgs.NetState.Dispose( true ); // 断开
                    //Utility.Free( netState.ReceiveBuffer );
                    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( true ); // 断开
                    //Utility.Free( netState.ReceiveBuffer );
                    return;
                }

                //ThrottlePacketCallback l_ThrottlePacketCallback = l_PacketHandler.ThrottleCallback;
                //if ( l_ThrottlePacketCallback != null )
                //{
                //    if ( l_ThrottlePacketCallback( netState ) == false )
                //    {
                //        Monitor.Enter( m_LockNetStateThrottled );
                //        {
                //            m_NetStateThrottled.Enqueue( netState );
                //        }
                //        Monitor.Exit( m_LockNetStateThrottled );

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

                //        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;
            }

            //Utility.Free( netState.ReceiveBuffer );
        }
开发者ID:andyhebear,项目名称:HappyQ-WowServer,代码行数:101,代码来源:ProcessNet.cs


注:本文中的System.IO.PacketReader.Trace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。