From 32fc9b807524f41cf9e517b847adaf3de9f986c1 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Fri, 12 Jun 2020 00:13:16 +0200 Subject: [PATCH] allow option to block all packets --- .../BlockAndReplacePackets.java | 15 ++++++++++----- .../rules/BlockPacketRule.java | 4 ++-- .../blockreplacepackets/rules/RuleFactory.java | 6 +++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/BlockAndReplacePackets.java b/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/BlockAndReplacePackets.java index 1b87e3f..ad3d6ff 100644 --- a/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/BlockAndReplacePackets.java +++ b/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/BlockAndReplacePackets.java @@ -92,12 +92,17 @@ public class BlockAndReplacePackets extends ExtensionForm { isValid = false; } else if (type.equals("Block packet")) { - try { - int v = Integer.parseInt(val); - isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0); + if (val.equals("")) { + isValid = true; } - catch (Exception e) { - isValid = false; + else { + try { + int v = Integer.parseInt(val); + isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0); + } + catch (Exception e) { + isValid = false; + } } } else { diff --git a/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/BlockPacketRule.java b/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/BlockPacketRule.java index a387803..d80c675 100644 --- a/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/BlockPacketRule.java +++ b/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/BlockPacketRule.java @@ -20,7 +20,7 @@ public class BlockPacketRule extends BlockReplaceRule{ 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) { + if (headerId == -1 || message.getPacket().headerId() == headerId) { message.setBlocked(true); } } @@ -43,7 +43,7 @@ public class BlockPacketRule extends BlockReplaceRule{ @Override public String value() { - return headerId+""; + return headerId == -1 ? "ALL" : (headerId+""); } @Override diff --git a/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/RuleFactory.java b/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/RuleFactory.java index 051bc28..ef99e03 100644 --- a/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/RuleFactory.java +++ b/Extensions/BlockReplacePackets/src/main/java/extensions/blockreplacepackets/rules/RuleFactory.java @@ -13,7 +13,11 @@ public class RuleFactory { BlockReplaceRule.Side rSide = BlockReplaceRule.Side.valueOf(side.toUpperCase()); if (rOption == BlockReplaceRule.Option.BLOCK) { - return new BlockPacketRule(rSide, Integer.parseInt(value)); + 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) {