diff --git a/Content.Server/_CP14/Discord/DiscordAuthManager.cs b/Content.Server/_CP14/Discord/DiscordAuthManager.cs index 3b887a6ff1..b47862e637 100644 --- a/Content.Server/_CP14/Discord/DiscordAuthManager.cs +++ b/Content.Server/_CP14/Discord/DiscordAuthManager.cs @@ -10,6 +10,7 @@ using Content.Server.Database; using Content.Shared._CP14.Discord; using Content.Shared.CCVar; using Robust.Server.Player; +using Robust.Shared; using Robust.Shared.Configuration; using Robust.Shared.Enums; using Robust.Shared.Network; @@ -29,8 +30,13 @@ public sealed class DiscordAuthManager private bool _enabled; private string _apiUrl = string.Empty; private string _apiKey = string.Empty; + // Suspicious activity blocking stuff + private string _suspiciousAccountsWarningLevel = string.Empty; + private bool _panicBunkerEnabled; + private string _panicBunkerCustomReason = string.Empty; + private bool _panicBunkerShowReason; - public const string DISCORD_GUILD = "1221923073759121468"; //CrystallEdge server required + public const string RequiredDiscordGuild = "1221923073759121468"; //CrystallEdge server required private HashSet _blockedGuilds = new() { @@ -54,6 +60,11 @@ public sealed class DiscordAuthManager _cfg.OnValueChanged(CCVars.DiscordAuthEnabled, v => _enabled = v, true); _cfg.OnValueChanged(CCVars.DiscordAuthUrl, v => _apiUrl = v, true); _cfg.OnValueChanged(CCVars.DiscordAuthToken, v => _apiKey = v, true); + // Suspicious activity blocking stuff + _cfg.OnValueChanged(CCVars.SuspiciousAccountsWarningLevel, v => _suspiciousAccountsWarningLevel = v, true); + _cfg.OnValueChanged(CCVars.PanicBunkerEnabled, v => _panicBunkerEnabled = v, true); + _cfg.OnValueChanged(CCVars.PanicBunkerCustomReason, v => _panicBunkerCustomReason = v, true); + _cfg.OnValueChanged(CCVars.PanicBunkerShowReason, v => _panicBunkerShowReason = v, true); _netMgr.RegisterNetMessage(); _netMgr.RegisterNetMessage(OnAuthCheck); @@ -145,9 +156,9 @@ public sealed class DiscordAuthManager } } - if (guilds.Guilds.All(guild => guild.Id != DISCORD_GUILD)) + if (guilds.Guilds.All(guild => guild.Id != RequiredDiscordGuild)) { - _sawmill.Debug($"Player {userId} is not in required guild {DISCORD_GUILD}"); + _sawmill.Debug($"Player {userId} is not in required guild {RequiredDiscordGuild}"); return new AuthData { Verified = false, ErrorMessage = "You are not a member of the CrystallEdge server." }; } @@ -163,6 +174,33 @@ public sealed class DiscordAuthManager isSuspicious = true; } + // Fastest way to block user is just not verify it + switch (_suspiciousAccountsWarningLevel) + { + case "medium": + if (_panicBunkerEnabled) + { + var errorMessage = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("RXJyb3IgMjcwMQ==")); + if (_panicBunkerShowReason) + { + errorMessage = "Panic bunker enabled"; + if (_panicBunkerCustomReason != string.Empty) + { + errorMessage = _panicBunkerCustomReason; + } + } + return new AuthData { Verified = false, ErrorMessage = errorMessage }; + } + break; + + case "high": + return new AuthData + { + Verified = false, + ErrorMessage = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("RXJyb3IgMjcwMQ==")) + }; + } + return new AuthData { Verified = true, Suspicious = isSuspicious }; } @@ -226,6 +264,7 @@ public sealed class DiscordAuthManager private double GetAccountAge(string id) { + // Please check https://discord.com/developers/docs/reference#convert-snowflake-to-datetime var intId = Convert.ToInt32(id); var snowflakeCreationDateBin = Convert.ToString(intId, 2).Substring(42); var snowflakeCreationDateDecimal = Convert.ToInt32(snowflakeCreationDateBin) + 1420070400000; diff --git a/Content.Server/_CP14/JoinQueue/JoinQueueManager.cs b/Content.Server/_CP14/JoinQueue/JoinQueueManager.cs index 0abad924f0..9558fec0c5 100644 --- a/Content.Server/_CP14/JoinQueue/JoinQueueManager.cs +++ b/Content.Server/_CP14/JoinQueue/JoinQueueManager.cs @@ -1,5 +1,6 @@ using System.Linq; using Content.Server._CP14.Discord; +using Content.Server.Chat.Managers; using Content.Server.Connection; using Content.Shared._CP14.JoinQueue; using Content.Shared.CCVar; @@ -40,6 +41,7 @@ public sealed class JoinQueueManager [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IServerNetManager _netManager = default!; [Dependency] private readonly DiscordAuthManager _discordAuthManager = default!; + [Dependency] private readonly IChatManager _chatManager = default!; private ISawmill _sawmill = default!; /// @@ -48,6 +50,7 @@ public sealed class JoinQueueManager private readonly List _queue = new(); // Real Queue class can't delete disconnected users private bool _isEnabled = false; + private string _suspiciousAccountWarningLevel = string.Empty; public int PlayerInQueueCount => _queue.Count; public int ActualPlayersCount => _playerManager.PlayerCount - PlayerInQueueCount; // Now it's only real value with actual players count that in game @@ -57,6 +60,7 @@ public sealed class JoinQueueManager _netManager.RegisterNetMessage(); _cfg.OnValueChanged(CCVars.QueueEnabled, OnQueueCVarChanged, true); + _cfg.OnValueChanged(CCVars.SuspiciousAccountsWarningLevel, v => _suspiciousAccountWarningLevel = v, true); _playerManager.PlayerStatusChanged += OnPlayerStatusChanged; _discordAuthManager.PlayerVerified += OnPlayerVerified; _sawmill = Logger.GetSawmill("queue"); @@ -168,5 +172,10 @@ public sealed class JoinQueueManager private void SendToGame(ICommonSession s) { Timer.Spawn(0, () => _playerManager.JoinGame(s)); + // Suspicious account warning + if (_suspiciousAccountWarningLevel != "disabled") + { + _chatManager.SendAdminAnnouncement(Loc.GetString("cp14-suspicious-player-join-message", ("name", s.Name))); + } } } diff --git a/Content.Server/_CP14/Sponsor/CP14SponsorManager.cs b/Content.Server/_CP14/Sponsor/CP14SponsorManager.cs index caf6a814ef..6f01ee2142 100644 --- a/Content.Server/_CP14/Sponsor/CP14SponsorManager.cs +++ b/Content.Server/_CP14/Sponsor/CP14SponsorManager.cs @@ -55,7 +55,7 @@ public sealed class SponsorSystem : ICP14SponsorManager private async Task?> GetRoles(NetUserId userId) { - var requestUrl = $"{_apiUrl}/api/roles?method=uid&id={userId}&guildId={DiscordAuthManager.DISCORD_GUILD}"; + var requestUrl = $"{_apiUrl}/api/roles?method=uid&id={userId}&guildId={DiscordAuthManager.RequiredDiscordGuild}"; var response = await _httpClient.GetAsync(requestUrl); if (!response.IsSuccessStatusCode) diff --git a/Content.Shared/_CP14/CCvar/CCvars.CP14DiscordAuth.cs b/Content.Shared/_CP14/CCvar/CCvars.CP14DiscordAuth.cs index 14db786211..f9d8c32521 100644 --- a/Content.Shared/_CP14/CCvar/CCvars.CP14DiscordAuth.cs +++ b/Content.Shared/_CP14/CCvar/CCvars.CP14DiscordAuth.cs @@ -12,4 +12,7 @@ public sealed partial class CCVars public static readonly CVarDef DiscordAuthToken = CVarDef.Create("cp14.discord_auth_token", "token", CVar.SERVERONLY | CVar.CONFIDENTIAL); + + public static readonly CVarDef SuspiciousAccountsWarningLevel = + CVarDef.Create("cp14.suspicious_accounts_warning_level", "disabled", CVar.SERVERONLY, "Can be: disabled, low, medium, high"); } diff --git a/Resources/Locale/en-US/_CP14/discord/warning.ftl b/Resources/Locale/en-US/_CP14/discord/warning.ftl new file mode 100644 index 0000000000..750dd3c70e --- /dev/null +++ b/Resources/Locale/en-US/_CP14/discord/warning.ftl @@ -0,0 +1 @@ +cp14-suspicious-player-join-message = SUSPICIOUS player {$name} joined. \ No newline at end of file diff --git a/Resources/Locale/ru-RU/_CP14/discord/warning.ftl b/Resources/Locale/ru-RU/_CP14/discord/warning.ftl new file mode 100644 index 0000000000..e72f1c953b --- /dev/null +++ b/Resources/Locale/ru-RU/_CP14/discord/warning.ftl @@ -0,0 +1 @@ +cp14-suspicious-player-join-message = ПОДОЗРИТЕЛЬНЫЙ игрок {$name} зашёл. \ No newline at end of file