Exemplo n.º 1
0
        /// <summary>
        /// 处理filehash
        /// 保存列表文件并且发送列表
        /// </summary>
        /// <param name="package"></param>
        /// <param name="write"></param>
        /// <returns></returns>
        private bool FileHashHandle(PackagePlugin package, BinaryWriter toClientWriter, BinaryWriter toServerWriter)
        {
            if (LocalData == null)
            {
                using (MemoryStream ms = new MemoryStream(package.ChannelData, 1, package.ChannelData.Length - 1))
                {
                    using (BinaryReader br = new BinaryReader(ms))
                    {
                        // 0-2: gziplength
                        // 2-~: data
                        ushort gzipLength = br.ReadUInt16BE();
                        byte[] gzipdata   = br.ReadBytes(gzipLength);
                        // 0: salt
                        // 1-~: hashlist
                        byte[] unzipdata = GzipUtil.Decompress(gzipdata);
                        byte[] hashs     = new byte[unzipdata.Length - 1];
                        Array.Copy(unzipdata, 1, hashs, 0, hashs.Length);

                        CatAntiCheatData local = new CatAntiCheatData
                        {
                            Version       = version,
                            FileHashBytes = hashs
                        };

                        SerializeUtil.SerializeToFile(fileName, local);
                    }
                }
                Console.WriteLine($"[CatAntiCheat]本地文件[{fileName}]不存在, 创建完成");
            }
            LocalData = SerializeUtil.DeserializeFromFile <CatAntiCheatData>(fileName);

            return(false);
        }
        public byte[] GetRawData()
        {
            Stream networkStream = stream;

            if (this.rawData != null)
            {
                return(this.rawData);
            }

            Collection <byte> content = new Collection <byte>();

            if (commonHeaders.Keys.Contains("Transfer-Encoding") &&
                commonHeaders["Transfer-Encoding"].Equals("chunked"))
            {
                content = ReadChunks();
            }
            else
            {
                byte[] temContent = new byte[10];
                while (true)
                {
                    int temLength = networkStream.Read(temContent, 0, temContent.Length);
                    streamIndex += temLength;
                    for (int i = 0; i < temLength; i++)
                    {
                        copiedStream.WriteByte(temContent[i]);
                        content.Add(temContent[i]);
                    }
                    if (temLength != temContent.Length)
                    {
                        break;
                    }
                }
                temContent = null;
            }

            byte[] rawData          = content.ToArray();
            byte[] decompressedData = null;

            if (commonHeaders.Keys.Contains("Content-Encoding") &&
                commonHeaders["Content-Encoding"].Equals("gzip"))
            {
                decompressedData = GzipUtil.Decompress(rawData);
            }
            else
            {
                decompressedData = rawData;
            }

            this.rawData = decompressedData;
            return(this.rawData);
        }