This commit is contained in:
sirjonasxx 2021-07-04 20:57:15 +02:00
parent 3735799629
commit 2512678eb4
4 changed files with 14 additions and 8 deletions

View File

@ -22,7 +22,7 @@ public abstract class ExtensionBase extends IExtension {
protected final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>(); protected final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>();
protected final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>(); protected final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>();
protected PacketInfoManager packetInfoManager = new PacketInfoManager(new ArrayList<>()); // empty volatile PacketInfoManager packetInfoManager = PacketInfoManager.EMPTY;
/** /**
* Register a listener on a specific packet Type * Register a listener on a specific packet Type
@ -131,7 +131,7 @@ public abstract class ExtensionBase extends IExtension {
return onConnectionObservable; return onConnectionObservable;
} }
protected void setPacketInfoManager(PacketInfoManager packetInfoManager) { void setPacketInfoManager(PacketInfoManager packetInfoManager) {
this.packetInfoManager = packetInfoManager; this.packetInfoManager = packetInfoManager;
} }

View File

@ -1,5 +1,6 @@
package gearth.extensions; package gearth.extensions;
import gearth.services.packet_info.PacketInfoManager;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.stage.Stage; import javafx.stage.Stage;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
@ -47,6 +48,11 @@ public abstract class ExtensionForm extends ExtensionBase {
extension.onConnect(listener); extension.onConnect(listener);
} }
@Override
public PacketInfoManager getPacketInfoManager() {
return extension.getPacketInfoManager();
}
protected void onShow(){}; protected void onShow(){};
protected void onHide(){}; protected void onHide(){};

View File

@ -68,9 +68,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
txt_replacement.textProperty().addListener(event -> Platform.runLater(this::refreshOptions)); txt_replacement.textProperty().addListener(event -> Platform.runLater(this::refreshOptions));
txt_value.textProperty().addListener(event -> Platform.runLater(this::refreshOptions)); txt_value.textProperty().addListener(event -> Platform.runLater(this::refreshOptions));
refreshOptions();
cmb_type.requestFocus(); cmb_type.requestFocus();
} }
private String getVal() { private String getVal() {
@ -80,8 +78,8 @@ public class BlockAndReplacePackets extends ExtensionForm {
if (type.endsWith("packet")) { if (type.endsWith("packet")) {
HMessage.Direction dir = side.equals("Outgoing") ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT; HMessage.Direction dir = side.equals("Outgoing") ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
PacketInfo fromName = packetInfoManager.getPacketInfoFromName(dir, val); PacketInfo fromName = getPacketInfoManager().getPacketInfoFromName(dir, val);
PacketInfo fromHash = packetInfoManager.getPacketInfoFromHash(dir, val); PacketInfo fromHash = getPacketInfoManager().getPacketInfoFromHash(dir, val);
if (fromName != null) { if (fromName != null) {
val = fromName.getHeaderId() +""; val = fromName.getHeaderId() +"";
} }
@ -208,6 +206,8 @@ public class BlockAndReplacePackets extends ExtensionForm {
intercept(HMessage.Direction.TOSERVER, messageListener); intercept(HMessage.Direction.TOSERVER, messageListener);
intercept(HMessage.Direction.TOCLIENT, messageListener); intercept(HMessage.Direction.TOCLIENT, messageListener);
refreshOptions();
} }
@Override @Override
@ -231,7 +231,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
public void click_btnAddRule(ActionEvent actionEvent) { public void click_btnAddRule(ActionEvent actionEvent) {
BlockReplaceRule rule = RuleFactory.getRule(cmb_type.getSelectionModel().getSelectedItem(), BlockReplaceRule rule = RuleFactory.getRule(cmb_type.getSelectionModel().getSelectedItem(),
cmb_side.getSelectionModel().getSelectedItem(), getVal(), txt_replacement.getText(), packetInfoManager); cmb_side.getSelectionModel().getSelectedItem(), getVal(), txt_replacement.getText(), getPacketInfoManager());
rules.add(rule); rules.add(rule);
rule.onDelete(observable -> rules.remove(rule)); rule.onDelete(observable -> rules.remove(rule));
new RuleContainer(rule, vbox); new RuleContainer(rule, vbox);

View File

@ -111,7 +111,7 @@ public class PacketInfoExplorer extends ExtensionForm {
@Override @Override
protected void initExtension() { protected void initExtension() {
onConnect((host, port, hotelversion, clientIdentifier, clientType) -> { onConnect((host, port, hotelversion, clientIdentifier, clientType) -> {
init(packetInfoManager); init(getPacketInfoManager());
}); });
} }