Beispiel #1
0
        public static StreamBuffer GetPacketBufferWithHeader(ref RawStreamBuffer cReceiveBuffer)
        {
            try
            {
                ProtocolHeader pHeader = Packing.GetPacketHeader(cReceiveBuffer.ByteBuffer, cReceiveBuffer.ReadIndex, cReceiveBuffer.WriteIndex);
                if (pHeader != null)
                {
                    if (pHeader.BodyLength > 0)
                    {
                        if ((pHeader.BodyLength + ProtocolHeader.HeadLength) <= (cReceiveBuffer.WriteIndex - cReceiveBuffer.ReadIndex))
                        {
                            byte[] buffer = cReceiveBuffer.Read(pHeader.BodyLength, ProtocolHeader.HeadLength);
                            if (buffer != null)
                            {
                                StreamBuffer sb = new StreamBuffer(pHeader, buffer);
                                return(sb);
                            }
                        }
                    }
                    else if (pHeader.BodyLength == 0)
                    {
                        cReceiveBuffer.Read(ProtocolHeader.HeadLength);
                        StreamBuffer sb = new StreamBuffer(pHeader.ProtocolID, 0);
                        return(sb);
                    }
                }
            }
            catch (Exception e)
            {
                WriteFiles.WritFile.Log(e);
            }

            return(null);
        }
Beispiel #2
0
        public static StreamBuffer GetPacketBuffer(ref StreamBuffer cReceiveBuffer)
        {
            try
            {
                int bufferSize = Packing.GetPacketSize(cReceiveBuffer.ByteBuffer, cReceiveBuffer.ReadIndex, cReceiveBuffer.WriteIndex);
                if (bufferSize > 0 && (bufferSize + GetPacketHeadSize()) <= (cReceiveBuffer.WriteIndex - cReceiveBuffer.ReadIndex))
                {
                    int    protocolID = BitConverter.ToInt32(cReceiveBuffer.ByteBuffer, GetPacketHeadSize());
                    byte[] buffer     = cReceiveBuffer.Read(bufferSize - sizeof(int), GetPacketHeadSize() + sizeof(int));
                    if (buffer != null)
                    {
                        StreamBuffer sb = new StreamBuffer(protocolID, buffer);
                        return(sb);
                    }
                }
            }
            catch (Exception e)
            {
                WriteFiles.WritFile.Log(e);
            }

            return(null);
        }
Beispiel #3
0
 /// <summary>
 /// 打包解密
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="len"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public static byte[] PackingDecode(byte[] buffer, int len)
 {
     CEncrypt.Decoding(ref buffer, Packing.GetPacketHeadSize(), CEncrypt.GAMESERVER_TO_CLIENT_KEY, 0, len);
     return(buffer);
 }