mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2025-01-31 21:02:37 +01:00
anti spam filter packetlogger
This commit is contained in:
parent
71496b8a30
commit
da35c41524
@ -10,7 +10,8 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.CheckMenuItem;
|
import javafx.scene.control.CheckMenuItem;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.control.RadioMenuItem;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.FlowPane;
|
import javafx.scene.layout.FlowPane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.fxmisc.flowless.VirtualizedScrollPane;
|
import org.fxmisc.flowless.VirtualizedScrollPane;
|
||||||
@ -42,6 +43,18 @@ public class UiLoggerController implements Initializable {
|
|||||||
public CheckMenuItem chkHideOnDisconnect;
|
public CheckMenuItem chkHideOnDisconnect;
|
||||||
public CheckMenuItem chkResetOnDisconnect;
|
public CheckMenuItem chkResetOnDisconnect;
|
||||||
|
|
||||||
|
private final static int FILTER_AMOUNT_THRESHOLD_S = 15;
|
||||||
|
private final static int FILTER_AMOUNT_THRESHOLD_M = 9;
|
||||||
|
private final static int FILTER_AMOUNT_THRESHOLD_H = 4;
|
||||||
|
private final static int FILTER_TIME_THRESHOLD = 5000;
|
||||||
|
|
||||||
|
public RadioMenuItem chkAntiSpam_none;
|
||||||
|
public RadioMenuItem chkAntiSpam_low;
|
||||||
|
public RadioMenuItem chkAntiSpam_medium;
|
||||||
|
public RadioMenuItem chkAntiSpam_high;
|
||||||
|
|
||||||
|
private Map<Integer, LinkedList<Long>> filterTimestamps = new HashMap<>();
|
||||||
|
|
||||||
private StyleClassedTextArea area;
|
private StyleClassedTextArea area;
|
||||||
|
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
@ -90,11 +103,40 @@ public class UiLoggerController implements Initializable {
|
|||||||
return text.trim();
|
return text.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean checkFilter(HPacket packet) {
|
||||||
|
int headerId = packet.headerId();
|
||||||
|
|
||||||
|
int threshold = chkAntiSpam_none.isSelected() ? 100000000 : (
|
||||||
|
chkAntiSpam_low.isSelected() ? FILTER_AMOUNT_THRESHOLD_S : (
|
||||||
|
chkAntiSpam_medium.isSelected() ? FILTER_AMOUNT_THRESHOLD_M : FILTER_AMOUNT_THRESHOLD_H
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!filterTimestamps.containsKey(headerId)) {
|
||||||
|
filterTimestamps.put(headerId, new LinkedList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
long queueRemoveThreshold = System.currentTimeMillis() - FILTER_TIME_THRESHOLD;
|
||||||
|
LinkedList<Long> list = filterTimestamps.get(headerId);
|
||||||
|
while (!list.isEmpty() && list.get(0) < queueRemoveThreshold) list.removeFirst();
|
||||||
|
|
||||||
|
if (list.size() == threshold) list.removeFirst();
|
||||||
|
list.add(System.currentTimeMillis());
|
||||||
|
|
||||||
|
return list.size() >= threshold;
|
||||||
|
}
|
||||||
|
|
||||||
public void appendMessage(HPacket packet, int types) {
|
public void appendMessage(HPacket packet, int types) {
|
||||||
boolean isBlocked = (types & PacketLogger.MESSAGE_TYPE.BLOCKED.getValue()) != 0;
|
boolean isBlocked = (types & PacketLogger.MESSAGE_TYPE.BLOCKED.getValue()) != 0;
|
||||||
boolean isReplaced = (types & PacketLogger.MESSAGE_TYPE.REPLACED.getValue()) != 0;
|
boolean isReplaced = (types & PacketLogger.MESSAGE_TYPE.REPLACED.getValue()) != 0;
|
||||||
boolean isIncoming = (types & PacketLogger.MESSAGE_TYPE.INCOMING.getValue()) != 0;
|
boolean isIncoming = (types & PacketLogger.MESSAGE_TYPE.INCOMING.getValue()) != 0;
|
||||||
|
|
||||||
|
if (isIncoming && !isBlocked && !isReplaced) {
|
||||||
|
boolean filter = checkFilter(packet);
|
||||||
|
if (filter) return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isIncoming && !viewIncoming) return;
|
if (isIncoming && !viewIncoming) return;
|
||||||
if (!isIncoming && !viewOutgoing) return;
|
if (!isIncoming && !viewOutgoing) return;
|
||||||
|
|
||||||
|
@ -50,6 +50,18 @@
|
|||||||
<CheckMenuItem fx:id="chkUseNewStructures" mnemonicParsing="false" onAction="#toggleMessageHash" selected="true" text="New structures" />
|
<CheckMenuItem fx:id="chkUseNewStructures" mnemonicParsing="false" onAction="#toggleMessageHash" selected="true" text="New structures" />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
<Menu mnemonicParsing="false" text="Anti-spam filter">
|
||||||
|
<items>
|
||||||
|
<RadioMenuItem fx:id="chkAntiSpam_none" mnemonicParsing="false" selected="true" text="None">
|
||||||
|
<toggleGroup>
|
||||||
|
<ToggleGroup fx:id="antispam" />
|
||||||
|
</toggleGroup>
|
||||||
|
</RadioMenuItem>
|
||||||
|
<RadioMenuItem fx:id="chkAntiSpam_low" mnemonicParsing="false" text="Low" toggleGroup="$antispam" />
|
||||||
|
<RadioMenuItem fx:id="chkAntiSpam_medium" mnemonicParsing="false" text="Medium" toggleGroup="$antispam" />
|
||||||
|
<RadioMenuItem fx:id="chkAntiSpam_high" mnemonicParsing="false" text="High" toggleGroup="$antispam" />
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
<CheckMenuItem fx:id="chkSkipBigPackets" mnemonicParsing="false" onAction="#toggleSkipPackets" selected="true" text="Skip big packets" />
|
<CheckMenuItem fx:id="chkSkipBigPackets" mnemonicParsing="false" onAction="#toggleSkipPackets" selected="true" text="Skip big packets" />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user