uaua
This commit is contained in:
@@ -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<string> _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<MsgDiscordAuthRequired>();
|
||||
_netMgr.RegisterNetMessage<MsgDiscordAuthCheck>(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;
|
||||
|
||||
@@ -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!;
|
||||
|
||||
/// <summary>
|
||||
@@ -48,6 +50,7 @@ public sealed class JoinQueueManager
|
||||
private readonly List<ICommonSession> _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<MsgQueueUpdate>();
|
||||
|
||||
_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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public sealed class SponsorSystem : ICP14SponsorManager
|
||||
|
||||
private async Task<List<string>?> 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)
|
||||
|
||||
@@ -12,4 +12,7 @@ public sealed partial class CCVars
|
||||
|
||||
public static readonly CVarDef<string> DiscordAuthToken =
|
||||
CVarDef.Create("cp14.discord_auth_token", "token", CVar.SERVERONLY | CVar.CONFIDENTIAL);
|
||||
|
||||
public static readonly CVarDef<string> SuspiciousAccountsWarningLevel =
|
||||
CVarDef.Create("cp14.suspicious_accounts_warning_level", "disabled", CVar.SERVERONLY, "Can be: disabled, low, medium, high");
|
||||
}
|
||||
|
||||
1
Resources/Locale/en-US/_CP14/discord/warning.ftl
Normal file
1
Resources/Locale/en-US/_CP14/discord/warning.ftl
Normal file
@@ -0,0 +1 @@
|
||||
cp14-suspicious-player-join-message = SUSPICIOUS player {$name} joined.
|
||||
1
Resources/Locale/ru-RU/_CP14/discord/warning.ftl
Normal file
1
Resources/Locale/ru-RU/_CP14/discord/warning.ftl
Normal file
@@ -0,0 +1 @@
|
||||
cp14-suspicious-player-join-message = ПОДОЗРИТЕЛЬНЫЙ игрок {$name} зашёл.
|
||||
Reference in New Issue
Block a user