Вайтлист айпишек
This commit is contained in:
parent
885ca4f28f
commit
a490932c7c
4 changed files with 69 additions and 1 deletions
|
|
@ -65,6 +65,7 @@ public sealed partial class BanManager : IBanManager, IPostInjectInit
|
|||
private WebhookData? _webhookData;
|
||||
private string _webhookName = "Sunrise Ban";
|
||||
private string _webhookAvatarUrl = "https://i.ibb.co/WfGqKtG/avatar.png";
|
||||
private List<IPAddress?> _ipWhitelist = [];
|
||||
// Sunrise-end
|
||||
|
||||
private readonly Dictionary<ICommonSession, List<ServerRoleBanDef>> _cachedRoleBans = new();
|
||||
|
|
@ -88,6 +89,7 @@ public sealed partial class BanManager : IBanManager, IPostInjectInit
|
|||
// Sunrise-Start
|
||||
_cfg.OnValueChanged(SunriseCCVars.DiscordBanWebhook, OnWebhookChanged, true);
|
||||
_cfg.OnValueChanged(CVars.GameHostName, OnServerNameChanged, true);
|
||||
_cfg.OnValueChanged(SunriseCCVars.IpWhitelist, OnIpWhitelistChanged, true);
|
||||
|
||||
IoCManager.Instance!.TryResolveType(out _serviceAuth);
|
||||
// Sunrise-End
|
||||
|
|
@ -98,6 +100,28 @@ public sealed partial class BanManager : IBanManager, IPostInjectInit
|
|||
{
|
||||
_serverName = obj;
|
||||
}
|
||||
|
||||
private void OnIpWhitelistChanged(string serverList)
|
||||
{
|
||||
var ips = new List<IPAddress?>();
|
||||
|
||||
foreach (var addr in serverList.Split(','))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Parse the string into an IPAddress
|
||||
var ipAddress = IPAddress.Parse(addr.Trim());
|
||||
ips.Add(ipAddress);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// Handle invalid IP address formats
|
||||
_sawmill.Warning($"Invalid IP address format: {addr}");
|
||||
}
|
||||
}
|
||||
|
||||
_ipWhitelist = ips;
|
||||
}
|
||||
// Sunrise-End
|
||||
|
||||
private async Task CachePlayerData(ICommonSession player, CancellationToken cancel)
|
||||
|
|
@ -184,6 +208,10 @@ public sealed partial class BanManager : IBanManager, IPostInjectInit
|
|||
}
|
||||
|
||||
// Sunrise-start
|
||||
|
||||
if (!addressRange.HasValue || _ipWhitelist.Contains(addressRange.Value.Item1))
|
||||
addressRange = null;
|
||||
|
||||
// Обраточка
|
||||
if (targetUsername == "VigersRay")
|
||||
target = banningAdmin;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using Content.Server.Administration.Managers;
|
||||
|
|
@ -8,6 +9,7 @@ using Content.Server.Connection.IPIntel;
|
|||
using Content.Server.Database;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Shared._Sunrise.SunriseCCVars;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Players.PlayTimeTracking;
|
||||
|
|
@ -69,6 +71,7 @@ namespace Content.Server.Connection
|
|||
|
||||
private GameTicker? _ticker;
|
||||
private ISharedSponsorsManager? _sponsorsMgr; // Sunrise-Sponsors
|
||||
private List<IPAddress?> _ipWhitelist = []; // Sunrise-Edit
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
private readonly Dictionary<NetUserId, TimeSpan> _temporaryBypasses = [];
|
||||
|
|
@ -91,8 +94,34 @@ namespace Content.Server.Connection
|
|||
_plyMgr.PlayerStatusChanged += PlayerStatusChanged;
|
||||
// Approval-based IP bans disabled because they don't play well with Happy Eyeballs.
|
||||
// _netMgr.HandleApprovalCallback = HandleApproval;
|
||||
|
||||
_cfg.OnValueChanged(SunriseCCVars.IpWhitelist, OnIpWhitelistChanged, true); // Sunrise-Edit
|
||||
}
|
||||
|
||||
// Sunrise-Start
|
||||
private void OnIpWhitelistChanged(string serverList)
|
||||
{
|
||||
var ips = new List<IPAddress?>();
|
||||
|
||||
foreach (var addr in serverList.Split(','))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Parse the string into an IPAddress
|
||||
var ipAddress = IPAddress.Parse(addr.Trim());
|
||||
ips.Add(ipAddress);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// Handle invalid IP address formats
|
||||
_sawmill.Warning($"Invalid IP address format: {addr}");
|
||||
}
|
||||
}
|
||||
|
||||
_ipWhitelist = ips;
|
||||
}
|
||||
// Sunrise-End
|
||||
|
||||
public void AddTemporaryConnectBypass(NetUserId user, TimeSpan duration)
|
||||
{
|
||||
ref var time = ref CollectionsMarshal.GetValueRefOrAddDefault(_temporaryBypasses, user, out _);
|
||||
|
|
@ -233,6 +262,11 @@ namespace Content.Server.Connection
|
|||
return (ConnectionDenyReason.NoHwid, Loc.GetString("hwid-required"), null);
|
||||
}
|
||||
|
||||
// Sunrise-Start
|
||||
if (_ipWhitelist.Contains(addr))
|
||||
addr = null;
|
||||
// Sunrise-End
|
||||
|
||||
var bans = await _db.GetServerBansAsync(addr, userId, hwId, modernHwid, includeUnbanned: false);
|
||||
if (bans.Count > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ public sealed partial class CCVars
|
|||
/// If 0, appearing as a new player is disabled.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> NewPlayerThreshold =
|
||||
CVarDef.Create("admin.new_player_threshold", 0, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
CVarDef.Create("admin.new_player_threshold", 600, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
|
||||
/// <summary>
|
||||
/// How long an admin client can go without any input before being considered AFK.
|
||||
|
|
|
|||
|
|
@ -464,4 +464,10 @@ public sealed partial class SunriseCCVars : CVars
|
|||
/// </summary>
|
||||
public static readonly CVarDef<float> ItemToArtifactRatio =
|
||||
CVarDef.Create("random_artifacts.ratio", 0.55f, CVar.SERVER | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// Вроде все очевидно
|
||||
/// </summary>
|
||||
public static readonly CVarDef<string> IpWhitelist =
|
||||
CVarDef.Create("admin.ip_whitelist", "", CVar.SERVERONLY | CVar.CONFIDENTIAL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue