forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TTS rate limit (space-syndicate#2515)
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Content.Server.Chat.Managers; | ||
using Content.Server.Players.RateLimiting; | ||
using Content.Shared.Corvax.CCCVars; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Server.Corvax.TTS; | ||
|
||
public sealed partial class TTSSystem | ||
{ | ||
[Dependency] private readonly PlayerRateLimitManager _rateLimitManager = default!; | ||
[Dependency] private readonly IChatManager _chat = default!; | ||
|
||
private const string RateLimitKey = "TTS"; | ||
|
||
private void RegisterRateLimits() | ||
{ | ||
_rateLimitManager.Register(RateLimitKey, | ||
new RateLimitRegistration | ||
{ | ||
CVarLimitPeriodLength = CCCVars.TTSRateLimitPeriod, | ||
CVarLimitCount = CCCVars.TTSRateLimitCount, | ||
PlayerLimitedAction = RateLimitPlayerLimited, | ||
}); | ||
} | ||
|
||
private void RateLimitPlayerLimited(ICommonSession player) | ||
{ | ||
_chat.DispatchServerMessage(player, Loc.GetString("tts-rate-limited"), suppressLog: true); | ||
} | ||
|
||
private RateLimitStatus HandleRateLimit(ICommonSession player) | ||
{ | ||
return _rateLimitManager.CountAction(player, RateLimitKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters