示例#1
0
        protected virtual void ParseHeader(IAsyncResult ar)
        {
            if (!EndRead(ar))
            {
                return;
            }

            uint recvChecksum = InMessage.GetUInt32(); //Adler Checksum
            uint checksum     = Tools.AdlerChecksum(InMessage.Buffer, InMessage.Position, InMessage.Length - 6);

            if (checksum != recvChecksum)
            {
                InMessage.SkipBytes(-4);
            }

            if (!IsFirstMessageReceived)
            {
                IsFirstMessageReceived = true;
                ProcessFirstMessage(checksum == recvChecksum);
            }
            else
            {
                if (IsEncryptionEnabled && !InMessage.XteaDecrypt(XteaKey))
                {
                    return;
                }

                ProcessMessage();
            }
        }