Skip to content

Commit

Permalink
Add interaction rate limits (#32527)
Browse files Browse the repository at this point in the history
* Move PlayerRateLimitManager to shared

* Add interaction rate limits

* uncap tests
  • Loading branch information
ElectroJr authored Sep 29, 2024
1 parent 6b49a51 commit f1f1fc1
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 164 deletions.
10 changes: 10 additions & 0 deletions Content.Client/Chat/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public void Initialize()
_sawmill.Level = LogLevel.Info;
}

public void SendAdminAlert(string message)
{
// See server-side manager. This just exists for shared code.
}

public void SendAdminAlert(EntityUid player, string message)
{
// See server-side manager. This just exists for shared code.
}

public void SendMessage(string text, ChatSelectChannel channel)
{
var str = text.ToString();
Expand Down
4 changes: 1 addition & 3 deletions Content.Client/Chat/Managers/IChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Content.Client.Chat.Managers
{
public interface IChatManager
public interface IChatManager : ISharedChatManager
{
void Initialize();

public void SendMessage(string text, ChatSelectChannel channel);
}
}
8 changes: 7 additions & 1 deletion Content.Client/IoC/ClientContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
using Content.Client.Voting;
using Content.Shared.Administration.Logs;
using Content.Client.Lobby;
using Content.Client.Players.RateLimiting;
using Content.Shared.Administration.Managers;
using Content.Shared.Chat;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Players.RateLimiting;

namespace Content.Client.IoC
{
Expand All @@ -31,6 +34,7 @@ public static void Register()

collection.Register<IParallaxManager, ParallaxManager>();
collection.Register<IChatManager, ChatManager>();
collection.Register<ISharedChatManager, ChatManager>();
collection.Register<IClientPreferencesManager, ClientPreferencesManager>();
collection.Register<IStylesheetManager, StylesheetManager>();
collection.Register<IScreenshotHook, ScreenshotHook>();
Expand All @@ -47,10 +51,12 @@ public static void Register()
collection.Register<ExtendedDisconnectInformationManager>();
collection.Register<JobRequirementsManager>();
collection.Register<DocumentParsingManager>();
collection.Register<ContentReplayPlaybackManager, ContentReplayPlaybackManager>();
collection.Register<ContentReplayPlaybackManager>();
collection.Register<ISharedPlaytimeManager, JobRequirementsManager>();
collection.Register<MappingManager>();
collection.Register<DebugMonitorManager>();
collection.Register<PlayerRateLimitManager>();
collection.Register<SharedPlayerRateLimitManager, PlayerRateLimitManager>();
}
}
}
23 changes: 23 additions & 0 deletions Content.Client/Players/RateLimiting/PlayerRateLimitManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Shared.Players.RateLimiting;
using Robust.Shared.Player;

namespace Content.Client.Players.RateLimiting;

public sealed class PlayerRateLimitManager : SharedPlayerRateLimitManager
{
public override RateLimitStatus CountAction(ICommonSession player, string key)
{
// TODO Rate-Limit
// Add support for rate limit prediction
// I.e., dont mis-predict just because somebody is clicking too quickly.
return RateLimitStatus.Allowed;
}

public override void Register(string key, RateLimitRegistration registration)
{
}

public override void Initialize()
{
}
}
4 changes: 3 additions & 1 deletion Content.IntegrationTests/PoolManager.Cvars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ private static readonly (string cvar, string value)[] TestCvars =
(CCVars.ConfigPresetDevelopment.Name, "false"),
(CCVars.AdminLogsEnabled.Name, "false"),
(CCVars.AutosaveEnabled.Name, "false"),
(CVars.NetBufferSize.Name, "0")
(CVars.NetBufferSize.Name, "0"),
(CCVars.InteractionRateLimitCount.Name, "9999999"),
(CCVars.InteractionRateLimitPeriod.Name, "0.1"),
};

public static async Task SetupCVars(RobustIntegrationTest.IntegrationInstance instance, PoolSettings settings)
Expand Down
11 changes: 5 additions & 6 deletions Content.Server/Administration/Systems/BwoinkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Content.Shared.Mind;
using Content.Shared.Players.RateLimiting;
using JetBrains.Annotations;
using Robust.Server.Player;
using Robust.Shared;
Expand Down Expand Up @@ -104,12 +105,10 @@ public override void Initialize()

_rateLimit.Register(
RateLimitKey,
new RateLimitRegistration
{
CVarLimitPeriodLength = CCVars.AhelpRateLimitPeriod,
CVarLimitCount = CCVars.AhelpRateLimitCount,
PlayerLimitedAction = PlayerRateLimitedAction
});
new RateLimitRegistration(CCVars.AhelpRateLimitPeriod,
CCVars.AhelpRateLimitCount,
PlayerRateLimitedAction)
);
}

private void PlayerRateLimitedAction(ICommonSession obj)
Expand Down
21 changes: 9 additions & 12 deletions Content.Server/Chat/Managers/ChatManager.RateLimit.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Content.Server.Players.RateLimiting;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.Players.RateLimiting;
using Robust.Shared.Player;

namespace Content.Server.Chat.Managers;
Expand All @@ -12,15 +12,13 @@ internal sealed partial class ChatManager
private void RegisterRateLimits()
{
_rateLimitManager.Register(RateLimitKey,
new RateLimitRegistration
{
CVarLimitPeriodLength = CCVars.ChatRateLimitPeriod,
CVarLimitCount = CCVars.ChatRateLimitCount,
CVarAdminAnnounceDelay = CCVars.ChatRateLimitAnnounceAdminsDelay,
PlayerLimitedAction = RateLimitPlayerLimited,
AdminAnnounceAction = RateLimitAlertAdmins,
AdminLogType = LogType.ChatRateLimited,
});
new RateLimitRegistration(CCVars.ChatRateLimitPeriod,
CCVars.ChatRateLimitCount,
RateLimitPlayerLimited,
CCVars.ChatRateLimitAnnounceAdminsDelay,
RateLimitAlertAdmins,
LogType.ChatRateLimited)
);
}

private void RateLimitPlayerLimited(ICommonSession player)
Expand All @@ -30,8 +28,7 @@ private void RateLimitPlayerLimited(ICommonSession player)

private void RateLimitAlertAdmins(ICommonSession player)
{
if (_configurationManager.GetCVar(CCVars.ChatRateLimitAnnounceAdmins))
SendAdminAlert(Loc.GetString("chat-manager-rate-limit-admin-announcement", ("player", player.Name)));
SendAdminAlert(Loc.GetString("chat-manager-rate-limit-admin-announcement", ("player", player.Name)));
}

public RateLimitStatus HandleRateLimit(ICommonSession player)
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Chat/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Chat;
using Content.Shared.Database;
using Content.Shared.Mind;
using Content.Shared.Players.RateLimiting;
using Robust.Shared.Configuration;
using Robust.Shared.Network;
using Robust.Shared.Player;
Expand Down
9 changes: 2 additions & 7 deletions Content.Server/Chat/Managers/IChatManager.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System.Diagnostics.CodeAnalysis;
using Content.Server.Players;
using Content.Server.Players.RateLimiting;
using Content.Shared.Administration;
using Content.Shared.Chat;
using Content.Shared.Players.RateLimiting;
using Robust.Shared.Network;
using Robust.Shared.Player;

namespace Content.Server.Chat.Managers
{
public interface IChatManager
public interface IChatManager : ISharedChatManager
{
void Initialize();

/// <summary>
/// Dispatch a server announcement to every connected player.
/// </summary>
Expand All @@ -26,8 +23,6 @@ public interface IChatManager
void SendHookOOC(string sender, string message);
void SendAdminAnnouncement(string message, AdminFlags? flagBlacklist = null, AdminFlags? flagWhitelist = null);
void SendAdminAnnouncementMessage(ICommonSession player, string message, bool suppressLog = true);
void SendAdminAlert(string message);
void SendAdminAlert(EntityUid player, string message);

void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat,
INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0, NetUserId? author = null);
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Content.Shared.IdentityManagement;
using Content.Shared.Mobs.Systems;
using Content.Shared.Players;
using Content.Shared.Players.RateLimiting;
using Content.Shared.Radio;
using Content.Shared.Whitelist;
using Robust.Server.Player;
Expand Down
6 changes: 4 additions & 2 deletions Content.Server/IoC/ServerContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
using Content.Server.Maps;
using Content.Server.MoMMI;
using Content.Server.NodeContainer.NodeGroups;
using Content.Server.Objectives;
using Content.Server.Players;
using Content.Server.Players.JobWhitelist;
using Content.Server.Players.PlayTimeTracking;
using Content.Server.Players.RateLimiting;
Expand All @@ -26,8 +24,10 @@
using Content.Server.Worldgen.Tools;
using Content.Shared.Administration.Logs;
using Content.Shared.Administration.Managers;
using Content.Shared.Chat;
using Content.Shared.Kitchen;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Players.RateLimiting;

namespace Content.Server.IoC
{
Expand All @@ -36,6 +36,7 @@ internal static class ServerContentIoC
public static void Register()
{
IoCManager.Register<IChatManager, ChatManager>();
IoCManager.Register<ISharedChatManager, ChatManager>();
IoCManager.Register<IChatSanitizationManager, ChatSanitizationManager>();
IoCManager.Register<IMoMMILink, MoMMILink>();
IoCManager.Register<IServerPreferencesManager, ServerPreferencesManager>();
Expand Down Expand Up @@ -68,6 +69,7 @@ public static void Register()
IoCManager.Register<ServerApi>();
IoCManager.Register<JobWhitelistManager>();
IoCManager.Register<PlayerRateLimitManager>();
IoCManager.Register<SharedPlayerRateLimitManager, PlayerRateLimitManager>();
IoCManager.Register<MappingManager>();
}
}
Expand Down
Loading

0 comments on commit f1f1fc1

Please sign in to comment.