/************************************************************************* * ModernUO * * Copyright 2019-2026 - ModernUO Development Team * * Email: hi@modernuo.com * * File: BlocklistConfiguration.cs * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * *************************************************************************/ using System; using System.IO; using System.Text.Json.Serialization; using Server.Json; namespace Server.Network.Bans; /// /// Loads the from Configuration/blocklist.json (matching the /// per-feature JSON config pattern used by AssistantConfiguration). Loaded once; a missing file /// writes a template so operators have something to edit. /// public static class BlocklistConfiguration { private const string _path = "Configuration/blocklist.json"; public static BlocklistSettings Settings { get; private set; } public static void Load() { var path = Path.Join(Core.BaseDirectory, _path); if (File.Exists(path)) { Settings = JsonConfig.Deserialize(path); } else { Settings = new BlocklistSettings(); Save(); } } private static void Save() { JsonConfig.Serialize(Path.Join(Core.BaseDirectory, _path), Settings); } } /// /// Bound configuration for . The filter is inert unless /// points at a list that actually exists, so the shipped defaults are safe on a shard that never runs /// the generator. /// public record BlocklistSettings { /// /// Path to the blocklist. A relative path resolves against ; an /// absolute path is used as-is (handy when several shards share one generated list). Set to /// "" to disable the gate entirely. Produce the file with tools/Export-IpBlocklist.ps1. /// [JsonPropertyName("file")] public string File { get; set; } = "Configuration/ip-blocklist.txt"; /// /// Addresses that must never be blocked and never escalated, in the blocklist's own format. The same /// files tools/Export-IpBlocklist.ps1 subtracts at generation time; the shard reads them so an /// entry also suppresses ban contributions, which the generator alone cannot do. See /// . /// /// /// The filename may contain wildcards, which is how the default picks up a carve-out an admin adds /// without anyone editing this file. /// [JsonPropertyName("allowlistFiles")] public string[] AllowlistFiles { get; set; } = ["Configuration/ip-allowlist*.txt"]; /// How often the file is checked for changes. Reloads only happen when it actually changed. [JsonPropertyName("reloadInterval")] public TimeSpan ReloadInterval { get; set; } = TimeSpan.FromSeconds(60); /// Whether blocklist hits are contributed to the ban channel (the demand-paging promotion). [JsonPropertyName("reportHits")] public bool ReportHits { get; set; } = true; /// Duration reported for a blocklist-matched ban. [JsonPropertyName("banDuration")] public TimeSpan BanDuration { get; set; } = TimeSpan.FromHours(6); /// /// How long the accept-path guard suppresses re-reporting a promoted address. This only needs to /// bridge the gap until the OS bouncer picks up the promotion (seconds); after that the kernel drops /// repeat traffic. Decoupled from so the guard doesn't have to remember /// hours' worth of distinct addresses. /// [JsonPropertyName("promoteSuppression")] public TimeSpan PromoteSuppression { get; set; } = TimeSpan.FromSeconds(60); }