예제 #1
0
 public Segment(int size)
 {
     if (KCPLib.BufferAlloc != null)
     {
         this.data = new ArraySegment <byte>(KCPLib.BufferAlloc(size), 0, size);
     }
     else
     {
         this.data = new ArraySegment <byte>(new byte[size], 0, size);
     }
 }
예제 #2
0
        /// <summary>
        /// 是否是正确的握手响应
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="size"></param>
        /// <param name="index"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        internal static bool IsHandshakeDataRight(byte[] buffer, int offset, int size, out uint index, out uint key)
        {
            index = 0;
            key   = 0;
            if (size < UdpLibConfig.HandshakeDataSize)
            {
                return(false);
            }
            for (int i = 0; i < UdpLibConfig.HandshakeHeadData.Length; i++)
            {
                if (buffer[offset + i] != UdpLibConfig.HandshakeHeadData[i])
                {
                    return(false);
                }
            }

            KCPLib.ikcp_decode32u(buffer, offset + UdpLibConfig.HandshakeHeadData.Length, ref index);
            KCPLib.ikcp_decode32u(buffer, offset + UdpLibConfig.HandshakeHeadData.Length + 4, ref key);
            return(true);
        }