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


C# GSPacketIn.CopyFrom方法代码示例

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


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

示例1: ReceiveBytes

        /// <summary>
        /// Called when the client receives bytes
        /// </summary>
        /// <param name="numBytes">The number of bytes received</param>
        public void ReceiveBytes(int numBytes)
        {
            lock (this)
            {
                byte[] buffer = m_client.PacketBuf;

                //End Offset of buffer
                int bufferSize = m_client.PacketBufSize + numBytes;
                //log.Debug(Marshal.ToHexDump("Recieve:", buffer, 0, bufferSize));
                //Size < minimum
                if (bufferSize < GSPacketIn.HDR_SIZE)
                {
                    m_client.PacketBufSize = bufferSize; // undo buffer read
                    return;
                }
                //Reset the offset
                m_client.PacketBufSize = 0;

                int curOffset = 0;

                do
                {
                    //read buffer length
                    int packetLength = 0;
                    int header = 0;
                    if (m_client.Encryted)
                    {
                        //int key = receive_fsm.getState();
                        int i = receive_fsm.count;
                        //key = (key & (0xff << 16)) >> 16;
                        byte[] tempKey = cloneArrary(m_client.RECEIVE_KEY);
                        while (curOffset + 4 < bufferSize)
                        {
                            byte[] tempBuffer = decryptBytes(buffer,curOffset, 8, tempKey);
                            header = ((byte)(tempBuffer[0] ) << 8) + (byte)(tempBuffer[1]);
                            if (header == GSPacketIn.HEADER)
                            {
                                packetLength = ((byte)(tempBuffer[2]) << 8) + (byte)(tempBuffer[3]);
                                break;
                            }
                            else
                            {
                                curOffset++;
                            }
                        }

                        //decryptBytes(buffer,

                    }
                    else
                    {
                        while(curOffset + 4 < bufferSize)
                        {
                            header = (buffer[curOffset] << 8) + buffer[curOffset + 1];
                            if (header == GSPacketIn.HEADER)
                            {
                                packetLength = (buffer[curOffset + 2] << 8) + buffer[curOffset + 3];
                                break;
                            }
                            else
                            {
                                curOffset++;
                            }
                        }
                    }

                    if ((packetLength != 0 && packetLength < GSPacketIn.HDR_SIZE) || packetLength > 2048)
                    {
                        log.Error("packetLength:" + packetLength + ",GSPacketIn.HDR_SIZE:" + GSPacketIn.HDR_SIZE + ",offset:" + curOffset + ",bufferSize:" + bufferSize + ",numBytes:" + numBytes);
                        log.ErrorFormat("Err pkg from {0}:", m_client.TcpEndpoint);
                        log.Error(Marshal.ToHexDump("===> error buffer", buffer));
                        m_client.PacketBufSize = 0;
                        if (m_client.Strict)
                        {
                            m_client.Disconnect();
                        }
                        return;
                    }

                    int dataLeft = bufferSize - curOffset;
                    if (dataLeft < packetLength || packetLength == 0)
                    {
                        Array.Copy(buffer, curOffset, buffer, 0, dataLeft);
                        m_client.PacketBufSize = dataLeft;
                        break;
                    }

                    GSPacketIn pkg = new GSPacketIn(new byte[2048],2048);
                    if (m_client.Encryted)
                    {
                       // pkg.CopyFrom(buffer, curOffset, 0, packetLength, receive_fsm.getState());
                         pkg.CopyFrom3(buffer, curOffset, 0, packetLength, m_client.RECEIVE_KEY);
                        //receive_fsm.UpdateState();
                    }
                    else
                    {
//.........这里部分代码省略.........
开发者ID:vancourt,项目名称:BaseGunnyII,代码行数:101,代码来源:StreamProcessor.cs


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