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,6 +92,10 @@ public class BlockAndReplacePackets extends ExtensionForm {
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);
@ -100,6 +104,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
isValid = false;
}
}
}
else {
if (type.endsWith("packet")) {
try {

View File

@ -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

View File

@ -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) {