allow option to block all packets

This commit is contained in:
sirjonasxx 2020-06-12 00:13:16 +02:00
parent 7ea507da98
commit 32fc9b8075
3 changed files with 17 additions and 8 deletions

View File

@ -92,12 +92,17 @@ public class BlockAndReplacePackets extends ExtensionForm {
isValid = false; isValid = false;
} }
else if (type.equals("Block packet")) { else if (type.equals("Block packet")) {
try { if (val.equals("")) {
int v = Integer.parseInt(val); isValid = true;
isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0);
} }
catch (Exception e) { else {
isValid = false; try {
int v = Integer.parseInt(val);
isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0);
}
catch (Exception e) {
isValid = false;
}
} }
} }
else { else {

View File

@ -20,7 +20,7 @@ public class BlockPacketRule extends BlockReplaceRule{
if (side == Side.ALL if (side == Side.ALL
|| (message.getDestination() == HMessage.Direction.TOSERVER && side == Side.OUTGOING) || (message.getDestination() == HMessage.Direction.TOSERVER && side == Side.OUTGOING)
|| (message.getDestination() == HMessage.Direction.TOCLIENT && side ==Side.INCOMING)) { || (message.getDestination() == HMessage.Direction.TOCLIENT && side ==Side.INCOMING)) {
if (message.getPacket().headerId() == headerId) { if (headerId == -1 || message.getPacket().headerId() == headerId) {
message.setBlocked(true); message.setBlocked(true);
} }
} }
@ -43,7 +43,7 @@ public class BlockPacketRule extends BlockReplaceRule{
@Override @Override
public String value() { public String value() {
return headerId+""; return headerId == -1 ? "ALL" : (headerId+"");
} }
@Override @Override

View File

@ -13,7 +13,11 @@ public class RuleFactory {
BlockReplaceRule.Side rSide = BlockReplaceRule.Side.valueOf(side.toUpperCase()); BlockReplaceRule.Side rSide = BlockReplaceRule.Side.valueOf(side.toUpperCase());
if (rOption == BlockReplaceRule.Option.BLOCK) { 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 (rOption == BlockReplaceRule.Option.REPLACE) {
if (rType == BlockReplaceRule.Type.INTEGER) { if (rType == BlockReplaceRule.Type.INTEGER) {