Skip to content

Commit

Permalink
忽略 Peer 快速测试的封禁项
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Nov 7, 2024
1 parent 0a379ac commit 60aecb2
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ private void handleLogs(Context ctx) throws SQLException {
private void handleBans(Context ctx) {
long limit = Long.parseLong(Objects.requireNonNullElse(ctx.queryParam("limit"), "-1"));
long lastBanTime = Long.parseLong(Objects.requireNonNullElse(ctx.queryParam("lastBanTime"), "-1"));
var banResponseList = getBanResponseStream(locale(ctx), lastBanTime, limit);
boolean ignoreBanForDisconnect = Boolean.parseBoolean(Objects.requireNonNullElse(ctx.queryParam("ignoreBanForDisconnect"), "true"));
var banResponseList = getBanResponseStream(locale(ctx), lastBanTime, limit, ignoreBanForDisconnect);
ctx.json(new StdResp(true, null, banResponseList.toList()));
}

Expand All @@ -110,11 +111,14 @@ public void onDisable() {
}


private @NotNull Stream<BanResponse> getBanResponseStream(String locale, long lastBanTime, long limit) {
private @NotNull Stream<BanResponse> getBanResponseStream(String locale, long lastBanTime, long limit, boolean ignoreBanForDisconnect) {
var banResponseList = getServer().getBannedPeers()
.entrySet()
.stream()
.filter(b -> !b.getValue().isBanForDisconnect())
.filter(b -> {
if(!ignoreBanForDisconnect) return true;
return !b.getValue().isBanForDisconnect();
})
.map(entry -> new BanResponse(entry.getKey().getAddress().toString(), new BakedBanMetadata(locale, entry.getValue())))
.sorted((o1, o2) -> Long.compare(o2.getBanMetadata().getBanAt(), o1.getBanMetadata().getBanAt()));
if (lastBanTime > 0) {
Expand Down

0 comments on commit 60aecb2

Please sign in to comment.