This commit is contained in:
Kamron Batman 2026-07-25 10:45:47 -07:00
parent f3b7c7451c
commit fc15a61542
No known key found for this signature in database
GPG key ID: 7D81DF26D9A5D94A
10 changed files with 18 additions and 45 deletions

View file

@ -55,7 +55,7 @@ public static class ConnectionFilters
}
}
filter.Configure();
filter.Register();
var updated = new IConnectionFilter[_filters.Length + 1];
Array.Copy(_filters, updated, _filters.Length);

View file

@ -44,7 +44,7 @@ public interface IConnectionFilter
string Name { get; }
/// <summary>Reads configuration. Called by <see cref="ConnectionFilters.Register"/>. No I/O beyond config.</summary>
void Configure();
void Register();
/// <summary>Starts any background hydration. The token is cancelled on shutdown.</summary>
void Start(CancellationToken token);

View file

@ -1,32 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2026 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: BlocklistBans.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 <http://www.gnu.org/licenses/>. *
*************************************************************************/
using Server.Network;
using Server.Network.Bans.Blocklist;
namespace Server.Misc;
/// <summary>
/// Registers the file-backed blocklist with the Core <see cref="ConnectionFilters"/> registry during the
/// Configure sweep. Registration is unconditional: the filter self-disables when <c>blocklist.json</c>
/// names no file, or when that file does not exist yet, so no config gate is needed here.
/// </summary>
public static class BlocklistBans
{
public static void Configure()
{
ConnectionFilters.Register(new BlocklistFilter());
}
}

View file

@ -18,7 +18,7 @@ using System.IO;
using System.Text.Json.Serialization;
using Server.Json;
namespace Server.Network.Bans.Blocklist;
namespace Server.Network.Bans;
/// <summary>
/// Loads the <see cref="BlocklistSettings"/> from <c>Configuration/blocklist.json</c> (matching the

View file

@ -16,7 +16,7 @@
using System;
using System.IO;
namespace Server.Network.Bans.Blocklist;
namespace Server.Network.Bans;
public readonly record struct BlocklistHeader(string Generated, int Count, bool Present);

View file

@ -20,7 +20,7 @@ using System.Threading;
using System.Threading.Tasks;
using Server.Logging;
namespace Server.Network.Bans.Blocklist;
namespace Server.Network.Bans;
/// <summary>
/// Accept-path gate for a large, file-sourced IP blocklist, hydrated from the file a generator
@ -57,9 +57,13 @@ public sealed class BlocklistFilter : IConnectionFilter
public int Count => _snapshot.Count;
public void Configure()
public static void Configure()
{
ConnectionFilters.Register(new BlocklistFilter());
}
public void Register()
{
BlocklistConfiguration.Configure();
var s = BlocklistConfiguration.Settings;
_path = ResolvePath(s.File);

View file

@ -20,7 +20,7 @@ using System.Net.Sockets;
using System.Text;
using Server.Collections;
namespace Server.Network.Bans.Blocklist;
namespace Server.Network.Bans;
/// <summary>
/// Immutable dual-stack blocklist. Singles and CIDRs are folded into a single sorted, coalesced

View file

@ -16,7 +16,7 @@
using System;
using System.Collections.Generic;
namespace Server.Network.Bans.Blocklist;
namespace Server.Network.Bans;
/// <summary>Suppresses re-reporting the same IP within a TTL. Accept-path thread only.</summary>
public sealed class PromotedGuard

View file

@ -14,6 +14,7 @@
*************************************************************************/
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Net;
@ -324,7 +325,7 @@ public static class Firewall
{
_dirty = false;
var path = Path.Join(Core.BaseDirectory, _path);
var tmp = path + ".tmp";
var tmp = $"{path}.tmp";
JsonConfig.Serialize(tmp, ToSettings());
File.Move(tmp, path, overwrite: true); // atomic swap
}
@ -348,7 +349,7 @@ public static class Firewall
private static void MigrateLegacyCfg(string legacyPath)
{
var searchValues = System.Buffers.SearchValues.Create("*Xx?");
var searchValues = SearchValues.Create("*Xx?");
using var reader = new StreamReader(legacyPath);
while (reader.ReadLine() is { } line)
@ -384,7 +385,7 @@ public static class Firewall
{
try
{
File.Move(legacyPath, legacyPath + ".migrated", overwrite: true);
File.Move(legacyPath, $"{legacyPath}.migrated", overwrite: true);
}
catch (Exception e)
{

View file

@ -37,7 +37,7 @@ internal sealed class FirewallConnectionFilter : IConnectionFilter
// Firewall.Configure() owns loading/persistence and does the registering, so there is nothing to do
// here; Register() calling this back is harmless.
public void Configure()
public void Register()
{
}