scheduler almost done, need Save & Load implementation

This commit is contained in:
sirjonasxx 2018-06-14 01:39:54 +02:00
parent 1204666dd8
commit 19c7643519
8 changed files with 106 additions and 14 deletions

View File

@ -1,4 +1,4 @@
package main; package main.misc;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;

View File

@ -1,4 +1,4 @@
package main; package main.misc;
public class OSValidator { public class OSValidator {

View File

@ -0,0 +1,15 @@
package main.misc;
/**
* Created by Jonas on 14/06/18.
* This interface defines an object which can FULLY be represented as a String (all fields). An object must be able to be recreated having the String representation
*/
public interface StringifyAble {
String stringify();
//the object before calling this function will typically have no real point, this is some kind of constructor
// (this implies that the Object should probably have a constructor just calling this function)
void constructFromString(String str);
}

View File

@ -1,6 +1,6 @@
package main.protocol.hostreplacer; package main.protocol.hostreplacer;
import main.OSValidator; import main.misc.OSValidator;
/** /**
* Created by Jonas on 04/04/18. * Created by Jonas on 04/04/18.

View File

@ -1,6 +1,6 @@
package main.protocol.memory.habboclient; package main.protocol.memory.habboclient;
import main.OSValidator; import main.misc.OSValidator;
import main.protocol.memory.habboclient.linux.LinuxHabboClient; import main.protocol.memory.habboclient.linux.LinuxHabboClient;
/** /**

View File

@ -4,6 +4,7 @@ import javafx.beans.InvalidationListener;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import main.misc.StringifyAble;
import main.protocol.HMessage; import main.protocol.HMessage;
import main.protocol.HPacket; import main.protocol.HPacket;
@ -13,15 +14,19 @@ import java.util.List;
/** /**
* Created by Jonas on 07/04/18. * Created by Jonas on 07/04/18.
*/ */
public class ScheduleItem { public class ScheduleItem implements StringifyAble {
private SimpleIntegerProperty indexProperty; private SimpleIntegerProperty indexProperty = null;
private SimpleBooleanProperty pausedProperty; private SimpleBooleanProperty pausedProperty = null;
private SimpleObjectProperty<Interval> delayProperty; private SimpleObjectProperty<Interval> delayProperty = null;
private SimpleObjectProperty<HPacket> packetProperty; private SimpleObjectProperty<HPacket> packetProperty = null;
private SimpleObjectProperty<HMessage.Side> destinationProperty; private SimpleObjectProperty<HMessage.Side> destinationProperty = null;
ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Side destination) { ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Side destination) {
construct(index, paused, delay, packet, destination);
}
private void construct(int index, boolean paused, Interval delay, HPacket packet, HMessage.Side destination) {
this.indexProperty = new SimpleIntegerProperty(index); this.indexProperty = new SimpleIntegerProperty(index);
this.pausedProperty = new SimpleBooleanProperty(paused); this.pausedProperty = new SimpleBooleanProperty(paused);
this.delayProperty = new SimpleObjectProperty<>(delay); this.delayProperty = new SimpleObjectProperty<>(delay);
@ -29,6 +34,10 @@ public class ScheduleItem {
this.destinationProperty = new SimpleObjectProperty<>(destination); this.destinationProperty = new SimpleObjectProperty<>(destination);
} }
ScheduleItem(String stringifyAbleRepresentation) {
constructFromString(stringifyAbleRepresentation);
}
public SimpleIntegerProperty getIndexProperty() { public SimpleIntegerProperty getIndexProperty() {
return indexProperty; return indexProperty;
} }
@ -90,4 +99,33 @@ public class ScheduleItem {
} }
} }
@Override
public String stringify() {
StringBuilder b = new StringBuilder();
b .append(indexProperty.get())
.append("\t")
.append(pausedProperty.get() ? "true" : "false")
.append("\t")
.append(delayProperty.get().toString())
.append("\t")
.append(packetProperty.get().toString())
.append("\t")
.append(destinationProperty.get().name());
return b.toString();
}
@Override
public void constructFromString(String str) {
String[] parts = str.split("\t");
if (parts.length == 5) {
int index = Integer.parseInt(parts[0]);
boolean paused = parts[1].equals("true");
Interval delay = new Interval(parts[2]);
HPacket packet = new HPacket(parts[3]);
HMessage.Side side = parts[4].equals(HMessage.Side.TOSERVER.name()) ? HMessage.Side.TOSERVER : HMessage.Side.TOCLIENT;
construct(index, paused, delay, packet, side);
}
}
} }

View File

@ -65,10 +65,13 @@
<Insets bottom="10.0" left="17.0" right="17.0" /> <Insets bottom="10.0" left="17.0" right="17.0" />
</GridPane.margin> </GridPane.margin>
<children> <children>
<GridPane> <GridPane hgap="7.0">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="63.0" minWidth="10.0" prefWidth="63.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="63.0" minWidth="63.0" prefWidth="63.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="468.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="468.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="70.0" prefWidth="70.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="35.0" prefWidth="35.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="35.0" prefWidth="35.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
@ -76,7 +79,7 @@
<children> <children>
<TextField fx:id="txt_packet" text="[0][0][0][2][0][0]" GridPane.columnIndex="1"> <TextField fx:id="txt_packet" text="[0][0][0][2][0][0]" GridPane.columnIndex="1">
<GridPane.margin> <GridPane.margin>
<Insets /> <Insets left="-7.0" />
</GridPane.margin> </GridPane.margin>
</TextField> </TextField>
<Label maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Packet:" textFill="#000000bb"> <Label maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Packet:" textFill="#000000bb">
@ -84,6 +87,9 @@
<Insets left="3.0" /> <Insets left="3.0" />
</GridPane.margin> </GridPane.margin>
</Label> </Label>
<Button fx:id="btn_clear" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#clearBtnClicked" text="Clear" GridPane.columnIndex="2" />
<Button fx:id="btn_save" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#saveBtnClicked" text="S" GridPane.columnIndex="3" />
<Button fx:id="btn_load" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#loadBtnClicked" text="L" GridPane.columnIndex="4" />
</children> </children>
</GridPane> </GridPane>
<GridPane prefHeight="33.0" prefWidth="502.0" GridPane.rowIndex="1"> <GridPane prefHeight="33.0" prefWidth="502.0" GridPane.rowIndex="1">

View File

@ -36,6 +36,10 @@ public class Scheduler extends SubForm {
public RadioButton rb_incoming; public RadioButton rb_incoming;
public RadioButton rb_outgoing; public RadioButton rb_outgoing;
public Button btn_clear;
public Button btn_save;
public Button btn_load;
private ScheduleItem isBeingEdited = null; private ScheduleItem isBeingEdited = null;
private List<ScheduleItem> scheduleItemList = new ArrayList<>(); private List<ScheduleItem> scheduleItemList = new ArrayList<>();
@ -48,6 +52,10 @@ public class Scheduler extends SubForm {
txt_packet.textProperty().addListener(event -> Platform.runLater(this::updateUI)); txt_packet.textProperty().addListener(event -> Platform.runLater(this::updateUI));
txt_delay.textProperty().addListener(event -> Platform.runLater(this::updateUI)); txt_delay.textProperty().addListener(event -> Platform.runLater(this::updateUI));
btn_clear.setTooltip(new Tooltip("Clear all items"));
btn_save.setTooltip(new Tooltip("Save to file"));
btn_load.setTooltip(new Tooltip("Load from file"));
updateUI(); updateUI();
new Thread(() -> { new Thread(() -> {
@ -73,7 +81,7 @@ public class Scheduler extends SubForm {
Interval cur = item.getDelayProperty().get(); Interval cur = item.getDelayProperty().get();
for (int i = 0; i < changed; i++) { for (int i = 0; i < changed; i++) {
if ((t - i) % cur.getDelay() == cur.getOffset()) { if ((t - i) % cur.getDelay() == cur.getOffset()) {
if (item.getDestinationProperty().getValue() == HMessage.Side.TOSERVER) { if (item.getDestinationProperty().get() == HMessage.Side.TOSERVER) {
getHConnection().sendToServerAsync(item.getPacketProperty().get()); getHConnection().sendToServerAsync(item.getPacketProperty().get());
} }
else { else {
@ -182,4 +190,29 @@ public class Scheduler extends SubForm {
btn_addoredit.setText("Add to scheduler"); btn_addoredit.setText("Add to scheduler");
updateUI(); updateUI();
} }
private void clear() {
for (int i = scheduleItemList.size() - 1; i >= 0; i--) {
scheduleItemList.get(i).delete();
}
}
private void load(List<ScheduleItem> list) {
clear();
for (ScheduleItem item : list) {
addItem(item);
}
}
public void clearBtnClicked(ActionEvent actionEvent) {
clear();
}
public void saveBtnClicked(ActionEvent actionEvent) {
}
public void loadBtnClicked(ActionEvent actionEvent) {
}
} }