mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2025-01-18 16:26:26 +01:00
purge builtin extensions
This commit is contained in:
parent
344bdea382
commit
c0a6e3d617
@ -3,12 +3,8 @@ package gearth.services.extension_handler.extensions.implementations.simple;
|
||||
import gearth.extensions.InternalExtensionFormBuilder;
|
||||
import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducer;
|
||||
import gearth.services.extension_handler.extensions.extensionproducers.ExtensionProducerObserver;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.BlockAndReplacePackets;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.BlockAndReplacePacketsLauncher;
|
||||
import gearth.services.internal_extensions.extensionstore.GExtensionStore;
|
||||
import gearth.services.internal_extensions.extensionstore.GExtensionStoreLauncher;
|
||||
import gearth.services.internal_extensions.packetinfoexplorer.PacketInfoExplorer;
|
||||
import gearth.services.internal_extensions.packetinfoexplorer.PacketInfoExplorerLauncher;
|
||||
|
||||
public class SimpleExtensionProducer implements ExtensionProducer {
|
||||
|
||||
@ -21,10 +17,5 @@ public class SimpleExtensionProducer implements ExtensionProducer {
|
||||
new InternalExtensionFormBuilder<GExtensionStoreLauncher, GExtensionStore>()
|
||||
.launch(new GExtensionStoreLauncher(), observer);
|
||||
|
||||
new InternalExtensionFormBuilder<BlockAndReplacePacketsLauncher, BlockAndReplacePackets>()
|
||||
.launch(new BlockAndReplacePacketsLauncher(), observer);
|
||||
|
||||
new InternalExtensionFormBuilder<PacketInfoExplorerLauncher, PacketInfoExplorer>()
|
||||
.launch(new PacketInfoExplorerLauncher(), observer);
|
||||
}
|
||||
}
|
||||
|
@ -1,230 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets;
|
||||
|
||||
import gearth.extensions.ExtensionForm;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.BlockReplaceRule;
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.RuleFactory;
|
||||
import gearth.services.packet_info.PacketInfo;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 22/09/18.
|
||||
*/
|
||||
|
||||
|
||||
@ExtensionInfo(
|
||||
Title = "G-Manipulate",
|
||||
Description = "Block &/ replace packets",
|
||||
Version = "0.2",
|
||||
Author = "sirjonasxx"
|
||||
)
|
||||
public class BlockAndReplacePackets extends ExtensionForm {
|
||||
|
||||
public TextField txt_replacement;
|
||||
public ComboBox<String> cmb_type;
|
||||
public Button btn_add;
|
||||
public volatile ComboBox<String> cmb_side;
|
||||
public TextField txt_value;
|
||||
public ScrollPane scrollpane;
|
||||
public VBox vbox;
|
||||
public GridPane header;
|
||||
|
||||
List<BlockReplaceRule> rules = new ArrayList<>();
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// runExtensionForm(args, BlockAndReplacePackets.class);
|
||||
// }
|
||||
|
||||
//initialize javaFX elements
|
||||
public void initialize() {
|
||||
cmb_type.getItems().addAll("Block packet", "Replace packet", "Replace integer", "Replace string", "Replace substring");
|
||||
cmb_type.getSelectionModel().selectFirst();
|
||||
|
||||
cmb_side.getItems().addAll("Incoming", "Outgoing");
|
||||
cmb_side.getSelectionModel().selectFirst();
|
||||
|
||||
cmb_side.getSelectionModel().selectedItemProperty().addListener(observable -> Platform.runLater(this::refreshOptions));
|
||||
cmb_type.getSelectionModel().selectedItemProperty().addListener(observable -> Platform.runLater(this::refreshOptions));
|
||||
txt_replacement.textProperty().addListener(event -> Platform.runLater(this::refreshOptions));
|
||||
txt_value.textProperty().addListener(event -> Platform.runLater(this::refreshOptions));
|
||||
|
||||
cmb_type.requestFocus();
|
||||
}
|
||||
|
||||
private String getVal() {
|
||||
String val = txt_value.getText();
|
||||
String type = cmb_type.getSelectionModel().getSelectedItem();
|
||||
String side = cmb_side.getSelectionModel().getSelectedItem();
|
||||
|
||||
if (type.endsWith("packet")) {
|
||||
HMessage.Direction dir = side.equals("Outgoing") ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
|
||||
PacketInfo fromName = getPacketInfoManager().getPacketInfoFromName(dir, val);
|
||||
PacketInfo fromHash = getPacketInfoManager().getPacketInfoFromHash(dir, val);
|
||||
if (fromName != null) {
|
||||
val = fromName.getHeaderId() +"";
|
||||
}
|
||||
else if (fromHash != null) {
|
||||
val = fromHash.getHeaderId() +"";
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private void refreshOptions() {
|
||||
txt_replacement.setDisable(cmb_type.getSelectionModel().getSelectedItem().startsWith("Block"));
|
||||
if (cmb_side.getItems().size() == 2 && !cmb_type.getSelectionModel().getSelectedItem().endsWith("packet")) {
|
||||
cmb_side.getItems().add("All");
|
||||
}
|
||||
else if (cmb_side.getItems().size() == 3 && cmb_type.getSelectionModel().getSelectedItem().endsWith("packet")) {
|
||||
if (cmb_side.getSelectionModel().getSelectedItem() != null && cmb_side.getSelectionModel().getSelectedItem().equals("All")) {
|
||||
cmb_side.getSelectionModel().selectFirst();
|
||||
}
|
||||
cmb_side.getItems().remove(2);
|
||||
}
|
||||
|
||||
boolean isValid = false;
|
||||
String val = getVal();
|
||||
String repl = txt_replacement.getText();
|
||||
String type = cmb_type.getSelectionModel().getSelectedItem();
|
||||
String side = cmb_side.getSelectionModel().getSelectedItem();
|
||||
|
||||
if (side == null) {
|
||||
isValid = false;
|
||||
}
|
||||
else if (type.equals("Block packet")) {
|
||||
if (val.equals("")) {
|
||||
isValid = true;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
int v = Integer.parseInt(val);
|
||||
isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (type.endsWith("packet")) {
|
||||
try {
|
||||
int v = Integer.parseInt(val);
|
||||
isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0);
|
||||
if (isValid) {
|
||||
HPacket packet = new HPacket(repl);
|
||||
isValid = !packet.isCorrupted();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
else if (type.endsWith("string")) {
|
||||
isValid = !val.equals("") && !repl.equals("") && !val.equals(repl);
|
||||
}
|
||||
else if (type.endsWith("integer")) {
|
||||
try {
|
||||
int v1 = Integer.parseInt(val);
|
||||
int v2 = Integer.parseInt(repl);
|
||||
isValid = (v1 != v2);
|
||||
}
|
||||
catch (Exception e) {
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btn_add.setDisable(!isValid);
|
||||
|
||||
String[] spl = type.split(" ");
|
||||
if (repl.equals("") && spl[0].equals("Replace")) {
|
||||
if (spl[1].equals("packet")) {
|
||||
txt_replacement.setPromptText("Enter a packet here");
|
||||
}
|
||||
else if (spl[1].equals("integer")) {
|
||||
txt_replacement.setPromptText("Enter an integer here");
|
||||
}
|
||||
else if (spl[1].endsWith("string")) {
|
||||
txt_replacement.setPromptText("Enter a string here");
|
||||
}
|
||||
}
|
||||
else {
|
||||
txt_replacement.setPromptText("");
|
||||
}
|
||||
|
||||
if (val.equals("")) {
|
||||
if (spl[1].equals("packet")) {
|
||||
txt_value.setPromptText("Enter headerID/name");
|
||||
}
|
||||
else if (spl[1].equals("integer")) {
|
||||
txt_value.setPromptText("Enter an integer");
|
||||
}
|
||||
else if (spl[1].endsWith("string")) {
|
||||
txt_value.setPromptText("Enter a string");
|
||||
}
|
||||
}
|
||||
else {
|
||||
txt_value.setPromptText("");
|
||||
}
|
||||
}
|
||||
|
||||
private void clearInput() {
|
||||
txt_value.clear();
|
||||
txt_replacement.clear();
|
||||
refreshOptions();
|
||||
cmb_type.requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
MessageListener messageListener = message -> {
|
||||
for (BlockReplaceRule rule : rules) {
|
||||
rule.appendRuleToMessage(message);
|
||||
}
|
||||
};
|
||||
|
||||
intercept(HMessage.Direction.TOSERVER, messageListener);
|
||||
intercept(HMessage.Direction.TOCLIENT, messageListener);
|
||||
|
||||
refreshOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onShow() {
|
||||
Platform.runLater(() -> cmb_type.requestFocus());
|
||||
}
|
||||
|
||||
public void click_btnAddRule(ActionEvent actionEvent) {
|
||||
BlockReplaceRule rule = RuleFactory.getRule(cmb_type.getSelectionModel().getSelectedItem(),
|
||||
cmb_side.getSelectionModel().getSelectedItem(), getVal(), txt_replacement.getText(), getPacketInfoManager());
|
||||
rules.add(rule);
|
||||
rule.onDelete(observable -> rules.remove(rule));
|
||||
new RuleContainer(rule, vbox);
|
||||
|
||||
|
||||
clearInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canLeave() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDelete() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.InternalExtensionFormLauncher;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class BlockAndReplacePacketsLauncher extends InternalExtensionFormLauncher<BlockAndReplacePackets> {
|
||||
|
||||
@Override
|
||||
public BlockAndReplacePackets createForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(BlockAndReplacePackets.class.getResource("blockreplace.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet blocker &/ replacer");
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets;
|
||||
|
||||
import gearth.services.internal_extensions.blockreplacepackets.rules.BlockReplaceRule;
|
||||
import gearth.ui.buttons.DeleteButton;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.ColumnConstraints;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.RowConstraints;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Font;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class RuleContainer extends GridPane {
|
||||
|
||||
public static final int[] columnWidths = {12, 14, 18, 33, 15, 6};
|
||||
|
||||
VBox parent;
|
||||
BlockReplaceRule item;
|
||||
|
||||
RuleContainer(BlockReplaceRule item, VBox parent) {
|
||||
super();
|
||||
|
||||
this.parent = parent;
|
||||
this.item = item;
|
||||
|
||||
setGridLinesVisible(true);
|
||||
VBox.setMargin(this, new Insets(2, -2, -2, -2));
|
||||
|
||||
setPrefWidth(parent.getWidth());
|
||||
setPrefHeight(23);
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
|
||||
RowConstraints rowConstraints = new RowConstraints(23);
|
||||
getRowConstraints().addAll(rowConstraints);
|
||||
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
ColumnConstraints columnConstraints = new ColumnConstraints(20);
|
||||
columnConstraints.setPercentWidth(columnWidths[i]);
|
||||
getColumnConstraints().add(columnConstraints);
|
||||
}
|
||||
|
||||
Label optionLabel = initNewLabelColumn(item.option().name());
|
||||
Label typeLabel = initNewLabelColumn(item.type().name());
|
||||
Label valueLabel = initNewLabelColumn(item.value());
|
||||
Label replacementLabel = initNewLabelColumn(item.replacement());
|
||||
Label destinationLabel = initNewLabelColumn(item.side().name());
|
||||
|
||||
add(optionLabel, 0, 0);
|
||||
add(typeLabel, 1, 0);
|
||||
add(valueLabel, 2, 0);
|
||||
add(replacementLabel, 3, 0);
|
||||
add(destinationLabel, 4, 0);
|
||||
|
||||
DeleteButton deleteButton = new DeleteButton();
|
||||
deleteButton.setAlignment(Pos.CENTER);
|
||||
deleteButton.show();
|
||||
|
||||
RuleContainer thiss = this;
|
||||
item.onDelete(observable -> parent.getChildren().remove(thiss));
|
||||
deleteButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.delete());
|
||||
|
||||
add(deleteButton, 5, 0);
|
||||
|
||||
|
||||
parent.getChildren().add(this);
|
||||
}
|
||||
|
||||
private Label initNewLabelColumn(String text) {
|
||||
Label label = new Label();
|
||||
// label.setMaxWidth(Double.MAX_VALUE);
|
||||
// label.setMinHeight(Double.MAX_VALUE);
|
||||
// label.setAlignment(Pos.CENTER);
|
||||
label.setFont(new Font(12));
|
||||
GridPane.setMargin(label, new Insets(0, 0, 0, 5));
|
||||
label.setText(text);
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class BlockPacketRule extends BlockReplaceRule{
|
||||
|
||||
private int headerId;
|
||||
private Side side;
|
||||
|
||||
BlockPacketRule(Side side, int headerId) {
|
||||
this.headerId = headerId;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Direction.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Direction.TOCLIENT && side ==Side.INCOMING)) {
|
||||
if (headerId == -1 || message.getPacket().headerId() == headerId) {
|
||||
message.setBlocked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return headerId == -1 ? "ALL" : (headerId+"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return "/";
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
import javafx.beans.InvalidationListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public abstract class BlockReplaceRule {
|
||||
|
||||
public enum Option {
|
||||
BLOCK,
|
||||
REPLACE
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
PACKET,
|
||||
INTEGER,
|
||||
STRING,
|
||||
SUBSTRING
|
||||
}
|
||||
|
||||
public enum Side {
|
||||
INCOMING,
|
||||
OUTGOING,
|
||||
ALL
|
||||
}
|
||||
|
||||
|
||||
public abstract void appendRuleToMessage(HMessage message);
|
||||
|
||||
public abstract Option option();
|
||||
public abstract Type type();
|
||||
public abstract Side side();
|
||||
|
||||
public abstract String value();
|
||||
public abstract String replacement();
|
||||
|
||||
private List<InvalidationListener> onDeleteListeners = new ArrayList<>();
|
||||
public void onDelete(InvalidationListener listener) {
|
||||
onDeleteListeners.add(listener);
|
||||
}
|
||||
public void delete() {
|
||||
for (int i = onDeleteListeners.size() - 1; i >= 0; i--) {
|
||||
onDeleteListeners.get(i).invalidated(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplaceIntegerRule extends BlockReplaceRule {
|
||||
|
||||
Side side;
|
||||
int value;
|
||||
int replacement;
|
||||
|
||||
ReplaceIntegerRule(Side side, int value, int replacement) {
|
||||
this.side = side;
|
||||
this.value = value;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Direction.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Direction.TOCLIENT && side ==Side.INCOMING)) {
|
||||
message.getPacket().replaceAllIntegers(value, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.INTEGER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return value+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement+"";
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplacePacketRule extends BlockReplaceRule {
|
||||
|
||||
private Side side;
|
||||
private int headerId;
|
||||
private HPacket replacement;
|
||||
|
||||
ReplacePacketRule(Side side, int headerId, HPacket replacement) {
|
||||
this.side = side;
|
||||
this.headerId = headerId;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Direction.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Direction.TOCLIENT && side ==Side.INCOMING)) {
|
||||
if (message.getPacket().headerId() == headerId) {
|
||||
message.getPacket().constructFromString(replacement.stringify());
|
||||
message.getPacket().overrideEditedField(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return headerId+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement.toString();
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplaceStringRule extends BlockReplaceRule {
|
||||
|
||||
private Side side;
|
||||
private String value;
|
||||
private String replacement;
|
||||
|
||||
ReplaceStringRule(Side side, String value, String replacement) {
|
||||
this.side = side;
|
||||
this.value = value;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Direction.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Direction.TOCLIENT && side ==Side.INCOMING)) {
|
||||
message.getPacket().replaceAllStrings(value, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplaceSubstringRule extends BlockReplaceRule {
|
||||
|
||||
private Side side;
|
||||
private String value;
|
||||
private String replacement;
|
||||
|
||||
ReplaceSubstringRule(Side side, String value, String replacement) {
|
||||
this.side = side;
|
||||
this.value = value;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Direction.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Direction.TOCLIENT && side ==Side.INCOMING)) {
|
||||
message.getPacket().replaceAllSubstrings(value, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.SUBSTRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package gearth.services.internal_extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.services.packet_info.PacketInfoManager;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class RuleFactory {
|
||||
|
||||
public static BlockReplaceRule getRule(String type, String side, String value, String replacement, PacketInfoManager packetInfoManager) {
|
||||
BlockReplaceRule.Option rOption = BlockReplaceRule.Option.valueOf(type.split(" ")[0].toUpperCase());
|
||||
BlockReplaceRule.Type rType = BlockReplaceRule.Type.valueOf(type.split(" ")[1].toUpperCase());
|
||||
BlockReplaceRule.Side rSide = BlockReplaceRule.Side.valueOf(side.toUpperCase());
|
||||
|
||||
if (rOption == BlockReplaceRule.Option.BLOCK) {
|
||||
return new BlockPacketRule(rSide,
|
||||
value.equals("") ?
|
||||
-1 : // block ALL headerIds if no headerId given
|
||||
Integer.parseInt(value)
|
||||
);
|
||||
}
|
||||
if (rOption == BlockReplaceRule.Option.REPLACE) {
|
||||
if (rType == BlockReplaceRule.Type.INTEGER) {
|
||||
return new ReplaceIntegerRule(rSide, Integer.parseInt(value), Integer.parseInt(replacement));
|
||||
}
|
||||
if (rType == BlockReplaceRule.Type.PACKET) {
|
||||
HPacket packet = new HPacket(replacement);
|
||||
if (!packet.isPacketComplete()) {
|
||||
packet.completePacket(packetInfoManager);
|
||||
}
|
||||
return new ReplacePacketRule(rSide, Integer.parseInt(value), packet);
|
||||
}
|
||||
if (rType == BlockReplaceRule.Type.STRING) {
|
||||
return new ReplaceStringRule(rSide, value, replacement);
|
||||
}
|
||||
if (rType == BlockReplaceRule.Type.SUBSTRING) {
|
||||
return new ReplaceSubstringRule(rSide, value, replacement);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -111,7 +111,6 @@ public class StoreExtensionTools {
|
||||
String folderName = name + "_" + version;
|
||||
String path = Paths.get(EXTENSIONS_PATH, folderName).toString();
|
||||
|
||||
File dir = new File(path);
|
||||
File extensionPath = new File(Paths.get(path, "extension").toString());
|
||||
|
||||
if (extensionPath.mkdirs()) {
|
||||
@ -131,16 +130,20 @@ public class StoreExtensionTools {
|
||||
|
||||
} catch (IOException e) {
|
||||
listener.fail("Error while unzipping");
|
||||
removeExtension(path);
|
||||
}
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
listener.fail("Invalid extension URL");
|
||||
removeExtension(path); // cleanup
|
||||
} catch (IOException e) {
|
||||
listener.fail("Extension not available in repository");
|
||||
removeExtension(path); // cleanup
|
||||
}
|
||||
}
|
||||
else {
|
||||
listener.fail("Something went wrong creating the extension directory, does the extension already exist?");
|
||||
// don't do cleanup since you might not want removal of current extension files
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -151,8 +154,12 @@ public class StoreExtensionTools {
|
||||
|
||||
}
|
||||
|
||||
public static void removeExtension(String extensionPath) throws IOException {
|
||||
FileUtils.deleteDirectory(new File(extensionPath));
|
||||
public static void removeExtension(String extensionPath) {
|
||||
try {
|
||||
FileUtils.deleteDirectory(new File(extensionPath));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<InstalledExtension> getInstalledExtension() {
|
||||
|
@ -1,173 +0,0 @@
|
||||
package gearth.services.internal_extensions.packetinfoexplorer;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.ExtensionForm;
|
||||
import gearth.extensions.ExtensionInfo;
|
||||
import gearth.services.packet_info.PacketInfo;
|
||||
import gearth.services.packet_info.PacketInfoManager;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ExtensionInfo(
|
||||
Title = "Packet Info",
|
||||
Description = "Packet info explorer",
|
||||
Version = "0.1",
|
||||
Author = "sirjonasxx"
|
||||
)
|
||||
public class PacketInfoExplorer extends ExtensionForm {
|
||||
public TextField txt_filterHeaderId;
|
||||
public TextField txt_filterNameHash;
|
||||
public GridPane source_grid;
|
||||
public CheckBox chk_toClient;
|
||||
public CheckBox chk_toServer;
|
||||
|
||||
private Map<String, CheckBox> chk_sources = new HashMap<>();
|
||||
|
||||
private List<PacketInfo> packetInfoList = new ArrayList<>();
|
||||
|
||||
private TableView<PacketInfo> tableView;
|
||||
public GridPane grid;
|
||||
|
||||
public void initialize() {
|
||||
Platform.runLater( () -> grid.requestFocus() );
|
||||
|
||||
tableView = new TableView<>();
|
||||
tableView.setTableMenuButtonVisible(true);
|
||||
tableView.setStyle("-fx-focus-color: white;");
|
||||
|
||||
tableView.focusedProperty().addListener(observable -> {
|
||||
if (tableView.isFocused()) {
|
||||
grid.requestFocus();
|
||||
}
|
||||
});
|
||||
|
||||
TableColumn<PacketInfo, Integer> headerIdColumn = new TableColumn<>("Header ID");
|
||||
headerIdColumn.setCellValueFactory(new PropertyValueFactory<>("headerId"));
|
||||
|
||||
TableColumn<PacketInfo, HMessage.Direction> directionColumn = new TableColumn<>("Direction");
|
||||
directionColumn.setCellValueFactory(new PropertyValueFactory<>("destination"));
|
||||
directionColumn.setPrefWidth(96);
|
||||
|
||||
TableColumn<PacketInfo, String> packetNameColumn = new TableColumn<>("Name");
|
||||
packetNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||
packetNameColumn.setPrefWidth(220);
|
||||
|
||||
TableColumn<PacketInfo, String> packetHashColumn = new TableColumn<>("Hash");
|
||||
packetHashColumn.setVisible(false);
|
||||
packetHashColumn.setCellValueFactory(new PropertyValueFactory<>("hash"));
|
||||
packetHashColumn.setPrefWidth(220);
|
||||
|
||||
TableColumn<PacketInfo, String> structureColumn = new TableColumn<>("Structure");
|
||||
structureColumn.setCellValueFactory(new PropertyValueFactory<>("structure"));
|
||||
structureColumn.setPrefWidth(115);
|
||||
|
||||
TableColumn<PacketInfo, String> sourceColumn = new TableColumn<>("Source");
|
||||
sourceColumn.setCellValueFactory(new PropertyValueFactory<>("source"));
|
||||
|
||||
tableView.getColumns().addAll(Arrays.asList(headerIdColumn, directionColumn, packetNameColumn,
|
||||
packetHashColumn, structureColumn, sourceColumn));
|
||||
|
||||
grid.add(tableView, 0, 1);
|
||||
|
||||
InvalidationListener filterValues = observable -> updateTableValues();
|
||||
txt_filterHeaderId.textProperty().addListener(filterValues);
|
||||
txt_filterNameHash.textProperty().addListener(filterValues);
|
||||
chk_toClient.selectedProperty().addListener(filterValues);
|
||||
chk_toServer.selectedProperty().addListener(filterValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
init(getPacketInfoManager());
|
||||
onConnect((host, port, hotelversion, clientIdentifier, clientType) -> init(getPacketInfoManager()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEndConnection() {
|
||||
init(PacketInfoManager.EMPTY);
|
||||
}
|
||||
|
||||
private void init(PacketInfoManager packetInfoManager) {
|
||||
packetInfoList = packetInfoManager.getPacketInfoList();
|
||||
packetInfoList.sort(Comparator.comparingInt(PacketInfo::getHeaderId));
|
||||
|
||||
Platform.runLater(() -> {
|
||||
source_grid.getChildren().clear();
|
||||
chk_sources.clear();
|
||||
for (PacketInfo packetInfo : packetInfoList) {
|
||||
if (!chk_sources.containsKey(packetInfo.getSource())) {
|
||||
CheckBox checkBox = new CheckBox(packetInfo.getSource());
|
||||
checkBox.setSelected(true);
|
||||
checkBox.selectedProperty().addListener(observable -> updateTableValues());
|
||||
source_grid.add(checkBox, 0, chk_sources.size());
|
||||
chk_sources.put(packetInfo.getSource(), checkBox);
|
||||
}
|
||||
}
|
||||
|
||||
primaryStage.setTitle("Packet info explorer | " + packetInfoList.size() + " packets");
|
||||
|
||||
updateTableValues();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void updateTableValues() {
|
||||
tableView.getItems().clear();
|
||||
|
||||
IntegerProperty doHeaderIdFilter = new SimpleIntegerProperty(-1);
|
||||
if (!txt_filterHeaderId.getText().equals("")) {
|
||||
try {
|
||||
doHeaderIdFilter.setValue(Integer.parseInt(txt_filterHeaderId.getText()));
|
||||
}
|
||||
catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
|
||||
List<PacketInfo> allPacketInfos = packetInfoList.stream()
|
||||
.filter(packetInfo -> {
|
||||
if (doHeaderIdFilter.get() != -1 && packetInfo.getHeaderId() != doHeaderIdFilter.get()) return false;
|
||||
String filterNameHashLower = txt_filterNameHash.getText().toLowerCase();
|
||||
if (!filterNameHashLower.equals("")
|
||||
&& (packetInfo.getName() == null || !packetInfo.getName().toLowerCase().contains(filterNameHashLower))
|
||||
&& (packetInfo.getHash() == null || !packetInfo.getHash().toLowerCase().contains(filterNameHashLower))) {
|
||||
return false;
|
||||
}
|
||||
if ((!chk_toClient.isSelected() && packetInfo.getDestination() == HMessage.Direction.TOCLIENT)
|
||||
|| (!chk_toServer.isSelected() && packetInfo.getDestination() == HMessage.Direction.TOSERVER)) {
|
||||
return false;
|
||||
}
|
||||
if (!chk_sources.get(packetInfo.getSource()).isSelected()) return false;
|
||||
return true;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
tableView.getItems().addAll(allPacketInfos);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canLeave() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDelete() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package gearth.services.internal_extensions.packetinfoexplorer;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.extensions.InternalExtensionFormLauncher;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class PacketInfoExplorerLauncher extends InternalExtensionFormLauncher<PacketInfoExplorer> {
|
||||
|
||||
@Override
|
||||
public PacketInfoExplorer createForm(Stage primaryStage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(PacketInfoExplorer.class.getResource("PacketInfoExplorer.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet info explorer");
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setMinWidth(430);
|
||||
primaryStage.setMinHeight(260);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
|
||||
|
||||
return loader.getController();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user