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


C# GSPacketIn.ReadHeader方法代码示例

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


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

示例1: ReadPacket_

 public GSPacketIn ReadPacket_()
 {
     byte[] buffer = ReadBytes();
     GSPacketIn pkg = new GSPacketIn(buffer, buffer.Length);
     pkg.ReadHeader();
     return pkg;
 }
开发者ID:vancourt,项目名称:BaseGunnyII,代码行数:7,代码来源:GSPacketIn.cs

示例2: Clone

 public GSPacketIn Clone()
 {
     GSPacketIn pkg = new GSPacketIn(m_buffer, m_length);
     pkg.ReadHeader();
     pkg.Offset = m_length;
     return pkg;
 }
开发者ID:vancourt,项目名称:BaseGunnyII,代码行数:7,代码来源:GSPacketIn.cs

示例3: ReadPacket

 public GSPacketIn ReadPacket()
 {
     int maxLen = this.ReadShort();
     byte[] buf = this.ReadBytes(maxLen);
     buf[0] = 113;
     buf[1] = 172;
     GSPacketIn pkg = new GSPacketIn(buf, maxLen);
     pkg.ReadHeader();
     if (pkg.Length != maxLen)
     {
         throw new Exception(string.Format("Error packet in ReadPacket,data length didn't equal packet length, data:{0}, packet:{1}", maxLen, pkg.Length));
     }
     return pkg;
 }
开发者ID:vancourt,项目名称:BaseGunnyII,代码行数:14,代码来源:GSPacketIn.cs

示例4: ReceiveBytes


//.........这里部分代码省略.........
                    //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
                    {
                        pkg.CopyFrom(buffer, curOffset, 0, packetLength);
                    }
                    pkg.ReadHeader();

                    log.Debug((Marshal.ToHexDump("Recieve Packet:", pkg.Buffer, 0, packetLength)));
                    try
                    {
                        m_client.OnRecvPacket(pkg);
                    }
                    catch (Exception e)
                    {
                        if (log.IsErrorEnabled)
                            log.Error("HandlePacket(pak)", e);
                    }

                    curOffset += packetLength;

                } while (bufferSize - 1 > curOffset);

                if (bufferSize - 1 == curOffset)
                {
                    buffer[0] = buffer[curOffset];
                    m_client.PacketBufSize = 1;
                }
            }
        }
开发者ID:vancourt,项目名称:BaseGunnyII,代码行数:101,代码来源:StreamProcessor.cs


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