Cleanup
This commit is contained in:
parent
f3b7c7451c
commit
fc15a61542
10 changed files with 18 additions and 45 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue