public void PacketReceived(Packet packet)
        {
            if (packet is SendPathContentPacket) //controller
            {
                var path = ((SendPathContentPacket)packet).Path;
                var pathListing = ((SendPathContentPacket)packet).PathListing;

                CurrentDictionary = path;
                PathContentReceived(this, new PathContentEventArgs(path, pathListing));
            }
            else if (packet is SendFilePacket) //controller
            {
                var filePacket = (SendFilePacket)packet;
                
                var path = Path.GetTempPath() + Path.GetFileNameWithoutExtension(filePacket.Path) + ".txt";
                if (filePacket.Count == 0) //Mindfuck? No it is just magic numbers saying it is done :D
                {
                    Process.Start(path);
                }
                else
                {
                    using (var fileStream = File.Open(path, filePacket.Offset == 0 ? FileMode.Create : FileMode.Append))
                    {
                        fileStream.Write(filePacket.Content, 0, (int) filePacket.Count);
                    }
                }
            }
        }
Exemple #2
0
        public void SendPacket(Packet packet)
        {
            if (packet == null) return;
            WriteByte(packet.Id);
            WriteInt((int)packet.Size);

            packet.WritePacket(this);

            //PacketSent(this, new PacketEventArgs(this, packet));
        }
Exemple #3
0
        public void PacketReceived(Packet packet)
        {
            if (packet is AckScreensharePacket)
            {
                var ackPacket = (AckScreensharePacket) packet;

                Blocks = ackPacket.Blocks;
                BlockSize = ackPacket.BlockSize;

                _blockHashes = new Dictionary<Point, uint>(Blocks.Height * Blocks.Width);
                Acknowledged(this, EventArgs.Empty);
                
                for (var x = 0; x < Blocks.Width; x++)
                {
                    for (var y = 0; y < Blocks.Height; y++)
                    {
                        var point = new Point(x, y);
                        _blockHashes[point] = uint.MaxValue;
                    }
                }

                var random = new Random();
               // foreach (var block in _blockHashes.OrderBy(x => random.Next()).Select(x => x.Key))
               //     RequestBlock(block, Quality);
            }
            else if (packet is SendScreenshotBlockPacket)
            {
                var blockPacket = (SendScreenshotBlockPacket) packet;
                ++_frames;
                if (blockPacket.Image == null) //Same image
                {
                    RequestBlock(blockPacket.Block, Quality);
                    return;
                }

                Trace.WriteLine(String.Format("Compressed: {0}", blockPacket.Compressed));
                var frame = (Bitmap)blockPacket.Image.Clone();
                
                FrameUpdated(this, new DesktopEventArgs(frame, blockPacket.Block));
                blockPacket.Image.Dispose();

                _blockHashes[blockPacket.Block] = blockPacket.BlockHash;

               // RequestBlock(blockPacket.Block, Quality);
            }
        }
Exemple #4
0
        /// <summary>
        /// Only the Id is written asynchronously!!
        /// </summary>
        public async Task SendPacketAsync(Packet packet)
        {
            await WriteByteAsync(packet.Id);
            WriteInt((int) packet.Size);

            packet.WritePacket(this);

            //PacketSent(this, new PacketEventArgs(this, packet));
        }
 public PacketEventArgs(Client client, Packet packet)
 {
     Client = client;
     Packet = packet;
 }