This commit is contained in:
haiwwkes
2024-10-28 05:01:17 +05:00
committed by GitHub
parent 2b05807882
commit dd11e6f774
4 changed files with 35 additions and 12 deletions

View File

@@ -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<ICommonSession, PendingReply> _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<TRequest, TResponse>(
@@ -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}";

View File

@@ -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<CheatCheckResponseEvent>(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);

View File

@@ -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<ScreengrabResponseEvent>(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)

View File

@@ -419,4 +419,8 @@ public sealed class WhiteCVars
public static readonly CVarDef<float> ItemToArtifactRatio =
CVarDef.Create("white.random_artifacts_ratio", 0.4f, CVar.SERVERONLY);
public static readonly CVarDef<string> ACWebhook =
CVarDef.Create("ac.webhook", "", CVar.SERVERONLY);
}