예제 #1
0
        private void HandleBatchPacket(BatchPacket packet)
        {
            byte[] data = CompressionManager.DecompressionZlib(new BinaryStream(packet.Payload), true);
            using (NetworkStream stream = new NetworkStream(data))
            {
                while (!stream.IsEndOfStream())
                {
                    int    len     = stream.ReadVarInt();
                    byte[] payload = stream.ReadBytes(len);
                    _logger.Info(payload[0].ToString("X"));

                    DataPacket pk = Protocol.GetDefinedPacket(payload[0]).ValueOrFailure();

                    pk.SetBuffer(payload);

                    pk.DecodeHeader();
                    pk.DecodePayload();

                    _players.TryGetValue(packet.EndPoint, out IServerPlayer player);
                    player?.HandleDataPacket(pk);
                }
            }

            packet.Dispose();
        }
예제 #2
0
        public void ZlibTest()
        {
            BinaryStream stream = new BinaryStream();

            stream.WriteStringUtf8("abcdefg");

            byte[]       compressionZlib = CompressionManager.CompressionZlib(stream, CompressionLevel.Fastest, true);
            BinaryStream stream2         = new BinaryStream(compressionZlib);

            byte[]       decompressionZlib = CompressionManager.DecompressionZlib(stream2, true);
            BinaryStream stream3           = new BinaryStream(decompressionZlib);

            Assert.True(stream3.ReadStringUtf8() == "abcdefg");
        }