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


C# PacketReader.ReadBytes方法代码示例

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


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

示例1: Recv


//.........这里部分代码省略.........
                            if (m_security_flags.security_bytes == 1)
                            {
                                byte expected_count = GenerateCountByte(true);
                                if (packet_security_count != expected_count)
                                {
                                    //throw (new Exception("[SecurityAPI::Recv] Count byte mismatch on {packet_opcode.ToString("X4")}."));
                                    StaticLogger.Instance.Warn($"[SecurityAPI::Recv] Count byte mismatch on {packet_opcode.ToString("X4")}. (Expected: {expected_count}, Packet: {packet_security_count})");
                                }

                                if (packet_encrypted || (m_security_flags.security_bytes == 1 && m_security_flags.blowfish == 0))
                                {
                                    if (packet_encrypted || m_enc_opcodes.Contains(packet_opcode))
                                    {
                                        packet_size |= 0x8000;
                                        Buffer.BlockCopy(BitConverter.GetBytes((ushort)packet_size), 0, buffer.Buffer, 0, 2);
                                    }
                                }

                                buffer.Buffer[5] = 0;

                                byte expected_crc = GenerateCheckByte(buffer.Buffer);
                                if (packet_security_crc != expected_crc)
                                {
                                    //throw (new Exception("[SecurityAPI::Recv] CRC byte mismatch."));
                                    StaticLogger.Instance.Warn($"[SecurityAPI::Recv] CRC byte mismatch on {packet_opcode.ToString("X4")}. (Expected: {expected_crc}, Packet: {packet_security_crc})");
                                }

                                buffer.Buffer[4] = 0;

                                if (packet_encrypted || (m_security_flags.security_bytes == 1 && m_security_flags.blowfish == 0))
                                {
                                    if (packet_encrypted || m_enc_opcodes.Contains(packet_opcode))
                                    {
                                        packet_size &= 0x7FFF;
                                        Buffer.BlockCopy(BitConverter.GetBytes((ushort)packet_size), 0, buffer.Buffer, 0, 2);
                                    }
                                }
                            }
                        }

                        if (packet_opcode == 0x5000 || packet_opcode == 0x9000) // New logic processing!
                        {
                            Handshake(packet_opcode, packet_data, packet_encrypted);

                            // Pass the handshake packets to the user so they can at least see them.
                            // They do not need to actually do anything with them. This was added to
                            // help debugging and make output logs complete.

                            Packet packet = new Packet(packet_opcode, packet_encrypted, false, buffer.Buffer, 6, packet_size);
                            packet.Lock();
                            m_incoming_packets.Add(packet);
                        }
                        else
                        {
                            if (m_client_security)
                            {
                                // Make sure the client accepted the security system first
                                if (!m_accepted_handshake)
                                {
                                    throw (new Exception("[SecurityAPI::Recv] The client has not accepted the handshake."));
                                }
                            }

                            if (packet_opcode == 0x600D) // Auto process massive messages for the user
                            {
                                byte mode = packet_data.ReadByte();
                                if (mode == 1)
                                {
                                    m_massive_count = packet_data.ReadUInt16();
                                    ushort contained_packet_opcode = packet_data.ReadUInt16();
                                    m_massive_packet = new Packet(contained_packet_opcode, packet_encrypted, true);
                                }
                                else
                                {
                                    if (m_massive_packet == null)
                                    {
                                        throw (new Exception("[SecurityAPI::Recv] A malformed 0x600D packet was received."));
                                    }
                                    m_massive_packet.WriteByteArray(packet_data.ReadBytes(packet_size - 1));
                                    m_massive_count--;

                                    if (m_massive_count == 0)
                                    {
                                        m_massive_packet.Lock();
                                        m_incoming_packets.Add(m_massive_packet);
                                        m_massive_packet = null;
                                    }
                                }
                            }
                            else
                            {
                                Packet packet = new Packet(packet_opcode, packet_encrypted, false, buffer.Buffer, 6, packet_size);
                                packet.Lock();
                                m_incoming_packets.Add(packet);
                            }
                        }
                    }
                }
            }
        }
开发者ID:GoneUp,项目名称:ModuleFilter,代码行数:101,代码来源:SecurityManager.cs

示例2: Read

 public override void Read(PacketReader reader)
 {
     SharedSecretLength = reader.ReadShort();
     SharedSecret = reader.ReadBytes(SharedSecretLength);
     VerifyTokenLength = reader.ReadShort();
     VerifyToken = reader.ReadBytes(VerifyTokenLength);
 }
开发者ID:OBASI,项目名称:c-raft,代码行数:7,代码来源:Packet.cs

示例3: Read

 public override void Read(PacketReader stream)
 {
     UnknownConstantValue = stream.ReadShort();
     UnknownMapId = stream.ReadShort();
     TextLength = stream.ReadByte();
     Text = stream.ReadBytes(TextLength);
 }
开发者ID:dekema2,项目名称:c-raft,代码行数:7,代码来源:Packet.cs


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