From dd11e6f7741ac08a24ee2e134da910b3e9d9ede6 Mon Sep 17 00:00:00 2001 From: haiwwkes <49613070+rhailrake@users.noreply.github.com> Date: Mon, 28 Oct 2024 05:01:17 +0500 Subject: [PATCH] avoooo (#753) --- .../_Miracle/Nya/ExpectedReplySystem.cs | 17 ++++++++++++++--- Content.Server/_Miracle/Nya/NyaCheckSystem.cs | 14 ++++++++++---- Content.Server/_Miracle/Nya/NyaGrabSystem.cs | 12 +++++++----- Content.Shared/_White/WhiteCVars.cs | 4 ++++ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Content.Server/_Miracle/Nya/ExpectedReplySystem.cs b/Content.Server/_Miracle/Nya/ExpectedReplySystem.cs index 966304a8ac..eebbffc5c5 100644 --- a/Content.Server/_Miracle/Nya/ExpectedReplySystem.cs +++ b/Content.Server/_Miracle/Nya/ExpectedReplySystem.cs @@ -6,6 +6,8 @@ using Robust.Shared.Timing; using System.Net.Http; using System.Text; using System.Text.Json; +using Content.Shared._White; +using Robust.Shared.Configuration; namespace Content.Server._Miracle.Nya; @@ -14,18 +16,22 @@ public sealed class ExpectedReplySystem : EntitySystem [Dependency] private readonly ISharedPlayerManager _playMan = default!; [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IChatManager _chatManager = default!; + [Dependency] private readonly IConfigurationManager _configuration = default!; + [Dependency] private readonly CheatCheckSystem _cheatCheckSystem = default!; private readonly Dictionary _pendingReplies = new(); private const float ReplyTimeoutSeconds = 5.0f; private readonly HttpClient _httpClient = new(); - private const string WebhookUrl = "https://discord.com/api/webhooks/1300204694395945021/jO_2nmXDXfMm2hKHH019gk1HqujhcHlW8yfmyMBeuScaOvCOiRJK9XurSJLf6AxpHmRv"; + private string _webhookUrl = ""; public override void Initialize() { base.Initialize(); _playMan.PlayerStatusChanged += OnPlayerStatusChanged; + + _configuration.OnValueChanged(WhiteCVars.ACWebhook, s => _webhookUrl = s, true); } private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) @@ -39,6 +45,11 @@ public sealed class ExpectedReplySystem : EntitySystem _pendingReplies.Remove(e.Session); } } + + if (e.NewStatus == SessionStatus.Connected) + { + _cheatCheckSystem.RequestCheck(e.Session); + } } public void ExpectReply( @@ -140,14 +151,14 @@ public sealed class ExpectedReplySystem : EntitySystem try { - await _httpClient.PostAsync(WebhookUrl, content); + await _httpClient.PostAsync(_webhookUrl, content); } catch (Exception e) { Log.Error($"Failed to send Discord webhook: {e}"); } - var inGameMsg = $"[color=red][Anticheat][/color] Внимание! Подозрительная активность:\n" + + var inGameMsg = $"[Anticheat] Внимание! Подозрительная активность:\n" + $"Игрок {player.Name} возможно читер!\n" + $"Причина обнаружения: {reason}"; diff --git a/Content.Server/_Miracle/Nya/NyaCheckSystem.cs b/Content.Server/_Miracle/Nya/NyaCheckSystem.cs index de94e676bf..86caf404bc 100644 --- a/Content.Server/_Miracle/Nya/NyaCheckSystem.cs +++ b/Content.Server/_Miracle/Nya/NyaCheckSystem.cs @@ -4,6 +4,8 @@ using System.Text; using System.Text.Json; using Content.Server.Chat.Managers; using Content.Shared._Miracle.Nya; +using Content.Shared._White; +using Robust.Shared.Configuration; using Robust.Shared.Player; namespace Content.Server._Miracle.Nya; @@ -12,15 +14,19 @@ public sealed class CheatCheckSystem : EntitySystem { [Dependency] private readonly ExpectedReplySystem _expectedReply = default!; [Dependency] private readonly IChatManager _chatManager = default!; + [Dependency] private readonly IConfigurationManager _configuration = default!; + private readonly HttpClient _httpClient = new(); - private const string WebhookUrl = "https://discord.com/api/webhooks/1300204694395945021/jO_2nmXDXfMm2hKHH019gk1HqujhcHlW8yfmyMBeuScaOvCOiRJK9XurSJLf6AxpHmRv"; + private string _webhookUrl = ""; public override void Initialize() { base.Initialize(); SubscribeNetworkEvent(OnCheckResponse); + + _configuration.OnValueChanged(WhiteCVars.ACWebhook, s => _webhookUrl = s, true); } public void RequestCheck(ICommonSession player) @@ -112,21 +118,21 @@ public sealed class CheatCheckSystem : EntitySystem try { - await _httpClient.PostAsync(WebhookUrl, content); + await _httpClient.PostAsync(_webhookUrl, content); } catch (Exception e) { Log.Error($"Failed to send Discord webhook: {e}"); } - var inGameMsg = $"[color=red][Anticheat][/color] Обнаружена подозрительная активность!\n" + + var inGameMsg = $"[Anticheat] Обнаружена подозрительная активность!\n" + $"Игрок: {args.SenderSession.Name}\n" + $"Вероятность использования читов: {totalSeverity}%\n" + $"Обнаруженные нарушения:"; foreach (var (type, details, severity) in detections) { - inGameMsg += $"\n[color=yellow]• {type}[/color] ({severity}%): {details}"; + inGameMsg += $"\n•{type} ({severity}%): {details}"; } _chatManager.SendAdminAnnouncement(inGameMsg); diff --git a/Content.Server/_Miracle/Nya/NyaGrabSystem.cs b/Content.Server/_Miracle/Nya/NyaGrabSystem.cs index 5bc337dee5..1307bfe826 100644 --- a/Content.Server/_Miracle/Nya/NyaGrabSystem.cs +++ b/Content.Server/_Miracle/Nya/NyaGrabSystem.cs @@ -2,6 +2,8 @@ using System.Net.Http; using System.Text.Json; using Content.Shared._Miracle.Nya; +using Content.Shared._White; +using Robust.Shared.Configuration; using Robust.Shared.Player; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; @@ -11,15 +13,18 @@ namespace Content.Server._Miracle.Nya; public sealed class NyaGrabSystem : EntitySystem { [Dependency] private readonly ExpectedReplySystem _expectedReply = default!; + [Dependency] private readonly IConfigurationManager _configuration = default!; private readonly HttpClient _httpClient = new(); - private const string WebhookUrl = "https://discord.com/api/webhooks/1300204694395945021/jO_2nmXDXfMm2hKHH019gk1HqujhcHlW8yfmyMBeuScaOvCOiRJK9XurSJLf6AxpHmRv"; + private string _webhookUrl = ""; public override void Initialize() { base.Initialize(); SubscribeNetworkEvent(OnScreengrabResponse); + + _configuration.OnValueChanged(WhiteCVars.ACWebhook, s => _webhookUrl = s, true); } public void RequestScreengrab(ICommonSession player) @@ -53,15 +58,12 @@ public sealed class NyaGrabSystem : EntitySystem fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg"); content.Add(fileContent, "file", fileName); - var hwIdString = string.Join("", args.SenderSession.Channel.UserData.HWId.Select(b => b.ToString("X2"))); - var embed = new { title = "📸 Скриншот игрока", description = $"**Игрок**: {args.SenderSession.Name}\n" + $"**UserId**: {args.SenderSession.UserId}\n" + $"**IP**: {args.SenderSession.Channel.RemoteEndPoint}\n" + - $"**HWId**: {hwIdString}\n" + $"**Дата и время**: {timestamp:yyyy-MM-dd HH:mm:ss} UTC\n" + $"**Разрешение**: {image.Width}x{image.Height}\n" + $"**Размер**: {(imagedata.Length / 1024.0):F2} KB", @@ -79,7 +81,7 @@ public sealed class NyaGrabSystem : EntitySystem try { - await _httpClient.PostAsync(WebhookUrl, content); + await _httpClient.PostAsync(_webhookUrl, content); Log.Info($"Screenshot sent to Discord for player {args.SenderSession.Name}"); } catch (Exception e) diff --git a/Content.Shared/_White/WhiteCVars.cs b/Content.Shared/_White/WhiteCVars.cs index 370e0748f8..e1496e951c 100644 --- a/Content.Shared/_White/WhiteCVars.cs +++ b/Content.Shared/_White/WhiteCVars.cs @@ -419,4 +419,8 @@ public sealed class WhiteCVars public static readonly CVarDef ItemToArtifactRatio = CVarDef.Create("white.random_artifacts_ratio", 0.4f, CVar.SERVERONLY); + + public static readonly CVarDef ACWebhook = + CVarDef.Create("ac.webhook", "", CVar.SERVERONLY); + }