2023-11-27 04:08:30 +01:00
|
|
|
using Content.Shared.CCVar;
|
|
|
|
|
using Content.Shared.Database;
|
2024-09-30 01:19:00 +13:00
|
|
|
using Content.Shared.Players.RateLimiting;
|
2023-11-27 04:08:30 +01:00
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Chat.Managers;
|
|
|
|
|
|
|
|
|
|
internal sealed partial class ChatManager
|
|
|
|
|
{
|
2024-06-21 00:13:02 +02:00
|
|
|
private const string RateLimitKey = "Chat";
|
2023-11-27 04:08:30 +01:00
|
|
|
|
2024-06-21 00:13:02 +02:00
|
|
|
private void RegisterRateLimits()
|
2023-11-27 04:08:30 +01:00
|
|
|
{
|
2024-06-21 00:13:02 +02:00
|
|
|
_rateLimitManager.Register(RateLimitKey,
|
2024-09-30 01:19:00 +13:00
|
|
|
new RateLimitRegistration(CCVars.ChatRateLimitPeriod,
|
|
|
|
|
CCVars.ChatRateLimitCount,
|
|
|
|
|
RateLimitPlayerLimited,
|
|
|
|
|
CCVars.ChatRateLimitAnnounceAdminsDelay,
|
|
|
|
|
RateLimitAlertAdmins,
|
|
|
|
|
LogType.ChatRateLimited)
|
|
|
|
|
);
|
2023-11-27 04:08:30 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-21 00:13:02 +02:00
|
|
|
private void RateLimitPlayerLimited(ICommonSession player)
|
2023-11-27 04:08:30 +01:00
|
|
|
{
|
2024-06-21 00:13:02 +02:00
|
|
|
DispatchServerMessage(player, Loc.GetString("chat-manager-rate-limited"), suppressLog: true);
|
2023-11-27 04:08:30 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-21 00:13:02 +02:00
|
|
|
private void RateLimitAlertAdmins(ICommonSession player)
|
2023-11-27 04:08:30 +01:00
|
|
|
{
|
2024-09-30 01:19:00 +13:00
|
|
|
SendAdminAlert(Loc.GetString("chat-manager-rate-limit-admin-announcement", ("player", player.Name)));
|
2024-06-21 00:13:02 +02:00
|
|
|
}
|
2023-11-27 04:08:30 +01:00
|
|
|
|
2024-06-21 00:13:02 +02:00
|
|
|
public RateLimitStatus HandleRateLimit(ICommonSession player)
|
|
|
|
|
{
|
|
|
|
|
return _rateLimitManager.CountAction(player, RateLimitKey);
|
2023-11-27 04:08:30 +01:00
|
|
|
}
|
|
|
|
|
}
|