Simplifies Configure()

This commit is contained in:
Kamron Batman 2026-07-25 10:52:06 -07:00
parent fc15a61542
commit 4d64a854c2
No known key found for this signature in database
GPG key ID: 7D81DF26D9A5D94A
7 changed files with 12 additions and 52 deletions

View file

@ -54,7 +54,7 @@ public static class BanChannel
}
}
reporter.Configure();
reporter.Register();
var updated = new IBanReporter[_reporters.Length + 1];
Array.Copy(_reporters, updated, _reporters.Length);

View file

@ -31,7 +31,7 @@ public interface IBanReporter
string Name { get; }
/// <summary>Reads configuration. No network or file I/O here.</summary>
void Configure();
void Register();
/// <summary>Starts background delivery. The token is cancelled on shutdown.</summary>
void Start(CancellationToken token);

View file

@ -31,15 +31,8 @@ public static class BlocklistConfiguration
public static BlocklistSettings Settings { get; private set; }
public static void Configure()
public static void Load()
{
// Idempotent: this Configure() is auto-discovered and also called explicitly by the filter,
// so guard against a redundant second load.
if (Settings != null)
{
return;
}
var path = Path.Join(Core.BaseDirectory, _path);
if (File.Exists(path))

View file

@ -64,6 +64,7 @@ public sealed class BlocklistFilter : IConnectionFilter
public void Register()
{
BlocklistConfiguration.Load();
var s = BlocklistConfiguration.Settings;
_path = ResolvePath(s.File);

View file

@ -1,32 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2026 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: CrowdSecBans.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.Bans;
using Server.Network.Bans.CrowdSec;
namespace Server.Misc;
/// <summary>
/// Registers the CrowdSec ban reporter with the Core <see cref="BanChannel"/> during the Configure sweep.
/// Registration is unconditional: the reporter self-disables when <c>crowdsec.json</c> has no credentials
/// (see <c>CrowdSecSettings.ReportingEnabled</c>), so no config gate is needed here.
/// </summary>
public static class CrowdSecBans
{
public static void Configure()
{
BanChannel.Register(new CrowdSecReporter());
}
}

View file

@ -31,15 +31,8 @@ public static class CrowdSecConfiguration
public static CrowdSecSettings Settings { get; private set; }
public static void Configure()
public static void Load()
{
// Idempotent: this Configure() is auto-discovered and also called explicitly by the reporter,
// so guard against a redundant second load.
if (Settings != null)
{
return;
}
var path = Path.Join(Core.BaseDirectory, _path);
if (File.Exists(path))

View file

@ -69,9 +69,14 @@ public sealed class CrowdSecReporter : IBanReporter
/// </summary>
public int SendFailureCount => _sendFailures;
public void Configure()
public static void Configure()
{
CrowdSecConfiguration.Configure();
BanChannel.Register(new CrowdSecReporter());
}
public void Register()
{
CrowdSecConfiguration.Load();
_settings ??= CrowdSecConfiguration.Settings;
}