bugfixes, packet safety in scheduler

This commit is contained in:
sirjonasxx 2022-12-27 23:41:17 +01:00
parent cd9f849d21
commit 76ce696186
9 changed files with 32 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import gearth.protocol.connection.proxy.unity.UnityProxyProvider;
import gearth.services.extension_handler.ExtensionHandler;
import java.io.IOException;
import java.util.function.Consumer;
public class HConnection {
@ -25,6 +26,7 @@ public class HConnection {
private volatile Object[] trafficObservables = {new Observable<TrafficListener>(), new Observable<TrafficListener>(), new Observable<TrafficListener>()};
private volatile Observable<StateChangeListener> stateObservable = new Observable<>();
private volatile Observable<Consumer<Boolean>> developerModeChangeObservable = new Observable<>();
private volatile HState state = HState.NOT_CONNECTED;
private volatile HProxy proxy = null;
@ -196,6 +198,11 @@ public class HConnection {
public void setDeveloperMode(boolean developerMode) {
this.developerMode = developerMode;
developerModeChangeObservable.fireEvent(listener -> listener.accept(developerMode));
}
public void onDeveloperModeChange(Consumer<Boolean> onChange) {
developerModeChangeObservable.addListener(onChange);
}
public String getClientHost() {

View File

@ -33,6 +33,9 @@ public class SubForm {
}
protected HConnection getHConnection() {
if (parentController == null) {
return null;
}
return parentController.getHConnection();
}
protected void writeToLog(javafx.scene.paint.Color color, String text) {

View File

@ -79,6 +79,8 @@ public class ExtensionsController extends SubForm {
extensionLogger.log(text);
}
}));
getHConnection().onDeveloperModeChange(this::setLocalInstallingEnabled);
}
@ -117,7 +119,6 @@ public class ExtensionsController extends SubForm {
btn_install.setDisable(!enabled);
}
private volatile int gpytonShellCounter = 1;
private volatile boolean pythonShellLaunching = false;
public void gpythonBtnClicked(ActionEvent actionEvent) {

View File

@ -266,7 +266,6 @@ public class ExtraController extends SubForm implements SocksConfiguration {
private void setDevelopMode(boolean enabled) {
cbx_develop.setSelected(enabled);
getHConnection().setDeveloperMode(enabled);
parentController.extensionsController.setLocalInstallingEnabled(enabled);
}
public void adminCbxClick(ActionEvent actionEvent) {

View File

@ -38,6 +38,7 @@ public class InjectionController extends SubForm {
private TranslatableString corruption, pcktInfo;
protected void onParentSet() {
getHConnection().onDeveloperModeChange(developMode -> updateUI());
getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(this::updateUI));
inputPacket.textProperty().addListener(event -> Platform.runLater(this::updateUI));

View File

@ -1,6 +1,10 @@
package gearth.ui.subforms.scheduler;
import com.tulskiy.keymaster.common.Provider;
import gearth.extensions.parsers.HDirection;
import gearth.protocol.HConnection;
import gearth.protocol.StateChangeListener;
import gearth.protocol.connection.HState;
import gearth.services.scheduler.Interval;
import gearth.services.scheduler.Scheduler;
import gearth.ui.translations.LanguageBundle;
@ -19,6 +23,7 @@ import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/**
* Created by Jonas on 06/04/18.
@ -61,8 +66,6 @@ public class SchedulerController extends SubForm {
txt_packet.textProperty().addListener(event -> Platform.runLater(this::updateUI));
txt_delay.textProperty().addListener(event -> Platform.runLater(this::updateUI));
updateUI();
//register hotkeys
//disable some output things
PrintStream err = System.err;
@ -85,6 +88,9 @@ public class SchedulerController extends SubForm {
@Override
protected void onParentSet() {
scheduler = new Scheduler<>(getHConnection());
getHConnection().onDeveloperModeChange(developMode -> updateUI());
getHConnection().getStateObservable().addListener((oldState, newState) -> updateUI());
updateUI();
}
private void switchPauseHotkey(int index) {
@ -104,7 +110,14 @@ public class SchedulerController extends SubForm {
}
private void updateUI() {
btn_addoredit.setDisable(!Interval.isValid(txt_delay.getText()) || new HPacket(txt_packet.getText()).isCorrupted());
HConnection connection = getHConnection();
if (connection == null) return;
HMessage.Direction direction = rb_incoming.isSelected() ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER;
HPacket packet = new HPacket(txt_packet.getText());
boolean isPacketOk = connection.canSendPacket(direction, packet);
btn_addoredit.setDisable(!Interval.isValid(txt_delay.getText()) || !isPacketOk);
}
public void scheduleBtnClicked(ActionEvent actionEvent) {

View File

@ -4,7 +4,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.subforms.extensions.ExtensionsController">
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.subforms.extensions.ExtensionsController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="277.0" />
</columnConstraints>

View File

@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.subforms.extra.ExtraController">
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.subforms.extra.ExtraController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="331.0" minWidth="10.0" prefWidth="318.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="390.0" minWidth="10.0" prefWidth="247.0" />

View File

@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.subforms.info.InfoController">
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.subforms.info.InfoController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="332.0" />
</columnConstraints>