/*************************************************************************
* ModernUO *
* Copyright 2019-2026 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: FileAllowlistConfiguration.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/ip-allowlist.json. Loaded once;
/// a missing file writes a template so operators have something to edit.
///
public static class FileAllowlistConfiguration
{
private const string _path = "Configuration/ip-allowlist.json";
public static FileAllowlistSettings 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 FileAllowlistSettings();
Save();
}
}
private static void Save()
{
JsonConfig.Serialize(Path.Join(Core.BaseDirectory, _path), Settings);
}
}
///
/// Bound configuration for . Its own file rather than a corner of
/// blocklist.json: the blocklist is only one of two consumers, and the other
/// () works on a shard that runs no blocklist at all.
///
public record FileAllowlistSettings
{
///
/// Whether the shard reads at all. Off by default: reading them costs a poll for
/// the whole uptime, which no shard should pay before an operator has written a carve-out.
///
[JsonPropertyName("enabled")]
public bool Enabled { get; set; }
///
/// 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.
///
///
/// The filename may contain wildcards, which is how the default picks up a carve-out an admin adds
/// without anyone editing this file.
///
[JsonPropertyName("files")]
public string[] Files { get; set; } = ["Configuration/ip-allowlist*.txt"];
/// How often the files are checked for changes. Reloads only happen when one actually changed.
[JsonPropertyName("reloadInterval")]
public TimeSpan ReloadInterval { get; set; } = TimeSpan.FromSeconds(60);
}