From 7fbbd51d23580ca165680be4dd75b4dffb4dc17e Mon Sep 17 00:00:00 2001 From: Vigers Ray Date: Mon, 5 Jan 2026 06:21:36 +0100 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B8=D0=BF=D0=BE=D0=B2=20=D1=81=20?= =?UTF-8?q?=D0=B0=D1=82=D1=80=D0=B8=D0=B1=D1=83=D1=82=D0=BE=D0=BC=20Harmon?= =?UTF-8?q?yPatch=20=D0=B8=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=B2=20=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=BC=D0=B5=20=D0=BF=D0=B0=D1=82=D1=87=D0=B5?= =?UTF-8?q?=D0=B9;=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5?= =?UTF-8?q?=D0=BC=D1=8B=D0=B5=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=20=D0=B8=D0=B7=20=D1=81=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=BC=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content.Server/Ani/PatchManager.cs | 44 +++++++++++++++++-- .../Connection/ConnectionManager.cs | 21 --------- .../Connection/IPBlocking/IPBlockingSystem.cs | 25 ++--------- .../IPBlocking/IIPBlockingSystem.cs | 9 +++- 4 files changed, 52 insertions(+), 47 deletions(-) diff --git a/Content.Server/Ani/PatchManager.cs b/Content.Server/Ani/PatchManager.cs index 7fd21ad9b7..12c9eddff0 100644 --- a/Content.Server/Ani/PatchManager.cs +++ b/Content.Server/Ani/PatchManager.cs @@ -1,4 +1,4 @@ -using System; +using System.Linq; using System.Reflection; using HarmonyLib; @@ -29,6 +29,21 @@ public sealed class PatchManager var patchedCount = 0; var failedCount = 0; + // Логируем все типы с атрибутом HarmonyPatch для диагностики + var allPatchTypes = new List(); + foreach (var type in types) + { + if (type.Assembly == assembly) + { + var hasHarmonyPatch = type.GetCustomAttributes(typeof(HarmonyPatch), false).Length > 0; + if (hasHarmonyPatch) + { + allPatchTypes.Add(type); + } + } + } + sawmill.Info($"Found {allPatchTypes.Count} patch types: {string.Join(", ", allPatchTypes.Select(t => t.FullName))}"); + foreach (var type in types) { try @@ -37,14 +52,37 @@ public sealed class PatchManager if (type.Assembly != assembly) continue; + // Проверяем, есть ли атрибут HarmonyPatch + var hasHarmonyPatch = type.GetCustomAttributes(typeof(HarmonyPatch), false).Length > 0; + if (!hasHarmonyPatch) + continue; + + sawmill.Info($"Applying patch to type: {type.FullName}"); + // Применяем патчи к типу - harmony.CreateClassProcessor(type).Patch(); + var processor = harmony.CreateClassProcessor(type); + var patchInfo = processor.Patch(); + + if (patchInfo != null) + { + sawmill.Info($"Successfully patched type: {type.FullName}"); + } + else + { + sawmill.Warning($"Patch returned null for type: {type.FullName}"); + } + patchedCount++; } catch (Exception ex) { // Логируем ошибку, но продолжаем применять патчи к другим типам - sawmill.Warning($"Failed to patch type {type.FullName}: {ex.Message}"); + sawmill.Warning($"Failed to patch type {type.FullName}: {ex.GetType().Name}: {ex.Message}"); + if (ex.InnerException != null) + { + sawmill.Warning($"Inner exception: {ex.InnerException.GetType().Name}: {ex.InnerException.Message}"); + } + sawmill.Warning($"Stack trace: {ex.StackTrace}"); failedCount++; } } diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index a39c028d8e..bc3ec78a32 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -6,8 +6,6 @@ using System.Runtime.InteropServices; using Content.Server.Administration.Managers; using Content.Server.Chat.Managers; using Content.Server.Connection.IPIntel; -using Content.Server.Connection.IPBlocking; -using Content.Shared.Connection.IPBlocking; using Content.Server.Database; using Content.Server.GameTicking; using Content.Server.Preferences.Managers; @@ -61,7 +59,6 @@ namespace Content.Server.Connection private readonly Dictionary _temporaryBypasses = []; private readonly Dictionary _temporaryConnectionAllowed = []; private IPIntel.IPIntel _ipintel = default!; - private IPBlockingSystem _ipBlockingSystem = default!; public event EventHandler? PlayerConnectingWithBan; @@ -76,14 +73,6 @@ namespace Content.Server.Connection _ipintel = new IPIntel.IPIntel(new IPIntelApi(_http, _cfg), _db, _cfg, _logManager, _chatManager, _gameTiming); - // Инициализация системы блокировки IP - _ipBlockingSystem = new IPBlockingSystem(); - IoCManager.Instance!.InjectDependencies(_ipBlockingSystem); - _ipBlockingSystem.Initialize(); - - // Регистрация в IoC для использования в других системах - IoCManager.Instance.RegisterInstance(_ipBlockingSystem, true); - IoCManager.Instance!.TryResolveType(out _sponsorsMgr); _netMgr.Connecting += NetMgrOnConnecting; _netMgr.AssignUserIdCallback = AssignUserIdCallback; @@ -135,16 +124,6 @@ namespace Content.Server.Connection { _sawmill.Error("IPIntel update failed:" + e); } - - // Периодическая очистка истекших блокировок IP - try - { - _ipBlockingSystem.Update(); - } - catch (Exception e) - { - _sawmill.Error("IPBlockingSystem update failed:" + e); - } } private async Task NetMgrOnConnecting(NetConnectingArgs e) diff --git a/Content.Server/Connection/IPBlocking/IPBlockingSystem.cs b/Content.Server/Connection/IPBlocking/IPBlockingSystem.cs index e9bce2d4b1..1eee42276c 100644 --- a/Content.Server/Connection/IPBlocking/IPBlockingSystem.cs +++ b/Content.Server/Connection/IPBlocking/IPBlockingSystem.cs @@ -1,11 +1,7 @@ using System.Collections.Concurrent; -using System.Collections.Generic; using System.Net; using Content.Shared.CCVar; using Robust.Shared.Configuration; -using Robust.Shared.IoC; -using Robust.Shared.Log; -using Robust.Shared.Timing; using Content.Shared.Connection.IPBlocking; @@ -19,7 +15,6 @@ public sealed class IPBlockingSystem : IIPBlockingSystem { [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly ILogManager _logManager = default!; - [Dependency] private readonly IGameTiming _gameTiming = default!; private readonly ConcurrentDictionary _blockedIPs = new(); private ISawmill _sawmill = default!; @@ -88,12 +83,16 @@ public sealed class IPBlockingSystem : IIPBlockingSystem public bool CheckAndBlockSuspiciousLength(IPAddress ip, int length, string context) { if (!_enabled) + { + _sawmill.Debug($"IP blocking is disabled, skipping block for {ip}"); return false; + } // Проверяем на отрицательные или слишком большие значения if (length < 0 || length > _maxResponseLength) { var reason = $"Подозрительная длина ответа: {length} байт (контекст: {context})"; + _sawmill.Info($"Blocking IP {ip} for suspicious length {length} in context {context}"); BlockIP(ip, reason); return true; } @@ -101,14 +100,6 @@ public sealed class IPBlockingSystem : IIPBlockingSystem return false; } - /// - /// Получает максимально допустимую длину ответа. - /// - public int GetMaxResponseLength() - { - return _maxResponseLength; - } - /// /// Очищает истекшие блокировки. Должен вызываться периодически. /// @@ -144,13 +135,5 @@ public sealed class IPBlockingSystem : IIPBlockingSystem _sawmill.Info($"IP {ip} разблокирован вручную"); } } - - /// - /// Получает количество заблокированных IP-адресов. - /// - public int GetBlockedCount() - { - return _blockedIPs.Count; - } } diff --git a/Content.Shared/Connection/IPBlocking/IIPBlockingSystem.cs b/Content.Shared/Connection/IPBlocking/IIPBlockingSystem.cs index 8a8643719b..00ae7bc284 100644 --- a/Content.Shared/Connection/IPBlocking/IIPBlockingSystem.cs +++ b/Content.Shared/Connection/IPBlocking/IIPBlockingSystem.cs @@ -7,6 +7,11 @@ namespace Content.Shared.Connection.IPBlocking; /// public interface IIPBlockingSystem { + /// + /// Инициализирует систему блокировки IP. + /// + void Initialize(); + /// /// Проверяет, заблокирован ли указанный IP-адрес. /// @@ -19,8 +24,8 @@ public interface IIPBlockingSystem bool CheckAndBlockSuspiciousLength(IPAddress ip, int length, string context); /// - /// Получает максимально допустимую длину ответа. + /// Очищает истекшие блокировки. Должен вызываться периодически. /// - int GetMaxResponseLength(); + void Update(); }